diff --git a/ui/packages/consul-ui/app/abilities/nspace.js b/ui/packages/consul-ui/app/abilities/nspace.js index 0dc1a233f8..d4471e4171 100644 --- a/ui/packages/consul-ui/app/abilities/nspace.js +++ b/ui/packages/consul-ui/app/abilities/nspace.js @@ -16,7 +16,7 @@ export default class NspaceAbility extends BaseAbility { } get canChoose() { - return this.canUse && this.nspaces.length > 0; + return this.canUse && (this.nspaces || []).length > 0; } get canUse() { diff --git a/ui/packages/consul-ui/app/abilities/partition.js b/ui/packages/consul-ui/app/abilities/partition.js new file mode 100644 index 0000000000..4db971787c --- /dev/null +++ b/ui/packages/consul-ui/app/abilities/partition.js @@ -0,0 +1,25 @@ +import BaseAbility from './base'; +import { inject as service } from '@ember/service'; + +export default class PartitionAbility extends BaseAbility { + @service('env') env; + + resource = 'operator'; + segmented = false; + + get canManage() { + return this.canCreate; + } + + get canDelete() { + return this.item.Name !== 'default' && super.canDelete; + } + + get canChoose() { + return this.canUse && (this.partitions || []).length > 0; + } + + get canUse() { + return this.env.var('CONSUL_PARTITIONS_ENABLED'); + } +} diff --git a/ui/packages/consul-ui/app/adapters/auth-method.js b/ui/packages/consul-ui/app/adapters/auth-method.js index fdfee01cea..6d8bbad5ec 100644 --- a/ui/packages/consul-ui/app/adapters/auth-method.js +++ b/ui/packages/consul-ui/app/adapters/auth-method.js @@ -1,18 +1,19 @@ import Adapter from './application'; export default class AuthMethodAdapter extends Adapter { - requestForQuery(request, { dc, ns, index, id }) { + requestForQuery(request, { dc, ns, partition, index, id }) { return request` GET /v1/acl/auth-methods?${{ dc }} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; } - requestForQueryRecord(request, { dc, ns, index, id }) { + requestForQueryRecord(request, { dc, ns, partition, index, id }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -20,7 +21,8 @@ export default class AuthMethodAdapter extends Adapter { GET /v1/acl/auth-method/${id}?${{ dc }} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; diff --git a/ui/packages/consul-ui/app/adapters/binding-rule.js b/ui/packages/consul-ui/app/adapters/binding-rule.js index b487f2d6f2..0226a276ee 100644 --- a/ui/packages/consul-ui/app/adapters/binding-rule.js +++ b/ui/packages/consul-ui/app/adapters/binding-rule.js @@ -1,12 +1,13 @@ import Adapter from './application'; export default class BindingRuleAdapter extends Adapter { - requestForQuery(request, { dc, ns, authmethod, index, id }) { + requestForQuery(request, { dc, ns, partition, authmethod, index, id }) { return request` GET /v1/acl/binding-rules?${{ dc, authmethod }} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; diff --git a/ui/packages/consul-ui/app/adapters/coordinate.js b/ui/packages/consul-ui/app/adapters/coordinate.js index 66de8393bc..239abed813 100644 --- a/ui/packages/consul-ui/app/adapters/coordinate.js +++ b/ui/packages/consul-ui/app/adapters/coordinate.js @@ -1,12 +1,15 @@ import Adapter from './application'; // TODO: Update to use this.formatDatacenter() export default class CoordinateAdapter extends Adapter { - requestForQuery(request, { dc, index, uri }) { + requestForQuery(request, { dc, partition, index, uri }) { return request` GET /v1/coordinate/nodes?${{ dc }} X-Request-ID: ${uri} - ${{ index }} + ${{ + partition, + index, + }} `; } } diff --git a/ui/packages/consul-ui/app/adapters/discovery-chain.js b/ui/packages/consul-ui/app/adapters/discovery-chain.js index cee98ff574..21b69294ef 100644 --- a/ui/packages/consul-ui/app/adapters/discovery-chain.js +++ b/ui/packages/consul-ui/app/adapters/discovery-chain.js @@ -2,7 +2,7 @@ import Adapter from './application'; // TODO: Update to use this.formatDatacenter() export default class DiscoveryChainAdapter extends Adapter { - requestForQueryRecord(request, { dc, ns, index, id, uri }) { + requestForQueryRecord(request, { dc, ns, partition, index, id, uri }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -11,7 +11,8 @@ export default class DiscoveryChainAdapter extends Adapter { X-Request-ID: ${uri} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; diff --git a/ui/packages/consul-ui/app/adapters/intention.js b/ui/packages/consul-ui/app/adapters/intention.js index f39f102094..0f2357a5bc 100644 --- a/ui/packages/consul-ui/app/adapters/intention.js +++ b/ui/packages/consul-ui/app/adapters/intention.js @@ -1,6 +1,5 @@ -import Adapter, { DATACENTER_QUERY_PARAM as API_DATACENTER_KEY } from './application'; +import Adapter from './application'; import { get } from '@ember/object'; -import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc'; // Intentions have different namespacing to the rest of the UI in that the don't // have a Namespace property, the DestinationNS is essentially its namespace. @@ -22,7 +21,7 @@ export default class IntentionAdapter extends Adapter { } ${{ - ...this.formatNspace('*'), + ns: '*', index, filter, }} @@ -76,7 +75,7 @@ export default class IntentionAdapter extends Adapter { PUT /v1/connect/intentions/exact?${{ source: `${data.SourceNS}/${data.SourceName}`, destination: `${data.DestinationNS}/${data.DestinationName}`, - [API_DATACENTER_KEY]: data[DATACENTER_KEY], + dc: data.Datacenter, }} ${body} @@ -95,7 +94,7 @@ export default class IntentionAdapter extends Adapter { DELETE /v1/connect/intentions/exact?${{ source: `${data.SourceNS}/${data.SourceName}`, destination: `${data.DestinationNS}/${data.DestinationName}`, - [API_DATACENTER_KEY]: data[DATACENTER_KEY], + dc: data.Datacenter, }} `; } diff --git a/ui/packages/consul-ui/app/adapters/kv.js b/ui/packages/consul-ui/app/adapters/kv.js index 212979a5e3..8e39d90864 100644 --- a/ui/packages/consul-ui/app/adapters/kv.js +++ b/ui/packages/consul-ui/app/adapters/kv.js @@ -2,14 +2,12 @@ import Adapter from './application'; import isFolder from 'consul-ui/utils/isFolder'; import keyToArray from 'consul-ui/utils/keyToArray'; import { SLUG_KEY } from 'consul-ui/models/kv'; -import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc'; -import { NSPACE_KEY } from 'consul-ui/models/nspace'; // TODO: Update to use this.formatDatacenter() const API_KEYS_KEY = 'keys'; export default class KvAdapter extends Adapter { - requestForQuery(request, { dc, ns, index, id, separator }) { + requestForQuery(request, { dc, ns, partition, index, id, separator }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -17,13 +15,14 @@ export default class KvAdapter extends Adapter { GET /v1/kv/${keyToArray(id)}?${{ [API_KEYS_KEY]: null, dc, separator }} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; } - requestForQueryRecord(request, { dc, ns, index, id }) { + requestForQueryRecord(request, { dc, ns, partition, index, id }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -31,7 +30,8 @@ export default class KvAdapter extends Adapter { GET /v1/kv/${keyToArray(id)}?${{ dc }} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; @@ -41,8 +41,9 @@ export default class KvAdapter extends Adapter { // https://github.com/hashicorp/consul/issues/3804 requestForCreateRecord(request, serialized, data) { const params = { - ...this.formatDatacenter(data[DATACENTER_KEY]), - ...this.formatNspace(data[NSPACE_KEY]), + dc: data.Datacenter, + ns: data.Namespace, + partition: data.Partition, }; return request` PUT /v1/kv/${keyToArray(data[SLUG_KEY])}?${params} @@ -54,9 +55,10 @@ export default class KvAdapter extends Adapter { requestForUpdateRecord(request, serialized, data) { const params = { - ...this.formatDatacenter(data[DATACENTER_KEY]), + dc: data.Datacenter, + ns: data.Namespace, + partition: data.Partition, flags: data.Flags, - ...this.formatNspace(data[NSPACE_KEY]), }; return request` PUT /v1/kv/${keyToArray(data[SLUG_KEY])}?${params} @@ -72,8 +74,9 @@ export default class KvAdapter extends Adapter { recurse = null; } const params = { - ...this.formatDatacenter(data[DATACENTER_KEY]), - ...this.formatNspace(data[NSPACE_KEY]), + dc: data.Datacenter, + ns: data.Namespace, + partition: data.Partition, recurse, }; return request` diff --git a/ui/packages/consul-ui/app/adapters/node.js b/ui/packages/consul-ui/app/adapters/node.js index 33f039938e..b16e71eaed 100644 --- a/ui/packages/consul-ui/app/adapters/node.js +++ b/ui/packages/consul-ui/app/adapters/node.js @@ -10,19 +10,20 @@ import Adapter from './application'; // to the node. export default class NodeAdapter extends Adapter { - requestForQuery(request, { dc, ns, index, id, uri }) { + requestForQuery(request, { dc, ns, partition, index, id, uri }) { return request` GET /v1/internal/ui/nodes?${{ dc }} X-Request-ID: ${uri} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; } - requestForQueryRecord(request, { dc, ns, index, id, uri }) { + requestForQueryRecord(request, { dc, ns, partition, index, id, uri }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -31,7 +32,8 @@ export default class NodeAdapter extends Adapter { X-Request-ID: ${uri} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; diff --git a/ui/packages/consul-ui/app/adapters/nspace.js b/ui/packages/consul-ui/app/adapters/nspace.js index 043887f7bf..ea71a06eeb 100644 --- a/ui/packages/consul-ui/app/adapters/nspace.js +++ b/ui/packages/consul-ui/app/adapters/nspace.js @@ -3,29 +3,37 @@ import { SLUG_KEY } from 'consul-ui/models/nspace'; // namespaces aren't categorized by datacenter, therefore no dc export default class NspaceAdapter extends Adapter { - requestForQuery(request, { index, uri }) { + requestForQuery(request, { partition, index, uri }) { return request` GET /v1/namespaces X-Request-ID: ${uri} - ${{ index }} + ${{ + partition, + index, + }} `; } - requestForQueryRecord(request, { index, id }) { + requestForQueryRecord(request, { partition, index, id }) { if (typeof id === 'undefined') { throw new Error('You must specify an name'); } return request` GET /v1/namespace/${id} - ${{ index }} + ${{ + partition, + index, + }} `; } requestForCreateRecord(request, serialized, data) { return request` - PUT /v1/namespace/${data[SLUG_KEY]} + PUT /v1/namespace/${data[SLUG_KEY]}?${{ + partition: data.Partition, + }} ${{ Name: serialized.Name, @@ -40,7 +48,9 @@ export default class NspaceAdapter extends Adapter { requestForUpdateRecord(request, serialized, data) { return request` - PUT /v1/namespace/${data[SLUG_KEY]} + PUT /v1/namespace/${data[SLUG_KEY]}?${{ + partition: data.Partition, + }} ${{ Description: serialized.Description, @@ -54,7 +64,9 @@ export default class NspaceAdapter extends Adapter { requestForDeleteRecord(request, serialized, data) { return request` - DELETE /v1/namespace/${data[SLUG_KEY]} + DELETE /v1/namespace/${data[SLUG_KEY]}?${{ + partition: data.Partition, + }} `; } } diff --git a/ui/packages/consul-ui/app/adapters/oidc-provider.js b/ui/packages/consul-ui/app/adapters/oidc-provider.js index 6f85a0160d..155331f5ab 100644 --- a/ui/packages/consul-ui/app/adapters/oidc-provider.js +++ b/ui/packages/consul-ui/app/adapters/oidc-provider.js @@ -1,47 +1,38 @@ import Adapter from './application'; import { inject as service } from '@ember/service'; -import { env } from 'consul-ui/env'; -import nonEmptySet from 'consul-ui/utils/non-empty-set'; - -let Namespace; -if (env('CONSUL_NSPACES_ENABLED')) { - Namespace = nonEmptySet('Namespace'); -} else { - Namespace = () => ({}); -} export default class OidcProviderAdapter extends Adapter { @service('env') env; - requestForQuery(request, { dc, ns, index, uri }) { + requestForQuery(request, { dc, ns, partition, index, uri }) { return request` GET /v1/internal/ui/oidc-auth-methods?${{ dc }} X-Request-ID: ${uri} ${{ + ns, + partition, index, - ...this.formatNspace(ns), }} `; } - requestForQueryRecord(request, { dc, ns, id }) { + requestForQueryRecord(request, { dc, ns, partition, id }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } return request` - POST /v1/acl/oidc/auth-url?${{ dc }} + POST /v1/acl/oidc/auth-url?${{ dc, ns, partition }} Cache-Control: no-store ${{ - ...Namespace(ns), AuthMethod: id, RedirectURI: `${this.env.var('CONSUL_BASE_UI_URL')}/oidc/callback`, }} `; } - requestForAuthorize(request, { dc, ns, id, code, state }) { + requestForAuthorize(request, { dc, ns, partition, id, code, state }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -52,11 +43,10 @@ export default class OidcProviderAdapter extends Adapter { throw new Error('You must specify an state'); } return request` - POST /v1/acl/oidc/callback?${{ dc }} + POST /v1/acl/oidc/callback?${{ dc, ns, partition }} Cache-Control: no-store ${{ - ...Namespace(ns), AuthMethod: id, Code: code, State: state, diff --git a/ui/packages/consul-ui/app/adapters/permission.js b/ui/packages/consul-ui/app/adapters/permission.js index ee3a2110d4..74addd1f48 100644 --- a/ui/packages/consul-ui/app/adapters/permission.js +++ b/ui/packages/consul-ui/app/adapters/permission.js @@ -4,16 +4,22 @@ import { inject as service } from '@ember/service'; export default class PermissionAdapter extends Adapter { @service('env') env; - requestForAuthorize(request, { dc, ns, resources = [], index }) { + requestForAuthorize(request, { dc, ns, partition, resources = [], index }) { // the authorize endpoint is slightly different to all others in that it // ignores an ns parameter, but accepts a Namespace property on each // resource. Here we hide this difference from the rest of the app as // currently we never need to ask for permissions/resources for multiple // different namespaces in one call so here we use the ns param and add // this to the resources instead of passing through on the queryParameter + // + // ^ same goes for Partitions + if (this.env.var('CONSUL_NSPACES_ENABLED')) { resources = resources.map(item => ({ ...item, Namespace: ns })); } + if (this.env.var('CONSUL_PARTITIONS_ENABLED')) { + resources = resources.map(item => ({ ...item, Partition: partition })); + } return request` POST /v1/internal/acl/authorize?${{ dc, index }} diff --git a/ui/packages/consul-ui/app/adapters/policy.js b/ui/packages/consul-ui/app/adapters/policy.js index a07b039a13..143554ccfc 100644 --- a/ui/packages/consul-ui/app/adapters/policy.js +++ b/ui/packages/consul-ui/app/adapters/policy.js @@ -1,31 +1,21 @@ import Adapter from './application'; import { SLUG_KEY } from 'consul-ui/models/policy'; -import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc'; -import { NSPACE_KEY } from 'consul-ui/models/nspace'; -import { env } from 'consul-ui/env'; -import nonEmptySet from 'consul-ui/utils/non-empty-set'; - -let Namespace; -if (env('CONSUL_NSPACES_ENABLED')) { - Namespace = nonEmptySet('Namespace'); -} else { - Namespace = () => ({}); -} // TODO: Update to use this.formatDatacenter() export default class PolicyAdapter extends Adapter { - requestForQuery(request, { dc, ns, index, id }) { + requestForQuery(request, { dc, ns, partition, index, id }) { return request` GET /v1/acl/policies?${{ dc }} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; } - requestForQueryRecord(request, { dc, ns, index, id }) { + requestForQueryRecord(request, { dc, ns, partition, index, id }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -33,7 +23,8 @@ export default class PolicyAdapter extends Adapter { GET /v1/acl/policy/${id}?${{ dc }} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; @@ -41,7 +32,9 @@ export default class PolicyAdapter extends Adapter { requestForCreateRecord(request, serialized, data) { const params = { - ...this.formatDatacenter(data[DATACENTER_KEY]), + ...this.formatDatacenter(data.Datacenter), + ns: data.Namespace, + partition: data.Partition, }; return request` PUT /v1/acl/policy?${params} @@ -51,14 +44,15 @@ export default class PolicyAdapter extends Adapter { Description: serialized.Description, Rules: serialized.Rules, Datacenters: serialized.Datacenters, - ...Namespace(serialized.Namespace), }} `; } requestForUpdateRecord(request, serialized, data) { const params = { - ...this.formatDatacenter(data[DATACENTER_KEY]), + ...this.formatDatacenter(data.Datacenter), + ns: data.Namespace, + partition: data.Partition, }; return request` PUT /v1/acl/policy/${data[SLUG_KEY]}?${params} @@ -68,15 +62,15 @@ export default class PolicyAdapter extends Adapter { Description: serialized.Description, Rules: serialized.Rules, Datacenters: serialized.Datacenters, - ...Namespace(serialized.Namespace), }} `; } requestForDeleteRecord(request, serialized, data) { const params = { - ...this.formatDatacenter(data[DATACENTER_KEY]), - ...this.formatNspace(data[NSPACE_KEY]), + ...this.formatDatacenter(data.Datacenter), + ns: data.Namespace, + partition: data.Partition, }; return request` DELETE /v1/acl/policy/${data[SLUG_KEY]}?${params} diff --git a/ui/packages/consul-ui/app/adapters/proxy.js b/ui/packages/consul-ui/app/adapters/proxy.js index ce34ff605b..42eec4eb23 100644 --- a/ui/packages/consul-ui/app/adapters/proxy.js +++ b/ui/packages/consul-ui/app/adapters/proxy.js @@ -1,7 +1,7 @@ import Adapter from './application'; // TODO: Update to use this.formatDatacenter() export default class ProxyAdapter extends Adapter { - requestForQuery(request, { dc, ns, index, id, uri }) { + requestForQuery(request, { dc, ns, partition, index, id, uri }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -11,7 +11,8 @@ export default class ProxyAdapter extends Adapter { X-Range: ${id} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; diff --git a/ui/packages/consul-ui/app/adapters/role.js b/ui/packages/consul-ui/app/adapters/role.js index 9f9c869db5..fe5f92960d 100644 --- a/ui/packages/consul-ui/app/adapters/role.js +++ b/ui/packages/consul-ui/app/adapters/role.js @@ -1,31 +1,20 @@ import Adapter from './application'; import { SLUG_KEY } from 'consul-ui/models/role'; -import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc'; -import { NSPACE_KEY } from 'consul-ui/models/nspace'; -import { env } from 'consul-ui/env'; -import nonEmptySet from 'consul-ui/utils/non-empty-set'; -let Namespace; -if (env('CONSUL_NSPACES_ENABLED')) { - Namespace = nonEmptySet('Namespace'); -} else { - Namespace = () => ({}); -} - -// TODO: Update to use this.formatDatacenter() export default class RoleAdapter extends Adapter { - requestForQuery(request, { dc, ns, index, id }) { + requestForQuery(request, { dc, ns, partition, index, id }) { return request` GET /v1/acl/roles?${{ dc }} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; } - requestForQueryRecord(request, { dc, ns, index, id }) { + requestForQueryRecord(request, { dc, ns, partition, index, id }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -33,7 +22,8 @@ export default class RoleAdapter extends Adapter { GET /v1/acl/role/${id}?${{ dc }} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; @@ -41,7 +31,9 @@ export default class RoleAdapter extends Adapter { requestForCreateRecord(request, serialized, data) { const params = { - ...this.formatDatacenter(data[DATACENTER_KEY]), + ...this.formatDatacenter(data.Datacenter), + ns: data.Namespace, + partition: data.Partition, }; return request` PUT /v1/acl/role?${params} @@ -52,14 +44,15 @@ export default class RoleAdapter extends Adapter { Policies: serialized.Policies, ServiceIdentities: serialized.ServiceIdentities, NodeIdentities: serialized.NodeIdentities, - ...Namespace(serialized.Namespace), }} `; } requestForUpdateRecord(request, serialized, data) { const params = { - ...this.formatDatacenter(data[DATACENTER_KEY]), + ...this.formatDatacenter(data.Datacenter), + ns: data.Namespace, + partition: data.Partition, }; return request` PUT /v1/acl/role/${data[SLUG_KEY]}?${params} @@ -70,15 +63,15 @@ export default class RoleAdapter extends Adapter { Policies: serialized.Policies, ServiceIdentities: serialized.ServiceIdentities, NodeIdentities: serialized.NodeIdentities, - ...Namespace(serialized.Namespace), }} `; } requestForDeleteRecord(request, serialized, data) { const params = { - ...this.formatDatacenter(data[DATACENTER_KEY]), - ...this.formatNspace(data[NSPACE_KEY]), + ...this.formatDatacenter(data.Datacenter), + ns: data.Namespace, + partition: data.Partition, }; return request` DELETE /v1/acl/role/${data[SLUG_KEY]}?${params} diff --git a/ui/packages/consul-ui/app/adapters/service-instance.js b/ui/packages/consul-ui/app/adapters/service-instance.js index 971f21aeea..009944e79f 100644 --- a/ui/packages/consul-ui/app/adapters/service-instance.js +++ b/ui/packages/consul-ui/app/adapters/service-instance.js @@ -2,7 +2,7 @@ import Adapter from './application'; // TODO: Update to use this.formatDatacenter() export default class ServiceInstanceAdapter extends Adapter { - requestForQuery(request, { dc, ns, index, id, uri }) { + requestForQuery(request, { dc, ns, partition, index, id, uri }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -12,13 +12,14 @@ export default class ServiceInstanceAdapter extends Adapter { X-Range: ${id} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; } - requestForQueryRecord(request, { dc, ns, index, id, uri }) { + requestForQueryRecord() { // query and queryRecord both use the same endpoint // they are just serialized differently return this.requestForQuery(...arguments); diff --git a/ui/packages/consul-ui/app/adapters/service.js b/ui/packages/consul-ui/app/adapters/service.js index 8b07072ef9..ea69f0927e 100644 --- a/ui/packages/consul-ui/app/adapters/service.js +++ b/ui/packages/consul-ui/app/adapters/service.js @@ -1,8 +1,7 @@ import Adapter from './application'; -// TODO: Update to use this.formatDatacenter() export default class ServiceAdapter extends Adapter { - requestForQuery(request, { dc, ns, index, gateway, uri }) { + requestForQuery(request, { dc, ns, partition, index, gateway, uri }) { if (typeof gateway !== 'undefined') { return request` GET /v1/internal/ui/gateway-services-nodes/${gateway}?${{ dc }} @@ -10,7 +9,8 @@ export default class ServiceAdapter extends Adapter { X-Request-ID: ${uri} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; @@ -20,14 +20,15 @@ export default class ServiceAdapter extends Adapter { X-Request-ID: ${uri} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; } } - requestForQueryRecord(request, { dc, ns, index, id, uri }) { + requestForQueryRecord(request, { dc, ns, partition, index, id, uri }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -36,7 +37,8 @@ export default class ServiceAdapter extends Adapter { X-Request-ID: ${uri} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; diff --git a/ui/packages/consul-ui/app/adapters/session.js b/ui/packages/consul-ui/app/adapters/session.js index e8ba419ad0..42990855aa 100644 --- a/ui/packages/consul-ui/app/adapters/session.js +++ b/ui/packages/consul-ui/app/adapters/session.js @@ -1,12 +1,10 @@ import Adapter from './application'; import { SLUG_KEY } from 'consul-ui/models/session'; -import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc'; -import { NSPACE_KEY } from 'consul-ui/models/nspace'; // TODO: Update to use this.formatDatacenter() export default class SessionAdapter extends Adapter { - requestForQuery(request, { dc, ns, index, id, uri }) { + requestForQuery(request, { dc, ns, partition, index, id, uri }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -15,13 +13,14 @@ export default class SessionAdapter extends Adapter { X-Request-ID: ${uri} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; } - requestForQueryRecord(request, { dc, ns, index, id }) { + requestForQueryRecord(request, { dc, ns, partition, index, id }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -29,7 +28,8 @@ export default class SessionAdapter extends Adapter { GET /v1/session/info/${id}?${{ dc }} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; @@ -37,8 +37,9 @@ export default class SessionAdapter extends Adapter { requestForDeleteRecord(request, serialized, data) { const params = { - ...this.formatDatacenter(data[DATACENTER_KEY]), - ...this.formatNspace(data[NSPACE_KEY]), + dc: data.Datacenter, + ns: data.Namespace, + partition: data.Partition, }; return request` PUT /v1/session/destroy/${data[SLUG_KEY]}?${params} diff --git a/ui/packages/consul-ui/app/adapters/token.js b/ui/packages/consul-ui/app/adapters/token.js index d0a8d35263..ab8fe8bad5 100644 --- a/ui/packages/consul-ui/app/adapters/token.js +++ b/ui/packages/consul-ui/app/adapters/token.js @@ -1,34 +1,23 @@ import Adapter from './application'; import { inject as service } from '@ember/service'; import { SLUG_KEY } from 'consul-ui/models/token'; -import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc'; -import { NSPACE_KEY } from 'consul-ui/models/nspace'; -import { env } from 'consul-ui/env'; -import nonEmptySet from 'consul-ui/utils/non-empty-set'; -let Namespace; -if (env('CONSUL_NSPACES_ENABLED')) { - Namespace = nonEmptySet('Namespace'); -} else { - Namespace = () => ({}); -} - -// TODO: Update to use this.formatDatacenter() export default class TokenAdapter extends Adapter { @service('store') store; - requestForQuery(request, { dc, ns, index, role, policy }) { + requestForQuery(request, { dc, ns, partition, index, role, policy }) { return request` GET /v1/acl/tokens?${{ role, policy, dc }} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; } - requestForQueryRecord(request, { dc, ns, index, id }) { + requestForQueryRecord(request, { dc, ns, partition, index, id }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -36,7 +25,8 @@ export default class TokenAdapter extends Adapter { GET /v1/acl/token/${id}?${{ dc }} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; @@ -44,7 +34,9 @@ export default class TokenAdapter extends Adapter { requestForCreateRecord(request, serialized, data) { const params = { - ...this.formatDatacenter(data[DATACENTER_KEY]), + ...this.formatDatacenter(data.Datacenter), + ns: data.Namespace, + partition: data.Partition, }; return request` PUT /v1/acl/token?${params} @@ -56,7 +48,6 @@ export default class TokenAdapter extends Adapter { ServiceIdentities: serialized.ServiceIdentities, NodeIdentities: serialized.NodeIdentities, Local: serialized.Local, - ...Namespace(serialized.Namespace), }} `; } @@ -71,13 +62,15 @@ export default class TokenAdapter extends Adapter { // https://www.consul.io/api/acl/legacy.html#update-acl-token // as we are using the old API we don't need to specify a nspace return request` - PUT /v1/acl/update?${this.formatDatacenter(data[DATACENTER_KEY])} + PUT /v1/acl/update?${this.formatDatacenter(data.Datacenter)} ${serialized} `; } const params = { - ...this.formatDatacenter(data[DATACENTER_KEY]), + ...this.formatDatacenter(data.Datacenter), + ns: data.Namespace, + partition: data.Partition, }; return request` PUT /v1/acl/token/${data[SLUG_KEY]}?${params} @@ -89,15 +82,15 @@ export default class TokenAdapter extends Adapter { ServiceIdentities: serialized.ServiceIdentities, NodeIdentities: serialized.NodeIdentities, Local: serialized.Local, - ...Namespace(serialized.Namespace), }} `; } requestForDeleteRecord(request, serialized, data) { const params = { - ...this.formatDatacenter(data[DATACENTER_KEY]), - ...this.formatNspace(data[NSPACE_KEY]), + dc: data.Datacenter, + ns: data.Namespace, + partition: data.Partition, }; return request` DELETE /v1/acl/token/${data[SLUG_KEY]}?${params} @@ -123,8 +116,9 @@ export default class TokenAdapter extends Adapter { throw new Error('You must specify an id'); } const params = { - ...this.formatDatacenter(data[DATACENTER_KEY]), - ...this.formatNspace(data[NSPACE_KEY]), + dc: data.Datacenter, + ns: data.Namespace, + partition: data.Partition, }; return request` PUT /v1/acl/token/${id}/clone?${params} @@ -158,8 +152,9 @@ export default class TokenAdapter extends Adapter { // eventually the id is created with this dc value and the id taken from the // json response of `acls/token/*/clone` const params = { - ...this.formatDatacenter(data[DATACENTER_KEY]), - ...this.formatNspace(data[NSPACE_KEY]), + dc: data.Datacenter, + ns: data.Namespace, + partition: data.Partition, }; return serializer.respondForQueryRecord(respond, params); }, diff --git a/ui/packages/consul-ui/app/adapters/topology.js b/ui/packages/consul-ui/app/adapters/topology.js index 41ec913a78..f19cb373d5 100644 --- a/ui/packages/consul-ui/app/adapters/topology.js +++ b/ui/packages/consul-ui/app/adapters/topology.js @@ -2,7 +2,7 @@ import Adapter from './application'; // TODO: Update to use this.formatDatacenter() export default class TopologyAdapter extends Adapter { - requestForQueryRecord(request, { dc, ns, index, id, uri, kind }) { + requestForQueryRecord(request, { dc, ns, partition, kind, index, id, uri }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -11,7 +11,8 @@ export default class TopologyAdapter extends Adapter { X-Request-ID: ${uri} ${{ - ...this.formatNspace(ns), + ns, + partition, index, }} `; diff --git a/ui/packages/consul-ui/app/locations/fsm-with-optional.js b/ui/packages/consul-ui/app/locations/fsm-with-optional.js index 806d664cf9..e6168615e7 100644 --- a/ui/packages/consul-ui/app/locations/fsm-with-optional.js +++ b/ui/packages/consul-ui/app/locations/fsm-with-optional.js @@ -1,9 +1,9 @@ import { env } from 'consul-ui/env'; const OPTIONAL = {}; -// if (true) { -// OPTIONAL.partition = /^-([a-zA-Z0-9]([a-zA-Z0-9-]{0,62}[a-zA-Z0-9])?)$/; -// } -// +if (env('CONSUL_PARTITIONS_ENABLED')) { + OPTIONAL.partition = /^-([a-zA-Z0-9]([a-zA-Z0-9-]{0,62}[a-zA-Z0-9])?)$/; +} + if (env('CONSUL_NSPACES_ENABLED')) { OPTIONAL.nspace = /^~([a-zA-Z0-9]([a-zA-Z0-9-]{0,62}[a-zA-Z0-9])?)$/; } @@ -193,9 +193,9 @@ export default class FSMWithOptionalLocation { if (typeof hash.nspace !== 'undefined') { hash.nspace = `~${hash.nspace}`; } - // if (typeof hash.partition !== 'undefined') { - // hash.partition = `-${hash.partition}`; - // } + if (typeof hash.partition !== 'undefined') { + hash.partition = `-${hash.partition}`; + } if (typeof this.router === 'undefined') { this.router = this.container.lookup('router:main'); } diff --git a/ui/packages/consul-ui/app/serializers/application.js b/ui/packages/consul-ui/app/serializers/application.js index ed93189688..4b0682a6e9 100644 --- a/ui/packages/consul-ui/app/serializers/application.js +++ b/ui/packages/consul-ui/app/serializers/application.js @@ -1,5 +1,6 @@ import Serializer from './http'; import { set } from '@ember/object'; + import { HEADERS_SYMBOL as HTTP_HEADERS_SYMBOL, HEADERS_INDEX as HTTP_HEADERS_INDEX, @@ -11,8 +12,6 @@ import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc'; import { NSPACE_KEY } from 'consul-ui/models/nspace'; import createFingerprinter from 'consul-ui/utils/create-fingerprinter'; -const DEFAULT_NSPACE = ''; - const map = function(obj, cb) { if (!Array.isArray(obj)) { return [obj].map(cb)[0]; @@ -26,14 +25,6 @@ const attachHeaders = function(headers, body, query = {}) { Object.keys(headers).forEach(function(key) { lower[key.toLowerCase()] = headers[key]; }); - // Add a 'pretend' Datacenter/Nspace header, they are not headers the come - // from the request but we add them here so we can use them later for store - // reconciliation - if (typeof query.dc !== 'undefined') { - lower[HTTP_HEADERS_DATACENTER.toLowerCase()] = query.dc; - } - lower[HTTP_HEADERS_NAMESPACE.toLowerCase()] = - typeof query.ns !== 'undefined' ? query.ns : DEFAULT_NSPACE; // body[HTTP_HEADERS_SYMBOL] = lower; return body; @@ -47,7 +38,10 @@ export default class ApplicationSerializer extends Serializer { return respond((headers, body) => attachHeaders( headers, - map(body, this.fingerprint(this.primaryKey, this.slugKey, query.dc)), + map( + body, + this.fingerprint(this.primaryKey, this.slugKey, query.dc, headers[HTTP_HEADERS_NAMESPACE]) + ), query ) ); @@ -55,26 +49,42 @@ export default class ApplicationSerializer extends Serializer { respondForQueryRecord(respond, query) { return respond((headers, body) => - attachHeaders(headers, this.fingerprint(this.primaryKey, this.slugKey, query.dc)(body), query) + attachHeaders( + headers, + this.fingerprint( + this.primaryKey, + this.slugKey, + query.dc, + headers[HTTP_HEADERS_NAMESPACE] + )(body), + query + ) ); } respondForCreateRecord(respond, serialized, data) { const slugKey = this.slugKey; const primaryKey = this.primaryKey; + return respond((headers, body) => { // If creates are true use the info we already have if (body === true) { body = data; } // Creates need a primaryKey adding - return this.fingerprint(primaryKey, slugKey, data[DATACENTER_KEY])(body); + return this.fingerprint( + primaryKey, + slugKey, + data[DATACENTER_KEY], + headers[HTTP_HEADERS_NAMESPACE] + )(body); }); } respondForUpdateRecord(respond, serialized, data) { const slugKey = this.slugKey; const primaryKey = this.primaryKey; + return respond((headers, body) => { // If updates are true use the info we already have // TODO: We may aswell avoid re-fingerprinting here if we are just going @@ -85,13 +95,19 @@ export default class ApplicationSerializer extends Serializer { if (body === true) { body = data; } - return this.fingerprint(primaryKey, slugKey, data[DATACENTER_KEY])(body); + return this.fingerprint( + primaryKey, + slugKey, + data[DATACENTER_KEY], + headers[HTTP_HEADERS_NAMESPACE] + )(body); }); } respondForDeleteRecord(respond, serialized, data) { const slugKey = this.slugKey; const primaryKey = this.primaryKey; + return respond((headers, body) => { // Deletes only need the primaryKey/uid returning and they need the slug // key AND potential namespace in order to create the correct @@ -100,7 +116,8 @@ export default class ApplicationSerializer extends Serializer { [primaryKey]: this.fingerprint( primaryKey, slugKey, - data[DATACENTER_KEY] + data[DATACENTER_KEY], + headers[HTTP_HEADERS_NAMESPACE] )({ [slugKey]: data[slugKey], [NSPACE_KEY]: data[NSPACE_KEY], diff --git a/ui/packages/consul-ui/app/serializers/kv.js b/ui/packages/consul-ui/app/serializers/kv.js index 37dac48991..82436601de 100644 --- a/ui/packages/consul-ui/app/serializers/kv.js +++ b/ui/packages/consul-ui/app/serializers/kv.js @@ -1,8 +1,6 @@ import Serializer from './application'; import { inject as service } from '@ember/service'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/kv'; -import { NSPACE_KEY } from 'consul-ui/models/nspace'; -import { NSPACE_QUERY_PARAM as API_NSPACE_KEY } from 'consul-ui/adapters/application'; export default class KvSerializer extends Serializer { @service('atob') decoder; @@ -32,7 +30,6 @@ export default class KvSerializer extends Serializer { body.map(item => { return { [this.slugKey]: item, - [NSPACE_KEY]: query[API_NSPACE_KEY], }; }) ); diff --git a/ui/packages/consul-ui/app/services/client/http.js b/ui/packages/consul-ui/app/services/client/http.js index 365b7f12c5..696e3fdee3 100644 --- a/ui/packages/consul-ui/app/services/client/http.js +++ b/ui/packages/consul-ui/app/services/client/http.js @@ -3,7 +3,11 @@ import { get } from '@ember/object'; import { next } from '@ember/runloop'; import { CACHE_CONTROL, CONTENT_TYPE } from 'consul-ui/utils/http/headers'; -import { HEADERS_TOKEN as CONSUL_TOKEN } from 'consul-ui/utils/http/consul'; +import { + HEADERS_TOKEN as CONSUL_TOKEN, + HEADERS_NAMESPACE as CONSUL_NAMESPACE, + HEADERS_DATACENTER as CONSUL_DATACENTER, +} from 'consul-ui/utils/http/consul'; import createURL from 'consul-ui/utils/http/create-url'; import createHeaders from 'consul-ui/utils/http/create-headers'; @@ -26,8 +30,9 @@ export const restartWhenAvailable = function(client) { throw e; }; }; -const stringifyQueryParams = createQueryParams(encodeURIComponent); -const parseURL = createURL(encodeURIComponent, stringifyQueryParams); +const QueryParams = { + stringify: createQueryParams(encodeURIComponent), +}; const parseHeaders = createHeaders(); const parseBody = function(strs, ...values) { @@ -72,21 +77,34 @@ const parseBody = function(strs, ...values) { const CLIENT_HEADERS = [CACHE_CONTROL, 'X-Request-ID', 'X-Range', 'Refresh']; export default class HttpService extends Service { - @service('dom') - dom; - - @service('client/connections') - connections; - - @service('client/transports/xhr') - transport; - - @service('settings') - settings; + @service('dom') dom; + @service('env') env; + @service('client/connections') connections; + @service('client/transports/xhr') transport; + @service('settings') settings; init() { super.init(...arguments); this._listeners = this.dom.listeners(); + this.parseURL = createURL(encodeURIComponent, obj => QueryParams.stringify(this.sanitize(obj))); + } + + sanitize(obj) { + if (!this.env.var('CONSUL_NSPACES_ENABLED')) { + delete obj.ns; + } else { + if (typeof obj.ns === 'undefined' || obj.ns === null || obj.ns === '') { + delete obj.ns; + } + } + if (!this.env.var('CONSUL_PARTITIONS_ENABLED')) { + delete obj.partition; + } else { + if (typeof obj.partition === 'undefined' || obj.partition === null || obj.partition === '') { + delete obj.partition; + } + } + return obj; } willDestroy() { @@ -95,11 +113,13 @@ export default class HttpService extends Service { } url() { - return parseURL(...arguments); + return this.parseURL(...arguments); } body() { - return parseBody(...arguments); + const res = parseBody(...arguments); + this.sanitize(res[0]); + return res; } requestParams(strs, ...values) { @@ -146,7 +166,7 @@ export default class HttpService extends Service { } } } else { - const str = stringifyQueryParams(params.data); + const str = QueryParams.stringify(params.data); if (str.length > 0) { if (params.url.indexOf('?') !== -1) { params.url = `${params.url}&${str}`; @@ -204,6 +224,15 @@ export default class HttpService extends Service { return prev; }, {}), ...params.clientHeaders, + // Add a 'pretend' Datacenter/Nspace header, they are not + // headers the come from the request but we add them here so + // we can use them later for store reconciliation. + // Namespace will look at the ns query parameter first, + // followed by the Namespace property of the users token, + // defaulting back to 'default' which will mainly be used in + // OSS + [CONSUL_DATACENTER]: params.data.dc, + [CONSUL_NAMESPACE]: params.data.ns || token.Namespace || 'default', }; const respond = function(cb) { return cb(headers, e.data.response); diff --git a/ui/packages/consul-ui/app/utils/create-fingerprinter.js b/ui/packages/consul-ui/app/utils/create-fingerprinter.js index 8c74b0be40..2ffe49327f 100644 --- a/ui/packages/consul-ui/app/utils/create-fingerprinter.js +++ b/ui/packages/consul-ui/app/utils/create-fingerprinter.js @@ -1,6 +1,7 @@ import { get } from '@ember/object'; + export default function(foreignKey, nspaceKey, hash = JSON.stringify) { - return function(primaryKey, slugKey, foreignKeyValue) { + return function(primaryKey, slugKey, foreignKeyValue, nspaceValue) { if (foreignKeyValue == null || foreignKeyValue.length < 1) { throw new Error('Unable to create fingerprint, missing foreignKey value'); } @@ -12,17 +13,22 @@ export default function(foreignKey, nspaceKey, hash = JSON.stringify) { } return get(item, slugKey); }); - const nspaceValue = get(item, nspaceKey) || 'default'; - // This ensures that all data objects have a Namespace value set, even - // in OSS. An empty Namespace will default to default - item[nspaceKey] = nspaceValue; + // in OSS. + if (typeof item[nspaceKey] === 'undefined') { + if (nspaceValue === '*') { + nspaceValue = 'default'; + } + item[nspaceKey] = nspaceValue; + } + // console.log(nspaceValue); + // item[nspaceKey] = '*'; if (typeof item[foreignKey] === 'undefined') { item[foreignKey] = foreignKeyValue; } if (typeof item[primaryKey] === 'undefined') { - item[primaryKey] = hash([nspaceValue, foreignKeyValue].concat(slugValues)); + item[primaryKey] = hash([item[nspaceKey], foreignKeyValue].concat(slugValues)); } return item; }; diff --git a/ui/packages/consul-ui/app/utils/http/xhr.js b/ui/packages/consul-ui/app/utils/http/xhr.js index 5965ef8994..cbdea6411f 100644 --- a/ui/packages/consul-ui/app/utils/http/xhr.js +++ b/ui/packages/consul-ui/app/utils/http/xhr.js @@ -13,7 +13,11 @@ export default function(parseHeaders, XHR) { options.complete(this.status); } }; - xhr.open(options.method, options.url, true); + let url = options.url; + if (url.endsWith('?')) { + url = url.substr(0, url.length - 1); + } + xhr.open(options.method, url, true); if (typeof options.headers === 'undefined') { options.headers = {}; } diff --git a/ui/packages/consul-ui/mock-api/v1/acl/policy/_ b/ui/packages/consul-ui/mock-api/v1/acl/policy/_ index 32fa47ea5e..a442f70f1f 100644 --- a/ui/packages/consul-ui/mock-api/v1/acl/policy/_ +++ b/ui/packages/consul-ui/mock-api/v1/acl/policy/_ @@ -1,9 +1,8 @@ { "ID": "${location.pathname.get(3)}", - "Namespace": "${ - typeof location.search.ns !== 'undefined' ? location.search.ns : - typeof http.body.Namespace !== 'undefined' ? http.body.Namespace : 'default' - }", +${typeof location.search.ns !== 'undefined' ? ` + "Namespace": "${location.search.ns}", +` : ``} "Description": "${location.pathname.get(3) === '00000000-0000-0000-0000-000000000001' ? 'Built-in Management Policy' : fake.lorem.sentence()}", ${ location.pathname.get(3) !== '00000000-0000-0000-0000-000000000001' ? ` "Datacenters": ${fake.helpers.randomize(['["aq west-5", "ch east-4"]'])}, diff --git a/ui/packages/consul-ui/mock-api/v1/acl/role/_ b/ui/packages/consul-ui/mock-api/v1/acl/role/_ index f891e50479..8fb6b1b491 100644 --- a/ui/packages/consul-ui/mock-api/v1/acl/role/_ +++ b/ui/packages/consul-ui/mock-api/v1/acl/role/_ @@ -1,10 +1,9 @@ { "ID": "${location.pathname.get(3)}", "Name": "${fake.hacker.noun() + '-role'}", - "Namespace": "${ - typeof location.search.ns !== 'undefined' ? location.search.ns : - typeof http.body.Namespace !== 'undefined' ? http.body.Namespace : 'default' - }", +${typeof location.search.ns !== 'undefined' ? ` + "Namespace": "${location.search.ns}", +` : ``} "Description": "${fake.lorem.sentence()}", "Policies": [ ${ @@ -50,7 +49,7 @@ return ` { "NodeName": "${fake.hacker.noun()}", - "Datacenter":"${fake.address.countryCode().toLowerCase()} ${ i % 2 ? "west" : "east"}-${i}" + "Datacenter":"${fake.address.countryCode().toLowerCase()} ${ i % 2 ? "west" : "east"}-${i}" } `; } diff --git a/ui/packages/consul-ui/mock-api/v1/acl/token/_ b/ui/packages/consul-ui/mock-api/v1/acl/token/_ index dc01a3c450..02b234a657 100644 --- a/ui/packages/consul-ui/mock-api/v1/acl/token/_ +++ b/ui/packages/consul-ui/mock-api/v1/acl/token/_ @@ -2,10 +2,9 @@ "AccessorID": "${location.pathname.get(3)}", "SecretID":"${fake.random.uuid()}", "IDPName": "${fake.hacker.noun()}", - "Namespace": "${ - typeof location.search.ns !== 'undefined' ? location.search.ns : - typeof http.body.Namespace !== 'undefined' ? http.body.Namespace : 'default' - }", +${typeof location.search.ns !== 'undefined' ? ` + "Namespace": "${location.search.ns}", +` : ``} ${ location.pathname.get(3) === '00000000-0000-0000-0000-000000000002' ? ` "Name": "${fake.hacker.noun()}", diff --git a/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/as-many/add-existing.feature b/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/as-many/add-existing.feature index 540f977d20..54e64f8b47 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/as-many/add-existing.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/as-many/add-existing.feature @@ -31,14 +31,14 @@ Feature: dc / acls / policies / as many / add existing: Add existing policy And I click ".ember-power-select-option:first-child" And I see 2 policy models on the policies component And I submit - Then a PUT request was made to "/v1/acl/[Model]/key?dc=datacenter" with the body from yaml + Then a PUT request was made to "/v1/acl/[Model]/key?dc=datacenter&ns=@!namespace" from yaml --- - Namespace: @namespace - Policies: - - ID: policy-1 - Name: Policy 1 - - ID: policy-2 - Name: Policy 2 + body: + Policies: + - ID: policy-1 + Name: Policy 1 + - ID: policy-2 + Name: Policy 2 --- Then the url should be /datacenter/acls/[Model]s And "[data-notification]" has the "notification-update" class diff --git a/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/as-many/add-new.feature b/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/as-many/add-new.feature index fc9ab8b286..367ae9221d 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/as-many/add-new.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/as-many/add-new.feature @@ -23,19 +23,17 @@ Feature: dc / acls / policies / as many / add new: Add new policy Rules: key {} --- And I click submit on the policies.form - Then a PUT request was made to "/v1/acl/policy?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/policy?dc=datacenter&ns=@namespace" from yaml --- body: Name: New-Policy Description: New Policy Description - Namespace: @namespace Rules: key {} --- And I submit - Then a PUT request was made to "/v1/acl/[Model]/key?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/[Model]/key?dc=datacenter&ns=@!namespace" from yaml --- body: - Namespace: @namespace Policies: - ID: ee52203d-989f-4f7a-ab5a-2bef004164ca-1 Name: New-Policy @@ -57,10 +55,9 @@ Feature: dc / acls / policies / as many / add new: Add new policy And I click serviceIdentity on the policies.form And I click submit on the policies.form And I submit - Then a PUT request was made to "/v1/acl/[Model]/key?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/[Model]/key?dc=datacenter&ns=@!namespace" from yaml --- body: - Namespace: @namespace ServiceIdentities: - ServiceName: New-Service-Identity --- @@ -81,10 +78,9 @@ Feature: dc / acls / policies / as many / add new: Add new policy And I click nodeIdentity on the policies.form And I click submit on the policies.form And I submit - Then a PUT request was made to "/v1/acl/[Model]/key?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/[Model]/key?dc=datacenter&ns=@!namespace" from yaml --- body: - Namespace: @namespace NodeIdentities: - NodeName: New-Node-Identity Datacenter: datacenter @@ -112,12 +108,12 @@ Feature: dc / acls / policies / as many / add new: Add new policy Rules: key {} --- And I click submit on the policies.form - Then a PUT request was made to "/v1/acl/policy?dc=datacenter" with the body from yaml + Then a PUT request was made to "/v1/acl/policy?dc=datacenter&ns=@namespace" from yaml --- - Name: New-Policy - Description: New Policy Description - Namespace: @namespace - Rules: key {} + body: + Name: New-Policy + Description: New Policy Description + Rules: key {} --- And I see error on the policies.form.rules like 'Invalid service policy: acl.ServicePolicy{Name:"service", Policy:"", Sentinel:acl.Sentinel{Code:"", EnforcementLevel:""}, Intentions:""}' Where: diff --git a/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/as-many/remove.feature b/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/as-many/remove.feature index 7231423128..41388b8edd 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/as-many/remove.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/as-many/remove.feature @@ -25,10 +25,9 @@ Feature: dc / acls / policies / as many / remove: Remove And I click confirmDelete on the policies.selectedOptions And I see 0 policy models on the policies component And I submit - Then a PUT request was made to "/v1/acl/[Model]/key?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/[Model]/key?dc=datacenter&ns=@!namespace" from yaml --- body: - Namespace: @namespace Policies: [[]] --- Then the url should be /datacenter/acls/[Model]s diff --git a/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/create.feature b/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/create.feature index 256bb4a8d1..0e9f6a21d1 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/create.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/create.feature @@ -17,11 +17,10 @@ Feature: dc / acls / policies / create Description: [Description] --- And I submit - Then a PUT request was made to "/v1/acl/policy?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/policy?dc=datacenter&ns=@namespace" from yaml --- body: Name: my-policy - Namespace: @namespace Description: [Description] --- Then the url should be /datacenter/acls/policies diff --git a/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/update.feature b/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/update.feature index 129a2116ea..e0857d14ed 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/update.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/acls/policies/update.feature @@ -26,13 +26,12 @@ Feature: dc / acls / policies / update: ACL Policy Update And I click validDatacenters And I click datacenter And I submit - Then a PUT request was made to "/v1/acl/policy/policy-id?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/policy/policy-id?dc=datacenter&ns=@!namespace" from yaml --- body: Name: [Name] Description: [Description] Rules: [Rules] - Namespace: @namespace Datacenters: - datacenter diff --git a/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/as-many/add-existing.feature b/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/as-many/add-existing.feature index 256fd8f23a..6f22975753 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/as-many/add-existing.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/as-many/add-existing.feature @@ -35,10 +35,9 @@ Feature: dc / acls / roles / as many / add existing: Add existing Description: The Description --- And I submit - Then a PUT request was made to "/v1/acl/token/key?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/token/key?dc=datacenter&ns=@!namespace" from yaml --- body: - Namespace: @namespace Description: The Description Roles: - ID: role-1 diff --git a/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/as-many/add-new.feature b/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/as-many/add-new.feature index 7e0746ad28..45249a8e4a 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/as-many/add-new.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/as-many/add-new.feature @@ -30,19 +30,17 @@ Feature: dc / acls / roles / as-many / add-new: Add new --- Scenario: Add Policy-less Role And I click submit on the roles.form - Then a PUT request was made to "/v1/acl/role?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/role?dc=datacenter&ns=@namespace" from yaml --- body: Name: New-Role - Namespace: @namespace Description: New Role Description --- And I submit - Then a PUT request was made to "/v1/acl/token/key?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/token/key?dc=datacenter&ns=@namespace" from yaml --- body: Description: The Description - Namespace: @namespace Roles: - Name: New-Role ID: ee52203d-989f-4f7a-ab5a-2bef004164ca-1 @@ -54,22 +52,20 @@ Feature: dc / acls / roles / as-many / add-new: Add new And I click "#new-role .ember-power-select-trigger" And I click ".ember-power-select-option:first-child" And I click submit on the roles.form - Then a PUT request was made to "/v1/acl/role?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/role?dc=datacenter&ns=@namespace" from yaml --- body: Name: New-Role Description: New Role Description - Namespace: @namespace Policies: - ID: policy-1 Name: policy --- And I submit - Then a PUT request was made to "/v1/acl/token/key?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/token/key?dc=datacenter&ns=@namespace" from yaml --- body: Description: The Description - Namespace: @namespace Roles: - Name: New-Role ID: ee52203d-989f-4f7a-ab5a-2bef004164ca-1 @@ -87,32 +83,29 @@ Feature: dc / acls / roles / as-many / add-new: Add new --- # This next line is actually the popped up policyForm due to the way things currently work And I click submit on the roles.form - Then a PUT request was made to "/v1/acl/policy?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/policy?dc=datacenter&ns=@namespace" from yaml --- body: Name: New-Policy Description: New Policy Description - Namespace: @namespace Rules: key {} --- And I click submit on the roles.form - Then a PUT request was made to "/v1/acl/role?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/role?dc=datacenter&ns=@namespace" from yaml --- body: Name: New-Role Description: New Role Description - Namespace: @namespace Policies: # TODO: Ouch, we need to do deep partial comparisons here - ID: ee52203d-989f-4f7a-ab5a-2bef004164ca-1 Name: New-Policy --- And I submit - Then a PUT request was made to "/v1/acl/token/key?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/token/key?dc=datacenter&ns=@namespace" from yaml --- body: Description: The Description - Namespace: @namespace Roles: - Name: New-Role ID: ee52203d-989f-4f7a-ab5a-2bef004164ca-1 @@ -130,21 +123,19 @@ Feature: dc / acls / roles / as-many / add-new: Add new # This next line is actually the popped up policyForm due to the way things currently work And I click submit on the roles.form And I click submit on the roles.form - Then a PUT request was made to "/v1/acl/role?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/role?dc=datacenter&ns=@namespace" from yaml --- body: Name: New-Role Description: New Role Description - Namespace: @namespace ServiceIdentities: - ServiceName: New-Service-Identity --- And I submit - Then a PUT request was made to "/v1/acl/token/key?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/token/key?dc=datacenter&ns=@namespace" from yaml --- body: Description: The Description - Namespace: @namespace Roles: - Name: New-Role ID: ee52203d-989f-4f7a-ab5a-2bef004164ca-1 diff --git a/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/as-many/remove.feature b/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/as-many/remove.feature index 8c4daf05b8..37634d459d 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/as-many/remove.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/as-many/remove.feature @@ -21,10 +21,9 @@ Feature: dc / acls / roles / as-many / remove: Remove And I click confirmDelete on the roles.selectedOptions And I see 0 role models on the roles component And I submit - Then a PUT request was made to "/v1/acl/token/key?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/token/key?dc=datacenter&ns=@!namespace" from yaml --- body: - Namespace: @namespace Roles: [] --- Then the url should be /datacenter/acls/tokens diff --git a/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/create.feature b/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/create.feature index ef3c109f13..ce63a93df5 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/create.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/create.feature @@ -17,10 +17,9 @@ Feature: dc / acls / roles / create Description: [Description] --- And I submit - Then a PUT request was made to "/v1/acl/role?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/role?dc=datacenter&ns=@namespace" from yaml --- body: - Namespace: @namespace Name: my-role Description: [Description] --- diff --git a/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/update.feature b/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/update.feature index 2f82852c15..795fd7908f 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/update.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/acls/roles/update.feature @@ -22,10 +22,9 @@ Feature: dc / acls / roles / update: ACL Role Update Description: [Description] --- And I submit - Then a PUT request was made to "/v1/acl/role/role-id?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/role/role-id?dc=datacenter&ns=@!namespace" from yaml --- body: - Namespace: @namespace Name: [Name] Description: [Description] --- diff --git a/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/create.feature b/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/create.feature index 6542063106..351b21aa39 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/create.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/create.feature @@ -15,10 +15,9 @@ Feature: dc / acls / tokens / create Description: [Description] --- And I submit - Then a PUT request was made to "/v1/acl/token?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/token?dc=datacenter&ns=@namespace" from yaml --- body: - Namespace: @namespace Description: [Description] --- Then the url should be /datacenter/acls/tokens diff --git a/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/own-no-delete.feature b/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/own-no-delete.feature index 7ef9644ede..3a6e9b11f8 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/own-no-delete.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/own-no-delete.feature @@ -6,6 +6,7 @@ Feature: dc / acls / tokens / own-no-delete: The your current token has no delet --- AccessorID: token SecretID: ee52203d-989f-4f7a-ab5a-2bef004164ca + Namespace: @!namespace --- Scenario: On the listing page Given settings from yaml diff --git a/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/update.feature b/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/update.feature index c3b8e3d77c..4770cedf58 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/update.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/update.feature @@ -20,10 +20,9 @@ Feature: dc / acls / tokens / update: ACL Token Update Description: [Description] --- And I submit - Then a PUT request was made to "/v1/acl/token/key?dc=datacenter" from yaml + Then a PUT request was made to "/v1/acl/token/key?dc=datacenter&ns=@!namespace" from yaml --- body: - Namespace: @namespace Description: [Description] --- Then the url should be /datacenter/acls/tokens diff --git a/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/use.feature b/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/use.feature index 19c4aedbe7..3800e8a020 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/use.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/acls/tokens/use.feature @@ -6,6 +6,7 @@ Feature: dc / acls / tokens / use: Using an ACL token --- AccessorID: token SecretID: ee52203d-989f-4f7a-ab5a-2bef004164ca + Namespace: @!namespace --- And settings from yaml --- diff --git a/ui/packages/consul-ui/tests/acceptance/dc/kvs/sessions/invalidate.feature b/ui/packages/consul-ui/tests/acceptance/dc/kvs/sessions/invalidate.feature index 778df42163..1b3672dc00 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/kvs/sessions/invalidate.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/kvs/sessions/invalidate.feature @@ -24,7 +24,7 @@ Feature: dc / kvs / sessions / invalidate: Invalidate Lock Sessions And "[data-notification]" has the "notification-delete" class And "[data-notification]" has the "success" class Scenario: Invalidating a lock session and receiving an error - Given the url "/v1/session/destroy/ee52203d-989f-4f7a-ab5a-2bef004164ca?dc=datacenter&ns=@!namespace" responds with a 500 status + Given the url "/v1/session/destroy/ee52203d-989f-4f7a-ab5a-2bef004164ca?dc=datacenter&ns=@namespace" responds with a 500 status And I click delete on the session And I click confirmDelete on the session Then the url should be /datacenter/kv/key/edit diff --git a/ui/packages/consul-ui/tests/acceptance/dc/kvs/update.feature b/ui/packages/consul-ui/tests/acceptance/dc/kvs/update.feature index ff93ebe767..2f0a0f4532 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/kvs/update.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/kvs/update.feature @@ -22,7 +22,7 @@ Feature: dc / kvs / update: KV Update value: [Value] --- And I submit - Then a PUT request was made to "/v1/kv/[EncodedName]?dc=datacenter&flags=12&ns=@!namespace" with the body "[Value]" + Then a PUT request was made to "/v1/kv/[EncodedName]?dc=datacenter&ns=@!namespace&flags=12" with the body "[Value]" And "[data-notification]" has the "notification-update" class And "[data-notification]" has the "success" class Where: @@ -53,7 +53,7 @@ Feature: dc / kvs / update: KV Update value: ' ' --- And I submit - Then a PUT request was made to "/v1/kv/key?dc=datacenter&flags=12&ns=@!namespace" with the body " " + Then a PUT request was made to "/v1/kv/key?dc=datacenter&ns=@!namespace&flags=12" with the body " " Then the url should be /datacenter/kv And the title should be "Key/Value - Consul" And "[data-notification]" has the "notification-update" class @@ -77,7 +77,7 @@ Feature: dc / kvs / update: KV Update value: '' --- And I submit - Then a PUT request was made to "/v1/kv/key?dc=datacenter&flags=12&ns=@!namespace" with no body + Then a PUT request was made to "/v1/kv/key?dc=datacenter&ns=@!namespace&flags=12" with no body Then the url should be /datacenter/kv And "[data-notification]" has the "notification-update" class And "[data-notification]" has the "success" class @@ -95,7 +95,7 @@ Feature: dc / kvs / update: KV Update --- Then the url should be /datacenter/kv/key/edit And I submit - Then a PUT request was made to "/v1/kv/key?dc=datacenter&flags=12&ns=@!namespace" with no body + Then a PUT request was made to "/v1/kv/key?dc=datacenter&ns=@!namespace&flags=12" with no body Then the url should be /datacenter/kv And "[data-notification]" has the "notification-update" class And "[data-notification]" has the "success" class diff --git a/ui/packages/consul-ui/tests/acceptance/dc/nodes/sessions/invalidate.feature b/ui/packages/consul-ui/tests/acceptance/dc/nodes/sessions/invalidate.feature index 887b91987c..43dfcb7ae5 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/nodes/sessions/invalidate.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/nodes/sessions/invalidate.feature @@ -30,7 +30,7 @@ Feature: dc / nodes / sessions / invalidate: Invalidate Lock Sessions And "[data-notification]" has the "notification-delete" class And "[data-notification]" has the "success" class Scenario: Invalidating a lock session and receiving an error - Given the url "/v1/session/destroy/7bbbd8bb-fff3-4292-b6e3-cfedd788546a?dc=dc1&ns=@!namespace" responds with a 500 status + Given the url "/v1/session/destroy/7bbbd8bb-fff3-4292-b6e3-cfedd788546a?dc=dc1&ns=@namespace" responds with a 500 status And I click delete on the sessions And I click confirmDelete on the sessions Then the url should be /dc1/nodes/node-0/lock-sessions diff --git a/ui/packages/consul-ui/tests/dictionary.js b/ui/packages/consul-ui/tests/dictionary.js index a04e4b02ab..86dfc12a89 100644 --- a/ui/packages/consul-ui/tests/dictionary.js +++ b/ui/packages/consul-ui/tests/dictionary.js @@ -50,10 +50,12 @@ export default utils => (annotations, nspace, dict = new Yadda.Dictionary()) => // mainly for DELETEs if (env('CONSUL_NSPACES_ENABLED')) { val = val.replace(/ns=@!namespace/g, `ns=${nspace || 'default'}`); + val = val.replace(/Namespace: @!namespace/g, `Namespace: ${nspace || 'default'}`); } else { val = val.replace(/&ns=@!namespace/g, ''); val = val.replace(/&ns=\*/g, ''); val = val.replace(/- \/v1\/namespaces/g, ''); + val = val.replace(/Namespace: @!namespace/g, ''); } if (typeof nspace === 'undefined' || nspace === '') { val = val.replace(/Namespace: @namespace/g, '').replace(/&ns=@namespace/g, ''); diff --git a/ui/packages/consul-ui/tests/helpers/repo.js b/ui/packages/consul-ui/tests/helpers/repo.js index 91ad2f6fe0..228a48dde1 100644 --- a/ui/packages/consul-ui/tests/helpers/repo.js +++ b/ui/packages/consul-ui/tests/helpers/repo.js @@ -20,13 +20,15 @@ const stubAdapterResponse = function(cb, payload, adapter) { set(adapter, 'client', { request: function(cb) { return cb(function() { + const params = client.requestParams(...arguments); + payload.headers['X-Consul-Namespace'] = params.data.ns || 'default'; return Promise.resolve(function(cb) { - return cb({}, payloadClone); + return cb(payload.headers, payloadClone.payload); }); }); }, }); - return cb(payload).then(function(result) { + return cb(payload.payload).then(function(result) { set(adapter, 'client', client); return result; }); @@ -61,6 +63,11 @@ export default function(name, method, service, stub, test, assert) { headers: { cookie: cookies, }, + }).then(function(payload) { + return { + headers: {}, + payload: payload, + }; }); }; const parseResponse = function(response) { diff --git a/ui/packages/consul-ui/tests/integration/adapters/acl-test.js b/ui/packages/consul-ui/tests/integration/adapters/acl-test.js index 930463de37..398292bffa 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/acl-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/acl-test.js @@ -7,8 +7,9 @@ module('Integration | Adapter | acl', function(hooks) { test('requestForQuery returns the correct url', function(assert) { const adapter = this.owner.lookup('adapter:acl'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `GET /v1/acl/list?dc=${dc}`; - const actual = adapter.requestForQuery(client.url, { + const actual = adapter.requestForQuery(request, { dc: dc, }); assert.equal(actual, expected); @@ -16,8 +17,9 @@ module('Integration | Adapter | acl', function(hooks) { test('requestForQueryRecord returns the correct url', function(assert) { const adapter = this.owner.lookup('adapter:acl'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `GET /v1/acl/info/${id}?dc=${dc}`; - const actual = adapter.requestForQueryRecord(client.url, { + const actual = adapter.requestForQueryRecord(request, { dc: dc, id: id, }); @@ -26,8 +28,9 @@ module('Integration | Adapter | acl', function(hooks) { test("requestForQueryRecord throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:acl'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQueryRecord(client.url, { + adapter.requestForQueryRecord(request, { dc: dc, }); }); @@ -35,10 +38,11 @@ module('Integration | Adapter | acl', function(hooks) { test('requestForCreateRecord returns the correct url', function(assert) { const adapter = this.owner.lookup('adapter:acl'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `PUT /v1/acl/create?dc=${dc}`; const actual = adapter .requestForCreateRecord( - client.url, + request, {}, { Datacenter: dc, @@ -51,10 +55,11 @@ module('Integration | Adapter | acl', function(hooks) { test('requestForUpdateRecord returns the correct url', function(assert) { const adapter = this.owner.lookup('adapter:acl'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `PUT /v1/acl/update?dc=${dc}`; const actual = adapter .requestForUpdateRecord( - client.url, + request, {}, { Datacenter: dc, @@ -67,10 +72,11 @@ module('Integration | Adapter | acl', function(hooks) { test('requestForDeleteRecord returns the correct url', function(assert) { const adapter = this.owner.lookup('adapter:acl'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `PUT /v1/acl/destroy/${id}?dc=${dc}`; const actual = adapter .requestForDeleteRecord( - client.url, + request, {}, { Datacenter: dc, @@ -83,10 +89,11 @@ module('Integration | Adapter | acl', function(hooks) { test('requestForCloneRecord returns the correct url', function(assert) { const adapter = this.owner.lookup('adapter:acl'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `PUT /v1/acl/clone/${id}?dc=${dc}`; const actual = adapter .requestForCloneRecord( - client.url, + request, {}, { Datacenter: dc, diff --git a/ui/packages/consul-ui/tests/integration/adapters/auth-method-test.js b/ui/packages/consul-ui/tests/integration/adapters/auth-method-test.js index 8c41801ac2..f839d413f4 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/auth-method-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/auth-method-test.js @@ -10,8 +10,9 @@ module('Integration | Adapter | auth-method', function(hooks) { test('requestForQueryRecord returns the correct url/method', function(assert) { const adapter = this.owner.lookup('adapter:auth-method'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/acl/auth-method/${id}?dc=${dc}`; - const actual = adapter.requestForQueryRecord(client.requestParams.bind(client), { + const actual = adapter.requestForQueryRecord(request, { dc: dc, id: id, }); @@ -20,8 +21,9 @@ module('Integration | Adapter | auth-method', function(hooks) { test("requestForQueryRecord throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:auth-method'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQueryRecord(client.url, { + adapter.requestForQueryRecord(request, { dc: dc, }); }); @@ -29,7 +31,8 @@ module('Integration | Adapter | auth-method', function(hooks) { test('requestForQueryRecord returns the correct body', function(assert) { return nspaceRunner( (adapter, serializer, client) => { - return adapter.requestForQueryRecord(client.body, { + const request = client.body.bind(client); + return adapter.requestForQueryRecord(request, { id: id, dc: dc, ns: 'team-1', diff --git a/ui/packages/consul-ui/tests/integration/adapters/binding-rule-test.js b/ui/packages/consul-ui/tests/integration/adapters/binding-rule-test.js index 08f64d2076..74c59dc1af 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/binding-rule-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/binding-rule-test.js @@ -9,8 +9,9 @@ module('Integration | Adapter | binding-rule', function(hooks) { test('requestForQuery returns the correct url/method', function(assert) { const adapter = this.owner.lookup('adapter:binding-rule'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/acl/binding-rules?dc=${dc}`; - const actual = adapter.requestForQuery(client.requestParams.bind(client), { + const actual = adapter.requestForQuery(request, { dc: dc, }); assert.equal(`${actual.method} ${actual.url}`, expected); @@ -18,7 +19,8 @@ module('Integration | Adapter | binding-rule', function(hooks) { test('requestForQuery returns the correct body', function(assert) { return nspaceRunner( (adapter, serializer, client) => { - return adapter.requestForQuery(client.body, { + const request = client.body.bind(client); + return adapter.requestForQuery(request, { dc: dc, ns: 'team-1', index: 1, diff --git a/ui/packages/consul-ui/tests/integration/adapters/coordinate-test.js b/ui/packages/consul-ui/tests/integration/adapters/coordinate-test.js index 6989ae9c2f..d4f62530dc 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/coordinate-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/coordinate-test.js @@ -6,8 +6,9 @@ module('Integration | Adapter | coordinate', function(hooks) { test('requestForQuery returns the correct url', function(assert) { const adapter = this.owner.lookup('adapter:coordinate'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/coordinate/nodes?dc=${dc}`; - const actual = adapter.requestForQuery(client.requestParams.bind(client), { + const actual = adapter.requestForQuery(request, { dc: dc, }); assert.equal(`${actual.method} ${actual.url}`, expected); @@ -15,10 +16,11 @@ module('Integration | Adapter | coordinate', function(hooks) { test('requestForQuery returns the correct body', function(assert) { const adapter = this.owner.lookup('adapter:coordinate'); const client = this.owner.lookup('service:client/http'); + const request = client.body.bind(client); const expected = { index: 1, }; - const [actual] = adapter.requestForQuery(client.body, { + const [actual] = adapter.requestForQuery(request, { dc: dc, index: 1, }); diff --git a/ui/packages/consul-ui/tests/integration/adapters/dc-test.js b/ui/packages/consul-ui/tests/integration/adapters/dc-test.js index 50add0ffa7..2569b55e6b 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/dc-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/dc-test.js @@ -5,8 +5,9 @@ module('Integration | Adapter | dc', function(hooks) { test('requestForQuery returns the correct url', function(assert) { const adapter = this.owner.lookup('adapter:dc'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `GET /v1/catalog/datacenters`; - const actual = adapter.requestForQuery(client.url); + const actual = adapter.requestForQuery(request); assert.equal(actual, expected); }); }); diff --git a/ui/packages/consul-ui/tests/integration/adapters/discovery-chain-test.js b/ui/packages/consul-ui/tests/integration/adapters/discovery-chain-test.js index 3faac8c4fc..fb82571c14 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/discovery-chain-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/discovery-chain-test.js @@ -10,8 +10,9 @@ module('Integration | Adapter | discovery-chain', function(hooks) { test('requestForQueryRecord returns the correct url/method', function(assert) { const adapter = this.owner.lookup('adapter:discovery-chain'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/discovery-chain/${id}?dc=${dc}`; - const actual = adapter.requestForQueryRecord(client.requestParams.bind(client), { + const actual = adapter.requestForQueryRecord(request, { dc: dc, id: id, }); @@ -20,8 +21,9 @@ module('Integration | Adapter | discovery-chain', function(hooks) { test("requestForQueryRecord throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:discovery-chain'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQueryRecord(client.url, { + adapter.requestForQueryRecord(request, { dc: dc, }); }); @@ -29,7 +31,8 @@ module('Integration | Adapter | discovery-chain', function(hooks) { test('requestForQueryRecord returns the correct body', function(assert) { return nspaceRunner( (adapter, serializer, client) => { - return adapter.requestForQueryRecord(client.body, { + const request = client.body.bind(client); + return adapter.requestForQueryRecord(request, { id: id, dc: dc, ns: 'team-1', diff --git a/ui/packages/consul-ui/tests/integration/adapters/intention-test.js b/ui/packages/consul-ui/tests/integration/adapters/intention-test.js index 19b567df41..dd72d13d6b 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/intention-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/intention-test.js @@ -11,7 +11,8 @@ module('Integration | Adapter | intention', function(hooks) { test('requestForQuery returns the correct url', function(assert) { return nspaceRunner( (adapter, serializer, client) => { - return adapter.requestForQuery(client.body, { + const request = client.body.bind(client); + return adapter.requestForQuery(request, { dc: dc, ns: 'team-1', filter: '*', @@ -34,9 +35,10 @@ module('Integration | Adapter | intention', function(hooks) { test('requestForQueryRecord returns the correct url', function(assert) { const adapter = this.owner.lookup('adapter:intention'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `GET /v1/connect/intentions/exact?source=SourceNS%2FSourceName&destination=DestinationNS%2FDestinationName&dc=${dc}`; const actual = adapter - .requestForQueryRecord(client.url, { + .requestForQueryRecord(request, { dc: dc, id: id, }) @@ -46,8 +48,9 @@ module('Integration | Adapter | intention', function(hooks) { test("requestForQueryRecord throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:intention'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQueryRecord(client.url, { + adapter.requestForQueryRecord(request, { dc: dc, }); }); @@ -55,10 +58,11 @@ module('Integration | Adapter | intention', function(hooks) { test('requestForCreateRecord returns the correct url', function(assert) { const adapter = this.owner.lookup('adapter:intention'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `PUT /v1/connect/intentions/exact?source=SourceNS%2FSourceName&destination=DestinationNS%2FDestinationName&dc=${dc}`; const actual = adapter .requestForCreateRecord( - client.url, + request, {}, { Datacenter: dc, @@ -74,10 +78,11 @@ module('Integration | Adapter | intention', function(hooks) { test('requestForUpdateRecord returns the correct url', function(assert) { const adapter = this.owner.lookup('adapter:intention'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `PUT /v1/connect/intentions/exact?source=SourceNS%2FSourceName&destination=DestinationNS%2FDestinationName&dc=${dc}`; const actual = adapter .requestForUpdateRecord( - client.url, + request, {}, { Datacenter: dc, @@ -93,10 +98,11 @@ module('Integration | Adapter | intention', function(hooks) { test('requestForDeleteRecord returns the correct url', function(assert) { const adapter = this.owner.lookup('adapter:intention'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `DELETE /v1/connect/intentions/exact?source=SourceNS%2FSourceName&destination=DestinationNS%2FDestinationName&dc=${dc}`; const actual = adapter .requestForDeleteRecord( - client.url, + request, {}, { Datacenter: dc, diff --git a/ui/packages/consul-ui/tests/integration/adapters/kv-test.js b/ui/packages/consul-ui/tests/integration/adapters/kv-test.js index f7f48867fd..75b0e1fce6 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/kv-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/kv-test.js @@ -13,10 +13,11 @@ module('Integration | Adapter | kv', function(hooks) { test(`requestForQuery returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:kv'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/kv/${id}?keys&dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQuery(client.requestParams.bind(client), { + let actual = adapter.requestForQuery(request, { dc: dc, id: id, ns: nspace, @@ -26,10 +27,11 @@ module('Integration | Adapter | kv', function(hooks) { test(`requestForQueryRecord returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:kv'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/kv/${id}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQueryRecord(client.requestParams.bind(client), { + let actual = adapter.requestForQueryRecord(request, { dc: dc, id: id, ns: nspace, @@ -39,12 +41,13 @@ module('Integration | Adapter | kv', function(hooks) { test(`requestForCreateRecord returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:kv'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `PUT /v1/kv/${id}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; let actual = adapter .requestForCreateRecord( - client.url, + request, {}, { Datacenter: dc, @@ -60,13 +63,14 @@ module('Integration | Adapter | kv', function(hooks) { test(`requestForUpdateRecord returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:kv'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const flags = 12; - const expected = `PUT /v1/kv/${id}?dc=${dc}&flags=${flags}${ + const expected = `PUT /v1/kv/${id}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` - }`; + }&flags=${flags}`; let actual = adapter .requestForUpdateRecord( - client.url, + request, {}, { Datacenter: dc, @@ -83,12 +87,13 @@ module('Integration | Adapter | kv', function(hooks) { test(`requestForDeleteRecord returns the correct url/method when the nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:kv'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `DELETE /v1/kv/${id}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; let actual = adapter .requestForDeleteRecord( - client.url, + request, {}, { Datacenter: dc, @@ -103,13 +108,14 @@ module('Integration | Adapter | kv', function(hooks) { test(`requestForDeleteRecord returns the correct url/method for folders when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:kv'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const folder = `${id}/`; const expected = `DELETE /v1/kv/${folder}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }&recurse`; let actual = adapter .requestForDeleteRecord( - client.url, + request, {}, { Datacenter: dc, @@ -125,8 +131,9 @@ module('Integration | Adapter | kv', function(hooks) { test("requestForQuery throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:kv'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQuery(client.url, { + adapter.requestForQuery(request, { dc: dc, }); }); @@ -134,8 +141,9 @@ module('Integration | Adapter | kv', function(hooks) { test("requestForQueryRecord throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:kv'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQueryRecord(client.url, { + adapter.requestForQueryRecord(request, { dc: dc, }); }); diff --git a/ui/packages/consul-ui/tests/integration/adapters/node-test.js b/ui/packages/consul-ui/tests/integration/adapters/node-test.js index b718e984f8..32f1e8eacf 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/node-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/node-test.js @@ -13,10 +13,11 @@ module('Integration | Adapter | node', function(hooks) { test(`requestForQuery returns the correct url when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:node'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/internal/ui/nodes?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - const actual = adapter.requestForQuery(client.requestParams.bind(client), { + const actual = adapter.requestForQuery(request, { dc: dc, ns: nspace, }); @@ -25,10 +26,11 @@ module('Integration | Adapter | node', function(hooks) { test(`requestForQueryRecord returns the correct url when the nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:node'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/internal/ui/node/${id}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - const actual = adapter.requestForQueryRecord(client.requestParams.bind(client), { + const actual = adapter.requestForQueryRecord(request, { dc: dc, id: id, ns: nspace, @@ -40,8 +42,9 @@ module('Integration | Adapter | node', function(hooks) { test("requestForQueryRecord throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:node'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); assert.throws(function() { - adapter.requestForQueryRecord(client.url, { + adapter.requestForQueryRecord(request, { dc: dc, }); }); @@ -49,8 +52,9 @@ module('Integration | Adapter | node', function(hooks) { test('requestForQueryLeader returns the correct url', function(assert) { const adapter = this.owner.lookup('adapter:node'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/status/leader?dc=${dc}`; - const actual = adapter.requestForQueryLeader(client.requestParams.bind(client), { + const actual = adapter.requestForQueryLeader(request, { dc: dc, }); assert.equal(`${actual.method} ${actual.url}`, expected); diff --git a/ui/packages/consul-ui/tests/integration/adapters/nspace-test.js b/ui/packages/consul-ui/tests/integration/adapters/nspace-test.js index ecfde700a4..3e7a697e9d 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/nspace-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/nspace-test.js @@ -8,15 +8,17 @@ module('Integration | Adapter | nspace', function(hooks) { test('requestForQuery returns the correct url/method', function(assert) { const adapter = this.owner.lookup('adapter:nspace'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/namespaces`; - const actual = adapter.requestForQuery(client.requestParams.bind(client), {}); + const actual = adapter.requestForQuery(request, {}); assert.equal(`${actual.method} ${actual.url}`, expected); }); test('requestForQueryRecord returns the correct url/method', function(assert) { const adapter = this.owner.lookup('adapter:nspace'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `GET /v1/namespace/${id}`; - const actual = adapter.requestForQueryRecord(client.url, { + const actual = adapter.requestForQueryRecord(request, { id: id, }); assert.equal(actual, expected); @@ -24,8 +26,9 @@ module('Integration | Adapter | nspace', function(hooks) { test("requestForQueryRecord throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:nspace'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQueryRecord(client.url, {}); + adapter.requestForQueryRecord(request, {}); }); }); }); diff --git a/ui/packages/consul-ui/tests/integration/adapters/oidc-provider-test.js b/ui/packages/consul-ui/tests/integration/adapters/oidc-provider-test.js index 480ad96e3d..1777c7c306 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/oidc-provider-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/oidc-provider-test.js @@ -14,10 +14,11 @@ module('Integration | Adapter | oidc-provider', function(hooks) { test('requestForQuery returns the correct url/method', function(assert) { const adapter = this.owner.lookup('adapter:oidc-provider'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/internal/ui/oidc-auth-methods?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQuery(client.requestParams.bind(client), { + let actual = adapter.requestForQuery(request, { dc: dc, ns: nspace, }); @@ -26,9 +27,12 @@ module('Integration | Adapter | oidc-provider', function(hooks) { test('requestForQueryRecord returns the correct url/method', function(assert) { const adapter = this.owner.lookup('adapter:oidc-provider'); const client = this.owner.lookup('service:client/http'); - const expected = `POST /v1/acl/oidc/auth-url?dc=${dc}`; + const request = client.url.bind(client); + const expected = `POST /v1/acl/oidc/auth-url?dc=${dc}${ + shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` + }`; const actual = adapter - .requestForQueryRecord(client.url, { + .requestForQueryRecord(request, { dc: dc, id: id, ns: nspace, @@ -40,8 +44,9 @@ module('Integration | Adapter | oidc-provider', function(hooks) { test("requestForQueryRecord throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:oidc-provider'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQueryRecord(client.url, { + adapter.requestForQueryRecord(request, { dc: dc, }); }); @@ -49,9 +54,12 @@ module('Integration | Adapter | oidc-provider', function(hooks) { test('requestForAuthorize returns the correct url/method', function(assert) { const adapter = this.owner.lookup('adapter:oidc-provider'); const client = this.owner.lookup('service:client/http'); - const expected = `POST /v1/acl/oidc/callback?dc=${dc}`; + const request = client.url.bind(client); + const expected = `POST /v1/acl/oidc/callback?dc=${dc}${ + shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` + }`; const actual = adapter - .requestForAuthorize(client.url, { + .requestForAuthorize(request, { dc: dc, id: id, code: 'code', @@ -65,9 +73,10 @@ module('Integration | Adapter | oidc-provider', function(hooks) { test('requestForLogout returns the correct url/method', function(assert) { const adapter = this.owner.lookup('adapter:oidc-provider'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `POST /v1/acl/logout`; const actual = adapter - .requestForLogout(client.url, { + .requestForLogout(request, { id: id, }) .split('\n') diff --git a/ui/packages/consul-ui/tests/integration/adapters/permission-test.js b/ui/packages/consul-ui/tests/integration/adapters/permission-test.js index c65e3dc209..3bc2cee37d 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/permission-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/permission-test.js @@ -13,11 +13,12 @@ module('Integration | Adapter | permission', function(hooks) { test('requestForAuthorize returns the correct url/method', function(assert) { const adapter = this.owner.lookup('adapter:permission'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); // authorize endpoint doesn't need an ns sending on the query param const expected = `POST /v1/internal/acl/authorize?dc=${dc}${ shouldHaveNspace(nspace) ? `` : `` }`; - const actual = adapter.requestForAuthorize(client.requestParams.bind(client), { + const actual = adapter.requestForAuthorize(request, { dc: dc, ns: nspace, }); diff --git a/ui/packages/consul-ui/tests/integration/adapters/policy-test.js b/ui/packages/consul-ui/tests/integration/adapters/policy-test.js index a4d71c2d04..08470d3018 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/policy-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/policy-test.js @@ -9,8 +9,9 @@ module('Integration | Adapter | policy', function(hooks) { skip('urlForTranslateRecord returns the correct url', function(assert) { const adapter = this.owner.lookup('adapter:policy'); const client = this.owner.lookup('service:client/http'); + const request = client.id.bind(client); const expected = `GET /v1/acl/policy/translate`; - const actual = adapter.requestForTranslateRecord(client.id, {}); + const actual = adapter.requestForTranslateRecord(request, {}); assert.equal(actual, expected); }); const dc = 'dc-1'; @@ -20,10 +21,11 @@ module('Integration | Adapter | policy', function(hooks) { test(`requestForQuery returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:policy'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/acl/policies?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQuery(client.requestParams.bind(client), { + let actual = adapter.requestForQuery(request, { dc: dc, ns: nspace, }); @@ -32,10 +34,11 @@ module('Integration | Adapter | policy', function(hooks) { test(`requestForQueryRecord returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:policy'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/acl/policy/${id}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQueryRecord(client.requestParams.bind(client), { + let actual = adapter.requestForQueryRecord(request, { dc: dc, id: id, ns: nspace, @@ -45,10 +48,13 @@ module('Integration | Adapter | policy', function(hooks) { test(`requestForCreateRecord returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:policy'); const client = this.owner.lookup('service:client/http'); - const expected = `PUT /v1/acl/policy?dc=${dc}`; + const request = client.url.bind(client); + const expected = `PUT /v1/acl/policy?dc=${dc}${ + shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` + }`; const actual = adapter .requestForCreateRecord( - client.url, + request, {}, { Datacenter: dc, @@ -62,10 +68,13 @@ module('Integration | Adapter | policy', function(hooks) { test(`requestForUpdateRecord returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:policy'); const client = this.owner.lookup('service:client/http'); - const expected = `PUT /v1/acl/policy/${id}?dc=${dc}`; + const request = client.url.bind(client); + const expected = `PUT /v1/acl/policy/${id}?dc=${dc}${ + shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` + }`; const actual = adapter .requestForUpdateRecord( - client.url, + request, {}, { Datacenter: dc, @@ -80,12 +89,13 @@ module('Integration | Adapter | policy', function(hooks) { test(`requestForDeleteRecord returns the correct url/method when the nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:policy'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `DELETE /v1/acl/policy/${id}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; const actual = adapter .requestForDeleteRecord( - client.url, + request, {}, { Datacenter: dc, @@ -101,8 +111,9 @@ module('Integration | Adapter | policy', function(hooks) { test("requestForQueryRecord throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:policy'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQueryRecord(client.url, { + adapter.requestForQueryRecord(request, { dc: dc, }); }); diff --git a/ui/packages/consul-ui/tests/integration/adapters/role-test.js b/ui/packages/consul-ui/tests/integration/adapters/role-test.js index d0e109c944..c9ae1e1698 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/role-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/role-test.js @@ -13,10 +13,11 @@ module('Integration | Adapter | role', function(hooks) { test(`requestForQuery returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:role'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/acl/roles?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQuery(client.requestParams.bind(client), { + let actual = adapter.requestForQuery(request, { dc: dc, ns: nspace, }); @@ -25,10 +26,11 @@ module('Integration | Adapter | role', function(hooks) { test(`requestForQueryRecord returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:role'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/acl/role/${id}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQueryRecord(client.requestParams.bind(client), { + let actual = adapter.requestForQueryRecord(request, { dc: dc, id: id, ns: nspace, @@ -38,10 +40,13 @@ module('Integration | Adapter | role', function(hooks) { test(`requestForCreateRecord returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:role'); const client = this.owner.lookup('service:client/http'); - const expected = `PUT /v1/acl/role?dc=${dc}`; + const request = client.url.bind(client); + const expected = `PUT /v1/acl/role?dc=${dc}${ + shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` + }`; const actual = adapter .requestForCreateRecord( - client.url, + request, {}, { Datacenter: dc, @@ -55,10 +60,13 @@ module('Integration | Adapter | role', function(hooks) { test(`requestForUpdateRecord returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:role'); const client = this.owner.lookup('service:client/http'); - const expected = `PUT /v1/acl/role/${id}?dc=${dc}`; + const request = client.url.bind(client); + const expected = `PUT /v1/acl/role/${id}?dc=${dc}${ + shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` + }`; const actual = adapter .requestForUpdateRecord( - client.url, + request, {}, { Datacenter: dc, @@ -73,12 +81,13 @@ module('Integration | Adapter | role', function(hooks) { test(`requestForDeleteRecord returns the correct url/method when the nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:role'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `DELETE /v1/acl/role/${id}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; const actual = adapter .requestForDeleteRecord( - client.url, + request, {}, { Datacenter: dc, @@ -94,8 +103,9 @@ module('Integration | Adapter | role', function(hooks) { test("requestForQueryRecord throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:role'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQueryRecord(client.url, { + adapter.requestForQueryRecord(request, { dc: dc, }); }); diff --git a/ui/packages/consul-ui/tests/integration/adapters/service-instance-test.js b/ui/packages/consul-ui/tests/integration/adapters/service-instance-test.js index ab9b0ca44b..46985d029d 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/service-instance-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/service-instance-test.js @@ -13,10 +13,11 @@ module('Integration | Adapter | service-instance', function(hooks) { test(`requestForQueryRecord returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:service-instance'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/health/service/${id}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQueryRecord(client.requestParams.bind(client), { + let actual = adapter.requestForQueryRecord(request, { dc: dc, id: id, ns: nspace, @@ -27,8 +28,9 @@ module('Integration | Adapter | service-instance', function(hooks) { test("requestForQueryRecord throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:service-instance'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQueryRecord(client.url, { + adapter.requestForQueryRecord(request, { dc: dc, }); }); diff --git a/ui/packages/consul-ui/tests/integration/adapters/service-test.js b/ui/packages/consul-ui/tests/integration/adapters/service-test.js index d5327b9724..adf46258da 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/service-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/service-test.js @@ -13,10 +13,11 @@ module('Integration | Adapter | service', function(hooks) { test(`requestForQuery returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:service'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/internal/ui/services?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQuery(client.requestParams.bind(client), { + let actual = adapter.requestForQuery(request, { dc: dc, ns: nspace, }); @@ -25,11 +26,12 @@ module('Integration | Adapter | service', function(hooks) { test(`requestForQuery returns the correct url/method when called with gateway when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:service'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const gateway = 'gateway'; const expected = `GET /v1/internal/ui/gateway-services-nodes/${gateway}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQuery(client.requestParams.bind(client), { + let actual = adapter.requestForQuery(request, { dc: dc, ns: nspace, gateway: gateway, @@ -39,10 +41,11 @@ module('Integration | Adapter | service', function(hooks) { test(`requestForQueryRecord returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:service'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/health/service/${id}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQueryRecord(client.requestParams.bind(client), { + let actual = adapter.requestForQueryRecord(request, { dc: dc, id: id, ns: nspace, @@ -53,8 +56,9 @@ module('Integration | Adapter | service', function(hooks) { test("requestForQueryRecord throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:service'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQueryRecord(client.url, { + adapter.requestForQueryRecord(request, { dc: dc, }); }); diff --git a/ui/packages/consul-ui/tests/integration/adapters/session-test.js b/ui/packages/consul-ui/tests/integration/adapters/session-test.js index e464596788..306e338ece 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/session-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/session-test.js @@ -13,11 +13,12 @@ module('Integration | Adapter | session', function(hooks) { test(`requestForQuery returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:session'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const node = 'node-id'; const expected = `GET /v1/session/node/${node}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQuery(client.requestParams.bind(client), { + let actual = adapter.requestForQuery(request, { dc: dc, id: node, ns: nspace, @@ -27,10 +28,11 @@ module('Integration | Adapter | session', function(hooks) { test(`requestForQueryRecord returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:session'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/session/info/${id}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQueryRecord(client.requestParams.bind(client), { + let actual = adapter.requestForQueryRecord(request, { dc: dc, id: id, ns: nspace, @@ -40,12 +42,13 @@ module('Integration | Adapter | session', function(hooks) { test(`requestForDeleteRecord returns the correct url/method when the nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:session'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `PUT /v1/session/destroy/${id}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; const actual = adapter .requestForDeleteRecord( - client.url, + request, {}, { Datacenter: dc, @@ -61,8 +64,9 @@ module('Integration | Adapter | session', function(hooks) { test("requestForQuery throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:session'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQuery(client.url, { + adapter.requestForQuery(request, { dc: dc, }); }); @@ -70,8 +74,9 @@ module('Integration | Adapter | session', function(hooks) { test("requestForQueryRecord throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:session'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQueryRecord(client.url, { + adapter.requestForQueryRecord(request, { dc: dc, }); }); diff --git a/ui/packages/consul-ui/tests/integration/adapters/token-test.js b/ui/packages/consul-ui/tests/integration/adapters/token-test.js index 44de63b20f..6c66dbb567 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/token-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/token-test.js @@ -13,10 +13,11 @@ module('Integration | Adapter | token', function(hooks) { test(`requestForQuery returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:token'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/acl/tokens?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQuery(client.requestParams.bind(client), { + let actual = adapter.requestForQuery(request, { dc: dc, ns: nspace, }); @@ -25,10 +26,11 @@ module('Integration | Adapter | token', function(hooks) { test(`requestForQuery returns the correct url/method when a policy is specified when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:token'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/acl/tokens?policy=${id}&dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQuery(client.requestParams.bind(client), { + let actual = adapter.requestForQuery(request, { dc: dc, policy: id, ns: nspace, @@ -38,10 +40,11 @@ module('Integration | Adapter | token', function(hooks) { test(`requestForQuery returns the correct url/method when a role is specified when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:token'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/acl/tokens?role=${id}&dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQuery(client.requestParams.bind(client), { + let actual = adapter.requestForQuery(request, { dc: dc, role: id, ns: nspace, @@ -51,10 +54,11 @@ module('Integration | Adapter | token', function(hooks) { test(`requestForQueryRecord returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:token'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/acl/token/${id}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; - let actual = adapter.requestForQueryRecord(client.requestParams.bind(client), { + let actual = adapter.requestForQueryRecord(request, { dc: dc, id: id, ns: nspace, @@ -64,10 +68,13 @@ module('Integration | Adapter | token', function(hooks) { test(`requestForCreateRecord returns the correct url/method when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:token'); const client = this.owner.lookup('service:client/http'); - const expected = `PUT /v1/acl/token?dc=${dc}`; + const request = client.url.bind(client); + const expected = `PUT /v1/acl/token?dc=${dc}${ + shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` + }`; const actual = adapter .requestForCreateRecord( - client.url, + request, {}, { Datacenter: dc, @@ -81,10 +88,13 @@ module('Integration | Adapter | token', function(hooks) { test(`requestForUpdateRecord returns the correct url (without Rules it uses the v2 API) when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:token'); const client = this.owner.lookup('service:client/http'); - const expected = `PUT /v1/acl/token/${id}?dc=${dc}`; + const request = client.url.bind(client); + const expected = `PUT /v1/acl/token/${id}?dc=${dc}${ + shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` + }`; const actual = adapter .requestForUpdateRecord( - client.url, + request, {}, { Datacenter: dc, @@ -99,10 +109,13 @@ module('Integration | Adapter | token', function(hooks) { test(`requestForUpdateRecord returns the correct url (with Rules it uses the v1 API) when nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:token'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); + // As the title of the test says, this one uses the ACL legacy APIs and + // therefore does not expect a nspace const expected = `PUT /v1/acl/update?dc=${dc}`; const actual = adapter .requestForUpdateRecord( - client.url, + request, {}, { Rules: 'key {}', @@ -118,12 +131,13 @@ module('Integration | Adapter | token', function(hooks) { test(`requestForDeleteRecord returns the correct url/method when the nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:token'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `DELETE /v1/acl/token/${id}?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; const actual = adapter .requestForDeleteRecord( - client.url, + request, {}, { Datacenter: dc, @@ -138,12 +152,13 @@ module('Integration | Adapter | token', function(hooks) { test(`requestForCloneRecord returns the correct url when the nspace is ${nspace}`, function(assert) { const adapter = this.owner.lookup('adapter:token'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `PUT /v1/acl/token/${id}/clone?dc=${dc}${ shouldHaveNspace(nspace) ? `&ns=${nspace}` : `` }`; const actual = adapter .requestForCloneRecord( - client.url, + request, {}, { Datacenter: dc, @@ -159,8 +174,9 @@ module('Integration | Adapter | token', function(hooks) { test("requestForQueryRecord throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:token'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQueryRecord(client.url, { + adapter.requestForQueryRecord(request, { dc: dc, }); }); @@ -168,10 +184,11 @@ module('Integration | Adapter | token', function(hooks) { test('requestForSelf returns the correct url', function(assert) { const adapter = this.owner.lookup('adapter:token'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const expected = `GET /v1/acl/token/self?dc=${dc}`; const actual = adapter .requestForSelf( - client.url, + request, {}, { dc: dc, @@ -183,11 +200,12 @@ module('Integration | Adapter | token', function(hooks) { test('requestForSelf sets a token header using a secret', function(assert) { const adapter = this.owner.lookup('adapter:token'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); const secret = 'sssh'; const expected = `X-Consul-Token: ${secret}`; const actual = adapter .requestForSelf( - client.url, + request, {}, { dc: dc, diff --git a/ui/packages/consul-ui/tests/integration/adapters/topology-test.js b/ui/packages/consul-ui/tests/integration/adapters/topology-test.js index 5cf2e361f9..52c10a06b3 100644 --- a/ui/packages/consul-ui/tests/integration/adapters/topology-test.js +++ b/ui/packages/consul-ui/tests/integration/adapters/topology-test.js @@ -11,8 +11,9 @@ module('Integration | Adapter | topology', function(hooks) { test('requestForQueryRecord returns the correct url/method', function(assert) { const adapter = this.owner.lookup('adapter:topology'); const client = this.owner.lookup('service:client/http'); + const request = client.requestParams.bind(client); const expected = `GET /v1/internal/ui/service-topology/${id}?dc=${dc}&kind=${kind}`; - const actual = adapter.requestForQueryRecord(client.requestParams.bind(client), { + const actual = adapter.requestForQueryRecord(request, { dc: dc, id: id, kind: kind, @@ -22,8 +23,9 @@ module('Integration | Adapter | topology', function(hooks) { test("requestForQueryRecord throws if you don't specify an id", function(assert) { const adapter = this.owner.lookup('adapter:topology'); const client = this.owner.lookup('service:client/http'); + const request = client.url.bind(client); assert.throws(function() { - adapter.requestForQueryRecord(client.url, { + adapter.requestForQueryRecord(request, { dc: dc, }); }); @@ -31,7 +33,8 @@ module('Integration | Adapter | topology', function(hooks) { test('requestForQueryRecord returns the correct body', function(assert) { return nspaceRunner( (adapter, serializer, client) => { - return adapter.requestForQueryRecord(client.body, { + const request = client.body.bind(client); + return adapter.requestForQueryRecord(request, { id: id, dc: dc, ns: 'team-1', diff --git a/ui/packages/consul-ui/tests/integration/serializers/acl-test.js b/ui/packages/consul-ui/tests/integration/serializers/acl-test.js index 0029ac61fc..5bb1b8fc58 100644 --- a/ui/packages/consul-ui/tests/integration/serializers/acl-test.js +++ b/ui/packages/consul-ui/tests/integration/serializers/acl-test.js @@ -28,7 +28,9 @@ module('Integration | Serializer | acl', function(hooks) { ); const actual = serializer.respondForQuery( function(cb) { - const headers = {}; + const headers = { + [NSPACE]: nspace, + }; const body = payload; return cb(headers, body); }, @@ -49,7 +51,7 @@ module('Integration | Serializer | acl', function(hooks) { Datacenter: dc, [META]: { [DC.toLowerCase()]: dc, - [NSPACE.toLowerCase()]: '', + [NSPACE.toLowerCase()]: nspace, }, // TODO: default isn't required here, once we've // refactored out our Serializer this can go @@ -58,7 +60,10 @@ module('Integration | Serializer | acl', function(hooks) { }); const actual = serializer.respondForQueryRecord( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace, + }; const body = payload; return cb(headers, body); }, diff --git a/ui/packages/consul-ui/tests/integration/serializers/auth-method-test.js b/ui/packages/consul-ui/tests/integration/serializers/auth-method-test.js index 4142f30cca..0cd3180c00 100644 --- a/ui/packages/consul-ui/tests/integration/serializers/auth-method-test.js +++ b/ui/packages/consul-ui/tests/integration/serializers/auth-method-test.js @@ -27,13 +27,16 @@ module('Integration | Serializer | auth-method', function(hooks) { ); const actual = serializer.respondForQuery( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, { dc: dc, - ns: nspace, + ns: nspace || undefinedNspace, } ); assert.deepEqual(actual, expected); @@ -51,14 +54,17 @@ module('Integration | Serializer | auth-method', function(hooks) { Datacenter: dc, [META]: { [DC.toLowerCase()]: dc, - [NSPACE.toLowerCase()]: nspace || '', + [NSPACE.toLowerCase()]: nspace || undefinedNspace, }, Namespace: payload.Namespace || undefinedNspace, uid: `["${payload.Namespace || undefinedNspace}","${dc}","${id}"]`, }); const actual = serializer.respondForQueryRecord( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, diff --git a/ui/packages/consul-ui/tests/integration/serializers/coordinate-test.js b/ui/packages/consul-ui/tests/integration/serializers/coordinate-test.js index 3498678cd3..c4703254c8 100644 --- a/ui/packages/consul-ui/tests/integration/serializers/coordinate-test.js +++ b/ui/packages/consul-ui/tests/integration/serializers/coordinate-test.js @@ -1,6 +1,7 @@ import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; import { get } from 'consul-ui/tests/helpers/api'; +import { HEADERS_DATACENTER as DC, HEADERS_NAMESPACE as NSPACE } from 'consul-ui/utils/http/consul'; module('Integration | Serializer | coordinate', function(hooks) { setupTest(hooks); const dc = 'dc-1'; @@ -22,7 +23,10 @@ module('Integration | Serializer | coordinate', function(hooks) { ); const actual = serializer.respondForQuery( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace, + }; const body = payload; return cb(headers, body); }, diff --git a/ui/packages/consul-ui/tests/integration/serializers/discovery-chain-test.js b/ui/packages/consul-ui/tests/integration/serializers/discovery-chain-test.js index 65f6a6ed1a..0d6aaf2a1f 100644 --- a/ui/packages/consul-ui/tests/integration/serializers/discovery-chain-test.js +++ b/ui/packages/consul-ui/tests/integration/serializers/discovery-chain-test.js @@ -2,7 +2,11 @@ import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; import { get } from 'consul-ui/tests/helpers/api'; -import { HEADERS_SYMBOL as META } from 'consul-ui/utils/http/consul'; +import { + HEADERS_SYMBOL as META, + HEADERS_DATACENTER as DC, + HEADERS_NAMESPACE as NSPACE, +} from 'consul-ui/utils/http/consul'; module('Integration | Serializer | discovery-chain', function(hooks) { setupTest(hooks); @@ -10,6 +14,7 @@ module('Integration | Serializer | discovery-chain', function(hooks) { const serializer = this.owner.lookup('serializer:discovery-chain'); const dc = 'dc-1'; const id = 'slug'; + const nspace = 'default'; const request = { url: `/v1/discovery-chain/${id}?dc=${dc}`, }; @@ -17,11 +22,14 @@ module('Integration | Serializer | discovery-chain', function(hooks) { const expected = { Datacenter: dc, [META]: {}, - uid: `["default","${dc}","${id}"]`, + uid: `["${nspace}","${dc}","${id}"]`, }; const actual = serializer.respondForQueryRecord( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace, + }; const body = payload; return cb(headers, body); }, diff --git a/ui/packages/consul-ui/tests/integration/serializers/intention-test.js b/ui/packages/consul-ui/tests/integration/serializers/intention-test.js index 1cb4322d01..5625bf5e83 100644 --- a/ui/packages/consul-ui/tests/integration/serializers/intention-test.js +++ b/ui/packages/consul-ui/tests/integration/serializers/intention-test.js @@ -28,7 +28,10 @@ module('Integration | Serializer | intention', function(hooks) { ); const actual = serializer.respondForQuery( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace, + }; const body = payload; return cb(headers, body); }, @@ -70,7 +73,10 @@ module('Integration | Serializer | intention', function(hooks) { }); const actual = serializer.respondForQueryRecord( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace, + }; const body = payload; return cb(headers, body); }, diff --git a/ui/packages/consul-ui/tests/integration/serializers/kv-test.js b/ui/packages/consul-ui/tests/integration/serializers/kv-test.js index 82438ec8a8..a8f87a0012 100644 --- a/ui/packages/consul-ui/tests/integration/serializers/kv-test.js +++ b/ui/packages/consul-ui/tests/integration/serializers/kv-test.js @@ -35,7 +35,10 @@ module('Integration | Serializer | kv', function(hooks) { ); const actual = serializer.respondForQuery( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, @@ -57,20 +60,23 @@ module('Integration | Serializer | kv', function(hooks) { Datacenter: dc, [META]: { [DC.toLowerCase()]: dc, - [NSPACE.toLowerCase()]: nspace || '', + [NSPACE.toLowerCase()]: nspace || undefinedNspace, }, Namespace: payload[0].Namespace || undefinedNspace, uid: `["${payload[0].Namespace || undefinedNspace}","${dc}","${id}"]`, }); const actual = serializer.respondForQueryRecord( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, { dc: dc, - ns: nspace, + ns: nspace || undefinedNspace, id: id, } ); diff --git a/ui/packages/consul-ui/tests/integration/serializers/node-test.js b/ui/packages/consul-ui/tests/integration/serializers/node-test.js index 2ef5b85201..92c943408d 100644 --- a/ui/packages/consul-ui/tests/integration/serializers/node-test.js +++ b/ui/packages/consul-ui/tests/integration/serializers/node-test.js @@ -21,7 +21,10 @@ module('Integration | Serializer | node', function(hooks) { return get(request.url).then(function(payload) { const actual = serializer.respondForQuery( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace, + }; const body = payload; return cb(headers, body); }, @@ -51,7 +54,10 @@ module('Integration | Serializer | node', function(hooks) { return get(request.url).then(function(payload) { const actual = serializer.respondForQueryRecord( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace, + }; const body = payload; return cb(headers, body); }, @@ -80,12 +86,15 @@ module('Integration | Serializer | node', function(hooks) { Port: '8500', [META]: { [DC.toLowerCase()]: dc, - [NSPACE.toLowerCase()]: '', + [NSPACE.toLowerCase()]: nspace, }, }; const actual = serializer.respondForQueryLeader( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace, + }; const body = payload; return cb(headers, body); }, diff --git a/ui/packages/consul-ui/tests/integration/serializers/oidc-provider-test.js b/ui/packages/consul-ui/tests/integration/serializers/oidc-provider-test.js index f0f601e671..3829c68f9c 100644 --- a/ui/packages/consul-ui/tests/integration/serializers/oidc-provider-test.js +++ b/ui/packages/consul-ui/tests/integration/serializers/oidc-provider-test.js @@ -28,7 +28,10 @@ module('Integration | Serializer | oidc-provider', function(hooks) { ); const actual = serializer.respondForQuery( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, @@ -58,14 +61,17 @@ module('Integration | Serializer | oidc-provider', function(hooks) { Datacenter: dc, [META]: { [DC.toLowerCase()]: dc, - [NSPACE.toLowerCase()]: nspace || '', + [NSPACE.toLowerCase()]: nspace || undefinedNspace, }, Namespace: nspace || undefinedNspace, uid: `["${nspace || undefinedNspace}","${dc}","${id}"]`, }); const actual = serializer.respondForQueryRecord( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, diff --git a/ui/packages/consul-ui/tests/integration/serializers/policy-test.js b/ui/packages/consul-ui/tests/integration/serializers/policy-test.js index 238cfd41c2..2426f290d2 100644 --- a/ui/packages/consul-ui/tests/integration/serializers/policy-test.js +++ b/ui/packages/consul-ui/tests/integration/serializers/policy-test.js @@ -27,7 +27,10 @@ module('Integration | Serializer | policy', function(hooks) { ); const actual = serializer.respondForQuery( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, @@ -49,14 +52,17 @@ module('Integration | Serializer | policy', function(hooks) { Datacenter: dc, [META]: { [DC.toLowerCase()]: dc, - [NSPACE.toLowerCase()]: nspace || '', + [NSPACE.toLowerCase()]: nspace || undefinedNspace, }, Namespace: payload.Namespace || undefinedNspace, uid: `["${payload.Namespace || undefinedNspace}","${dc}","${id}"]`, }); const actual = serializer.respondForQueryRecord( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, diff --git a/ui/packages/consul-ui/tests/integration/serializers/role-test.js b/ui/packages/consul-ui/tests/integration/serializers/role-test.js index bebf39a53a..62e385fc68 100644 --- a/ui/packages/consul-ui/tests/integration/serializers/role-test.js +++ b/ui/packages/consul-ui/tests/integration/serializers/role-test.js @@ -30,7 +30,10 @@ module('Integration | Serializer | role', function(hooks) { ); const actual = serializer.respondForQuery( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, @@ -53,14 +56,17 @@ module('Integration | Serializer | role', function(hooks) { Policies: createPolicies(payload), [META]: { [DC.toLowerCase()]: dc, - [NSPACE.toLowerCase()]: nspace || '', + [NSPACE.toLowerCase()]: nspace || undefinedNspace, }, Namespace: payload.Namespace || undefinedNspace, uid: `["${payload.Namespace || undefinedNspace}","${dc}","${id}"]`, }); const actual = serializer.respondForQueryRecord( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, diff --git a/ui/packages/consul-ui/tests/integration/serializers/service-instance-test.js b/ui/packages/consul-ui/tests/integration/serializers/service-instance-test.js index 8ccab5e797..4fb176f291 100644 --- a/ui/packages/consul-ui/tests/integration/serializers/service-instance-test.js +++ b/ui/packages/consul-ui/tests/integration/serializers/service-instance-test.js @@ -28,14 +28,17 @@ module('Integration | Serializer | service-instance', function(hooks) { Datacenter: dc, [META]: { [DC.toLowerCase()]: dc, - [NSPACE.toLowerCase()]: nspace || '', + [NSPACE.toLowerCase()]: nspace || undefinedNspace, }, Namespace: payload[0].Service.Namespace || undefinedNspace, uid: `["${payload[0].Service.Namespace || undefinedNspace}","${dc}","${node}","${id}"]`, }; const actual = serializer.respondForQueryRecord( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, diff --git a/ui/packages/consul-ui/tests/integration/serializers/service-test.js b/ui/packages/consul-ui/tests/integration/serializers/service-test.js index c46dbb6754..8233df368c 100644 --- a/ui/packages/consul-ui/tests/integration/serializers/service-test.js +++ b/ui/packages/consul-ui/tests/integration/serializers/service-test.js @@ -1,6 +1,7 @@ import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; import { get } from 'consul-ui/tests/helpers/api'; +import { HEADERS_DATACENTER as DC, HEADERS_NAMESPACE as NSPACE } from 'consul-ui/utils/http/consul'; module('Integration | Serializer | service', function(hooks) { setupTest(hooks); const dc = 'dc-1'; @@ -23,7 +24,10 @@ module('Integration | Serializer | service', function(hooks) { ); const actual = serializer.respondForQuery( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, diff --git a/ui/packages/consul-ui/tests/integration/serializers/session-test.js b/ui/packages/consul-ui/tests/integration/serializers/session-test.js index e472088b91..0dc65c1bf4 100644 --- a/ui/packages/consul-ui/tests/integration/serializers/session-test.js +++ b/ui/packages/consul-ui/tests/integration/serializers/session-test.js @@ -30,7 +30,10 @@ module('Integration | Serializer | session | response', function(hooks) { ); const actual = serializer.respondForQuery( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, @@ -54,14 +57,17 @@ module('Integration | Serializer | session | response', function(hooks) { Datacenter: dc, [META]: { [DC.toLowerCase()]: dc, - [NSPACE.toLowerCase()]: nspace || '', + [NSPACE.toLowerCase()]: nspace || undefinedNspace, }, Namespace: payload[0].Namespace || undefinedNspace, uid: `["${payload[0].Namespace || undefinedNspace}","${dc}","${id}"]`, }); const actual = serializer.respondForQueryRecord( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, diff --git a/ui/packages/consul-ui/tests/integration/serializers/token-test.js b/ui/packages/consul-ui/tests/integration/serializers/token-test.js index 4485ff2a0b..3f044f411c 100644 --- a/ui/packages/consul-ui/tests/integration/serializers/token-test.js +++ b/ui/packages/consul-ui/tests/integration/serializers/token-test.js @@ -31,7 +31,10 @@ module('Integration | Serializer | token', function(hooks) { ); const actual = serializer.respondForQuery( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, @@ -53,7 +56,7 @@ module('Integration | Serializer | token', function(hooks) { Datacenter: dc, [META]: { [DC.toLowerCase()]: dc, - [NSPACE.toLowerCase()]: nspace || '', + [NSPACE.toLowerCase()]: nspace || undefinedNspace, }, Namespace: payload.Namespace || undefinedNspace, uid: `["${payload.Namespace || undefinedNspace}","${dc}","${id}"]`, @@ -61,7 +64,10 @@ module('Integration | Serializer | token', function(hooks) { }); const actual = serializer.respondForQueryRecord( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace || undefinedNspace, + }; const body = payload; return cb(headers, body); }, diff --git a/ui/packages/consul-ui/tests/integration/serializers/topology-test.js b/ui/packages/consul-ui/tests/integration/serializers/topology-test.js index 4806908f20..b28d663a0d 100644 --- a/ui/packages/consul-ui/tests/integration/serializers/topology-test.js +++ b/ui/packages/consul-ui/tests/integration/serializers/topology-test.js @@ -2,7 +2,11 @@ import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; import { get } from 'consul-ui/tests/helpers/api'; -import { HEADERS_SYMBOL as META } from 'consul-ui/utils/http/consul'; +import { + HEADERS_SYMBOL as META, + HEADERS_DATACENTER as DC, + HEADERS_NAMESPACE as NSPACE, +} from 'consul-ui/utils/http/consul'; module('Integration | Serializer | topology', function(hooks) { setupTest(hooks); @@ -11,6 +15,7 @@ module('Integration | Serializer | topology', function(hooks) { const dc = 'dc-1'; const id = 'slug'; const kind = ''; + const nspace = 'default'; const request = { url: `/v1/internal/ui/service-topology/${id}?dc=${dc}&kind=${kind}`, }; @@ -18,11 +23,14 @@ module('Integration | Serializer | topology', function(hooks) { const expected = { Datacenter: dc, [META]: {}, - uid: `["default","${dc}","${id}"]`, + uid: `["${nspace}","${dc}","${id}"]`, }; const actual = serializer.respondForQueryRecord( function(cb) { - const headers = {}; + const headers = { + [DC]: dc, + [NSPACE]: nspace, + }; const body = payload; return cb(headers, body); }, diff --git a/ui/packages/consul-ui/tests/integration/services/repository/kv-test.js b/ui/packages/consul-ui/tests/integration/services/repository/kv-test.js index d7810aeac0..14efa05b30 100644 --- a/ui/packages/consul-ui/tests/integration/services/repository/kv-test.js +++ b/ui/packages/consul-ui/tests/integration/services/repository/kv-test.js @@ -1,5 +1,7 @@ import { moduleFor, test } from 'ember-qunit'; import repo from 'consul-ui/tests/helpers/repo'; +import { env } from '../../../../env'; + const NAME = 'kv'; moduleFor(`service:repository/${NAME}`, `Integration | Service | ${NAME}`, { // Specify the other units that are required for this test. @@ -26,14 +28,17 @@ const undefinedNspace = 'default'; return service.findAllBySlug({ id, dc, ns: nspace || undefinedNspace }); }, function performAssertion(actual, expected) { + const expectedNspace = env('CONSUL_NSPACES_ENABLED') + ? nspace || undefinedNspace + : 'default'; assert.deepEqual( actual, expected(function(payload) { return payload.map(item => { return { Datacenter: dc, - Namespace: nspace || undefinedNspace, - uid: `["${nspace || undefinedNspace}","${dc}","${item}"]`, + Namespace: expectedNspace, + uid: `["${expectedNspace}","${dc}","${item}"]`, Key: item, }; }); diff --git a/ui/packages/consul-ui/tests/integration/services/repository/policy-test.js b/ui/packages/consul-ui/tests/integration/services/repository/policy-test.js index 3b25fd954c..def4f419bb 100644 --- a/ui/packages/consul-ui/tests/integration/services/repository/policy-test.js +++ b/ui/packages/consul-ui/tests/integration/services/repository/policy-test.js @@ -62,23 +62,8 @@ const undefinedNspace = 'default'; return service.findBySlug({ id, dc, ns: nspace || undefinedNspace }); }, function performAssertion(actual, expected) { - assert.deepEqual( - actual, - expected(function(payload) { - const item = payload; - return Object.assign({}, item, { - Datacenter: dc, - Namespace: item.Namespace || undefinedNspace, - uid: `["${item.Namespace || undefinedNspace}","${dc}","${item.ID}"]`, - meta: { - cacheControl: undefined, - cursor: undefined, - dc: dc, - nspace: item.Namespace || undefinedNspace, - }, - }); - }) - ); + assert.equal(actual.uid, `["${nspace || undefinedNspace}","${dc}","${actual.ID}"]`); + assert.equal(actual.Datacenter, dc); } ); }); diff --git a/ui/packages/consul-ui/tests/integration/services/repository/token-test.js b/ui/packages/consul-ui/tests/integration/services/repository/token-test.js index 864adf6fab..b19e763f21 100644 --- a/ui/packages/consul-ui/tests/integration/services/repository/token-test.js +++ b/ui/packages/consul-ui/tests/integration/services/repository/token-test.js @@ -60,25 +60,11 @@ const undefinedNspace = 'default'; return service.findBySlug({ id, dc, ns: nspace || undefinedNspace }); }, function performAssertion(actual, expected) { - assert.deepEqual( - actual, - expected(function(payload) { - const item = payload; - return Object.assign({}, item, { - Datacenter: dc, - CreateTime: new Date(item.CreateTime), - Namespace: item.Namespace || undefinedNspace, - uid: `["${item.Namespace || undefinedNspace}","${dc}","${item.AccessorID}"]`, - meta: { - cacheControl: undefined, - cursor: undefined, - dc: dc, - nspace: item.Namespace || undefinedNspace, - }, - Policies: createPolicies(item), - }); - }) - ); + expected(function(item) { + assert.equal(actual.uid, `["${nspace || undefinedNspace}","${dc}","${item.AccessorID}"]`); + assert.equal(actual.Datacenter, dc); + assert.deepEqual(actual.Policies, createPolicies(item)); + }); } ); }); diff --git a/ui/packages/consul-ui/tests/unit/serializers/application-test.js b/ui/packages/consul-ui/tests/unit/serializers/application-test.js index c0bef1c6d3..d6e69e6fc2 100644 --- a/ui/packages/consul-ui/tests/unit/serializers/application-test.js +++ b/ui/packages/consul-ui/tests/unit/serializers/application-test.js @@ -1,11 +1,7 @@ import { module } from 'qunit'; import test from 'ember-sinon-qunit/test-support/test'; import { setupTest } from 'ember-qunit'; -import { - HEADERS_SYMBOL as META, - HEADERS_DATACENTER as DC, - HEADERS_NAMESPACE as NSPACE, -} from 'consul-ui/utils/http/consul'; +import { HEADERS_SYMBOL as META } from 'consul-ui/utils/http/consul'; module('Unit | Serializer | application', function(hooks) { setupTest(hooks); @@ -65,10 +61,7 @@ module('Unit | Serializer | application', function(hooks) { const expected = { Datacenter: 'dc-1', Name: 'name', - [META]: { - [DC.toLowerCase()]: 'dc-1', - [NSPACE.toLowerCase()]: '', - }, + [META]: {}, 'primary-key-name': 'name', }; const respond = function(cb) { diff --git a/ui/packages/consul-ui/tests/unit/serializers/kv-test.js b/ui/packages/consul-ui/tests/unit/serializers/kv-test.js index 75a55593dd..ba91be5408 100644 --- a/ui/packages/consul-ui/tests/unit/serializers/kv-test.js +++ b/ui/packages/consul-ui/tests/unit/serializers/kv-test.js @@ -42,7 +42,9 @@ module('Unit | Serializer | kv', function(hooks) { ['respondForCreateRecord', 'respondForUpdateRecord'].forEach(function(item) { const actual = serializer[item]( function(cb) { - const headers = {}; + const headers = { + 'X-Consul-Namespace': 'default', + }; const body = true; return cb(headers, body); }, @@ -71,7 +73,9 @@ module('Unit | Serializer | kv', function(hooks) { ['respondForCreateRecord', 'respondForUpdateRecord'].forEach(function(item) { const actual = serializer[item]( function(cb) { - const headers = {}; + const headers = { + 'X-Consul-Namespace': 'default', + }; const body = { Key: uid, Datacenter: dc, diff --git a/ui/packages/consul-ui/tests/unit/utils/create-fingerprinter-test.js b/ui/packages/consul-ui/tests/unit/utils/create-fingerprinter-test.js index 35d92117d3..74915ed1c9 100644 --- a/ui/packages/consul-ui/tests/unit/utils/create-fingerprinter-test.js +++ b/ui/packages/consul-ui/tests/unit/utils/create-fingerprinter-test.js @@ -14,7 +14,7 @@ module('Unit | Utility | create fingerprinter', function() { uid: '["namespace","dc","slug"]', }; const fingerprint = createFingerprinter('Datacenter', 'Namespace'); - const actual = fingerprint('uid', 'ID', 'dc')(obj); + const actual = fingerprint('uid', 'ID', 'dc', 'namespace')(obj); assert.deepEqual(actual, expected); }); test("fingerprint returns a 'unique' fingerprinted object based on primary, slug and foreign keys, and uses default namespace if none set", function(assert) { @@ -28,7 +28,7 @@ module('Unit | Utility | create fingerprinter', function() { uid: '["default","dc","slug"]', }; const fingerprint = createFingerprinter('Datacenter', 'Namespace'); - const actual = fingerprint('uid', 'ID', 'dc')(obj); + const actual = fingerprint('uid', 'ID', 'dc', 'default')(obj); assert.deepEqual(actual, expected); }); test("fingerprint throws an error if it can't find a foreignKey", function(assert) {