open-vault/ui/tests/acceptance/leases-test.js

122 lines
3.9 KiB
JavaScript
Raw Normal View History

import { test, skip } from 'qunit';
2018-04-03 14:16:57 +00:00
import moduleForAcceptance from 'vault/tests/helpers/module-for-acceptance';
import secretList from 'vault/tests/pages/secrets/backend/list';
import secretEdit from 'vault/tests/pages/secrets/backend/kv/edit-secret';
import mountSecrets from 'vault/tests/pages/settings/mount-secret-backend';
2018-04-03 14:16:57 +00:00
import Ember from 'ember';
let adapterException;
// testing error states is terrible in ember acceptance tests so these weird Ember bits are to work around that
// adapted from https://github.com/emberjs/ember.js/issues/12791#issuecomment-244934786
moduleForAcceptance('Acceptance | leases', {
beforeEach() {
adapterException = Ember.Test.adapter.exception;
Ember.Test.adapter.exception = () => null;
authLogin();
this.enginePath = `kv-for-lease-${new Date().getTime()}`;
// need a version 1 mount for leased secrets here
return mountSecrets.visit().path(this.enginePath).type('kv').version(1).submit();
2018-04-03 14:16:57 +00:00
},
afterEach() {
Ember.Test.adapter.exception = adapterException;
return authLogout();
},
});
const createSecret = (context, isRenewable) => {
context.name = `secret-${new Date().getTime()}`;
secretList.visitRoot({ backend: context.enginePath });
secretList.create();
2018-04-03 14:16:57 +00:00
if (isRenewable) {
secretEdit.createSecret(context.name, 'ttl', '30h');
} else {
secretEdit.createSecret(context.name, 'foo', 'bar');
2018-04-03 14:16:57 +00:00
}
};
const navToDetail = context => {
2018-04-03 14:16:57 +00:00
visit('/vault/access/leases/');
click(`[data-test-lease-link="${context.enginePath}/"]`);
click(`[data-test-lease-link="${context.enginePath}/${context.name}/"]`);
2018-04-03 14:16:57 +00:00
click(`[data-test-lease-link]:eq(0)`);
};
test('it renders the show page', function(assert) {
createSecret(this);
navToDetail(this);
return andThen(() => {
2018-04-03 14:16:57 +00:00
assert.equal(
currentRouteName(),
'vault.cluster.access.leases.show',
'a lease for the secret is in the list'
);
assert
.dom('[data-test-lease-renew-picker]')
.doesNotExist('non-renewable lease does not render a renew picker');
2018-04-03 14:16:57 +00:00
});
});
// skip for now until we find an easy way to generate a renewable lease
skip('it renders the show page with a picker', function(assert) {
2018-04-03 14:16:57 +00:00
createSecret(this, true);
navToDetail(this);
2018-04-03 14:16:57 +00:00
andThen(() => {
assert.equal(
currentRouteName(),
'vault.cluster.access.leases.show',
'a lease for the secret is in the list'
);
assert
.dom('[data-test-lease-renew-picker]')
.exists({ count: 1 }, 'renewable lease renders a renew picker');
2018-04-03 14:16:57 +00:00
});
});
test('it removes leases upon revocation', function(assert) {
createSecret(this);
navToDetail(this);
2018-04-03 14:16:57 +00:00
click('[data-test-lease-revoke] button');
click('[data-test-confirm-button]');
andThen(() => {
assert.equal(
currentRouteName(),
'vault.cluster.access.leases.list-root',
'it navigates back to the leases root on revocation'
);
});
click(`[data-test-lease-link="${this.enginePath}/"]`);
click('[data-test-lease-link="data/"]');
2018-04-03 14:16:57 +00:00
andThen(() => {
assert
.dom(`[data-test-lease-link="${this.enginePath}/data/${this.name}/"]`)
.doesNotExist('link to the lease was removed with revocation');
2018-04-03 14:16:57 +00:00
});
});
test('it removes branches when a prefix is revoked', function(assert) {
createSecret(this);
visit(`/vault/access/leases/list/${this.enginePath}`);
2018-04-03 14:16:57 +00:00
click('[data-test-lease-revoke-prefix] button');
click('[data-test-confirm-button]');
andThen(() => {
assert.equal(
currentRouteName(),
'vault.cluster.access.leases.list-root',
'it navigates back to the leases root on revocation'
);
assert
.dom(`[data-test-lease-link="${this.enginePath}/"]`)
.doesNotExist('link to the prefix was removed with revocation');
2018-04-03 14:16:57 +00:00
});
});
test('lease not found', function(assert) {
visit('/vault/access/leases/show/not-found');
andThen(() => {
assert
.dom('[data-test-lease-error]')
.hasText('not-found is not a valid lease ID', 'it shows an error when the lease is not found');
2018-04-03 14:16:57 +00:00
});
});