2018-04-16 22:18:46 +00:00
|
|
|
import { test, skip } from 'qunit';
|
2018-04-03 14:16:57 +00:00
|
|
|
import moduleForAcceptance from 'vault/tests/helpers/module-for-acceptance';
|
2018-04-16 22:18:46 +00:00
|
|
|
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;
|
2018-04-16 22:18:46 +00:00
|
|
|
|
|
|
|
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) => {
|
2018-04-16 22:18:46 +00:00
|
|
|
context.name = `secret-${new Date().getTime()}`;
|
|
|
|
secretList.visitRoot({ backend: context.enginePath });
|
|
|
|
secretList.create();
|
2018-04-03 14:16:57 +00:00
|
|
|
if (isRenewable) {
|
2018-04-16 22:18:46 +00:00
|
|
|
secretEdit.createSecret(context.name, 'ttl', '30h');
|
|
|
|
} else {
|
|
|
|
secretEdit.createSecret(context.name, 'foo', 'bar');
|
2018-04-03 14:16:57 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-16 22:18:46 +00:00
|
|
|
const navToDetail = context => {
|
2018-04-03 14:16:57 +00:00
|
|
|
visit('/vault/access/leases/');
|
2018-04-16 22:18:46 +00:00
|
|
|
click(`[data-test-lease-link="${context.enginePath}/"]`);
|
2018-04-20 02:26:25 +00:00
|
|
|
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);
|
2018-04-16 22:18:46 +00:00
|
|
|
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.equal(
|
|
|
|
find('[data-test-lease-renew-picker]').length,
|
|
|
|
0,
|
|
|
|
'non-renewable lease does not render a renew picker'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-16 22:18:46 +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);
|
2018-04-16 22:18:46 +00:00
|
|
|
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.equal(find('[data-test-lease-renew-picker]').length, 1, 'renewable lease renders a renew picker');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it removes leases upon revocation', function(assert) {
|
|
|
|
createSecret(this);
|
2018-04-16 22:18:46 +00:00
|
|
|
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'
|
|
|
|
);
|
|
|
|
});
|
2018-04-16 22:18:46 +00:00
|
|
|
click(`[data-test-lease-link="${this.enginePath}/"]`);
|
|
|
|
click('[data-test-lease-link="data/"]');
|
2018-04-03 14:16:57 +00:00
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
2018-04-16 22:18:46 +00:00
|
|
|
find(`[data-test-lease-link="${this.enginePath}/data/${this.name}/"]`).length,
|
2018-04-03 14:16:57 +00:00
|
|
|
0,
|
|
|
|
'link to the lease was removed with revocation'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it removes branches when a prefix is revoked', function(assert) {
|
|
|
|
createSecret(this);
|
2018-04-16 22:18:46 +00:00
|
|
|
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.equal(
|
2018-04-16 22:18:46 +00:00
|
|
|
find(`[data-test-lease-link="${this.enginePath}/"]`).length,
|
2018-04-03 14:16:57 +00:00
|
|
|
0,
|
|
|
|
'link to the prefix was removed with revocation'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('lease not found', function(assert) {
|
|
|
|
visit('/vault/access/leases/show/not-found');
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
find('[data-test-lease-error]').text().trim(),
|
|
|
|
'not-found is not a valid lease ID',
|
|
|
|
'it shows an error when the lease is not found'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|