open-vault/ui/tests/unit/adapters/cluster-test.js

198 lines
7.6 KiB
JavaScript
Raw Normal View History

2018-04-03 14:16:57 +00:00
import { moduleFor, test } from 'ember-qunit';
import Ember from 'ember';
UI namespaces (#5119) * add namespace sidebar item * depend on ember-inflector directly * list-view and list-item components * fill out components and render empty namespaces page * list namespaces in access * add menu contextual component to list item * popup contextual component * full crud for namespaces * add namespaces service and picker component * split application and vault.cluster templates and controllers, add namespace query param, add namespace-picker to vault.namespace template * remove usage of href-to * remove ember-href-to from deps * add ember-responsive * start styling the picker and link to appropriate namespaces, use ember-responsive to render picker in different places based on the breakpoint * get query param working and save ns to authdata when authenticating, feed through ns in application adapter * move to observer on the controller for setting state on the service * set state in the beforeModel hook and clear the ember data model cache * nav to secrets on change and make error handling more resilient utilizing the method that atlas does to eagerly update URLs * add a list of sys endpoints in a helper * hide header elements if not in the root namespace * debounce namespace input on auth, fix 404 for auth method fetch, move auth method fetch to a task on the auth-form component and refretch on namespace change * fix display of supported engines and exclusion of sys and identity engines * don't fetch replication status if you're in a non-root namespace * hide seal sub-menu if not in the root namespace * don't autocomplete auth form inputs * always send some requests to the root namespace * use methodType and engineType instead of type in case there it is ns_ prefixed * use sys/internal/ui/namespaces to fetch the list in the dropdown * don't use model for namespace picker and always make the request to the token namespace * fix header handling for fetch calls * use namespace-reminder component on creation and edit forms throughout the application * add namespace-reminder to the console * add flat * add deepmerge for creating the tree in the menu * delayed rendering for animation timing * design and code feedback on the first round * white text in the namespace picker * fix namespace picker issues with root keys * separate path-to-tree * add tests for path-to-tree util * hide picker if you're in the root ns and you can't access other namespaces * show error message if you enter invalid characters for namespace path * return a different model if we dont have the namespaces feature and show upgrade page * if a token has a namespace_path, use that as the root user namespace and transition them there on login * use token namespace for user, but use specified namespace to log in * always renew tokens in the token namespace * fix edition-badge test
2018-08-16 17:48:24 +00:00
import needs from 'vault/tests/unit/adapters/_adapter-needs';
2018-04-03 14:16:57 +00:00
moduleFor('adapter:cluster', 'Unit | Adapter | cluster', {
UI namespaces (#5119) * add namespace sidebar item * depend on ember-inflector directly * list-view and list-item components * fill out components and render empty namespaces page * list namespaces in access * add menu contextual component to list item * popup contextual component * full crud for namespaces * add namespaces service and picker component * split application and vault.cluster templates and controllers, add namespace query param, add namespace-picker to vault.namespace template * remove usage of href-to * remove ember-href-to from deps * add ember-responsive * start styling the picker and link to appropriate namespaces, use ember-responsive to render picker in different places based on the breakpoint * get query param working and save ns to authdata when authenticating, feed through ns in application adapter * move to observer on the controller for setting state on the service * set state in the beforeModel hook and clear the ember data model cache * nav to secrets on change and make error handling more resilient utilizing the method that atlas does to eagerly update URLs * add a list of sys endpoints in a helper * hide header elements if not in the root namespace * debounce namespace input on auth, fix 404 for auth method fetch, move auth method fetch to a task on the auth-form component and refretch on namespace change * fix display of supported engines and exclusion of sys and identity engines * don't fetch replication status if you're in a non-root namespace * hide seal sub-menu if not in the root namespace * don't autocomplete auth form inputs * always send some requests to the root namespace * use methodType and engineType instead of type in case there it is ns_ prefixed * use sys/internal/ui/namespaces to fetch the list in the dropdown * don't use model for namespace picker and always make the request to the token namespace * fix header handling for fetch calls * use namespace-reminder component on creation and edit forms throughout the application * add namespace-reminder to the console * add flat * add deepmerge for creating the tree in the menu * delayed rendering for animation timing * design and code feedback on the first round * white text in the namespace picker * fix namespace picker issues with root keys * separate path-to-tree * add tests for path-to-tree util * hide picker if you're in the root ns and you can't access other namespaces * show error message if you enter invalid characters for namespace path * return a different model if we dont have the namespaces feature and show upgrade page * if a token has a namespace_path, use that as the root user namespace and transition them there on login * use token namespace for user, but use specified namespace to log in * always renew tokens in the token namespace * fix edition-badge test
2018-08-16 17:48:24 +00:00
needs,
2018-04-03 14:16:57 +00:00
});
test('cluster api urls', function(assert) {
let url, method, options;
let adapter = this.subject({
ajax: (...args) => {
[url, method, options] = args;
return Ember.RSVP.resolve();
},
});
adapter.health();
assert.equal('/v1/sys/health', url, 'health url OK');
assert.deepEqual(
{ standbycode: 200, sealedcode: 200, uninitcode: 200, drsecondarycode: 200 },
options.data,
'health data params OK'
);
assert.equal('GET', method, 'health method OK');
adapter.sealStatus();
assert.equal('/v1/sys/seal-status', url, 'health url OK');
assert.equal('GET', method, 'seal-status method OK');
let data = { someData: 1 };
adapter.unseal(data);
assert.equal('/v1/sys/unseal', url, 'unseal url OK');
assert.equal('PUT', method, 'unseal method OK');
assert.deepEqual({ data, unauthenticated: true }, options, 'unseal options OK');
adapter.initCluster(data);
assert.equal('/v1/sys/init', url, 'init url OK');
assert.equal('PUT', method, 'init method OK');
assert.deepEqual({ data, unauthenticated: true }, options, 'init options OK');
data = { token: 'token', password: 'password', username: 'username' };
adapter.authenticate({ backend: 'token', data });
assert.equal('/v1/auth/token/lookup-self', url, 'auth:token url OK');
assert.equal('GET', method, 'auth:token method OK');
assert.deepEqual(
{ headers: { 'X-Vault-Token': 'token' }, unauthenticated: true },
options,
'auth:token options OK'
);
adapter.authenticate({ backend: 'github', data });
assert.equal('/v1/auth/github/login', url, 'auth:github url OK');
assert.equal('POST', method, 'auth:github method OK');
assert.deepEqual(
{ data: { password: 'password', token: 'token' }, unauthenticated: true },
options,
'auth:github options OK'
);
data = { token: 'token', password: 'password', username: 'username', path: 'path' };
adapter.authenticate({ backend: 'token', data });
assert.equal('/v1/auth/token/lookup-self', url, 'auth:token url with path OK');
adapter.authenticate({ backend: 'github', data });
assert.equal('/v1/auth/path/login', url, 'auth:github with path url OK');
data = { password: 'password', username: 'username' };
adapter.authenticate({ backend: 'userpass', data });
assert.equal('/v1/auth/userpass/login/username', url, 'auth:userpass url OK');
assert.equal('POST', method, 'auth:userpass method OK');
assert.deepEqual(
{ data: { password: 'password' }, unauthenticated: true },
options,
'auth:userpass options OK'
);
adapter.authenticate({ backend: 'LDAP', data });
assert.equal('/v1/auth/ldap/login/username', url, 'ldap:userpass url OK');
assert.equal('POST', method, 'ldap:userpass method OK');
assert.deepEqual(
{ data: { password: 'password' }, unauthenticated: true },
options,
'ldap:userpass options OK'
);
adapter.authenticate({ backend: 'okta', data });
assert.equal('/v1/auth/okta/login/username', url, 'okta:userpass url OK');
assert.equal('POST', method, 'ldap:userpass method OK');
assert.deepEqual(
{ data: { password: 'password' }, unauthenticated: true },
options,
'okta:userpass options OK'
);
// use a custom mount path
data = { password: 'password', username: 'username', path: 'path' };
adapter.authenticate({ backend: 'userpass', data });
assert.equal('/v1/auth/path/login/username', url, 'auth:userpass with path url OK');
adapter.authenticate({ backend: 'LDAP', data });
assert.equal('/v1/auth/path/login/username', url, 'auth:LDAP with path url OK');
adapter.authenticate({ backend: 'Okta', data });
assert.equal('/v1/auth/path/login/username', url, 'auth:Okta with path url OK');
});
test('cluster replication api urls', function(assert) {
let url, method, options;
let adapter = this.subject({
ajax: (...args) => {
[url, method, options] = args;
return Ember.RSVP.resolve();
},
});
adapter.replicationStatus();
assert.equal('/v1/sys/replication/status', url, 'replication:status url OK');
assert.equal('GET', method, 'replication:status method OK');
assert.deepEqual({ unauthenticated: true }, options, 'replication:status options OK');
adapter.replicationAction('recover', 'dr');
assert.equal('/v1/sys/replication/recover', url, 'replication: recover url OK');
assert.equal('POST', method, 'replication:recover method OK');
adapter.replicationAction('reindex', 'dr');
assert.equal('/v1/sys/replication/reindex', url, 'replication: reindex url OK');
assert.equal('POST', method, 'replication:reindex method OK');
adapter.replicationAction('enable', 'dr', 'primary');
assert.equal('/v1/sys/replication/dr/primary/enable', url, 'replication:dr primary:enable url OK');
assert.equal('POST', method, 'replication:primary:enable method OK');
adapter.replicationAction('enable', 'performance', 'primary');
assert.equal(
'/v1/sys/replication/performance/primary/enable',
url,
'replication:performance primary:enable url OK'
);
adapter.replicationAction('enable', 'dr', 'secondary');
assert.equal('/v1/sys/replication/dr/secondary/enable', url, 'replication:dr secondary:enable url OK');
assert.equal('POST', method, 'replication:secondary:enable method OK');
adapter.replicationAction('enable', 'performance', 'secondary');
assert.equal(
'/v1/sys/replication/performance/secondary/enable',
url,
'replication:performance secondary:enable url OK'
);
adapter.replicationAction('disable', 'dr', 'primary');
assert.equal('/v1/sys/replication/dr/primary/disable', url, 'replication:dr primary:disable url OK');
assert.equal('POST', method, 'replication:primary:disable method OK');
adapter.replicationAction('disable', 'performance', 'primary');
assert.equal(
'/v1/sys/replication/performance/primary/disable',
url,
'replication:performance primary:disable url OK'
);
adapter.replicationAction('disable', 'dr', 'secondary');
assert.equal('/v1/sys/replication/dr/secondary/disable', url, 'replication: drsecondary:disable url OK');
assert.equal('POST', method, 'replication:secondary:disable method OK');
adapter.replicationAction('disable', 'performance', 'secondary');
assert.equal(
'/v1/sys/replication/performance/secondary/disable',
url,
'replication: performance:disable url OK'
);
adapter.replicationAction('demote', 'dr', 'primary');
assert.equal('/v1/sys/replication/dr/primary/demote', url, 'replication: dr primary:demote url OK');
assert.equal('POST', method, 'replication:primary:demote method OK');
adapter.replicationAction('demote', 'performance', 'primary');
assert.equal(
'/v1/sys/replication/performance/primary/demote',
url,
'replication: performance primary:demote url OK'
);
adapter.replicationAction('promote', 'performance', 'secondary');
assert.equal('POST', method, 'replication:secondary:promote method OK');
assert.equal(
'/v1/sys/replication/performance/secondary/promote',
url,
'replication:performance secondary:promote url OK'
);
adapter.replicationDrPromote();
assert.equal('/v1/sys/replication/dr/secondary/promote', url, 'replication:dr secondary:promote url OK');
assert.equal('PUT', method, 'replication:dr secondary:promote method OK');
adapter.replicationDrPromote({}, { checkStatus: true });
assert.equal('/v1/sys/replication/dr/secondary/promote', url, 'replication:dr secondary:promote url OK');
assert.equal('GET', method, 'replication:dr secondary:promote method OK');
});