2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
import { click, currentRouteName, visit } from '@ember/test-helpers';
|
2023-03-15 02:23:04 +00:00
|
|
|
// TESTS HERE ARE SKIPPED
|
2018-06-14 04:06:19 +00:00
|
|
|
// running vault with -dev-leased-kv flag lets you run some of these tests
|
|
|
|
// but generating leases programmatically is currently difficult
|
|
|
|
//
|
|
|
|
// TODO revisit this when it's easier to create leases
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
import { module, skip } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
2023-03-22 18:19:11 +00:00
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
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-09-25 16:28:26 +00:00
|
|
|
import authPage from 'vault/tests/pages/auth';
|
|
|
|
import logout from 'vault/tests/pages/logout';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Acceptance | leases', function (hooks) {
|
2018-09-25 16:28:26 +00:00
|
|
|
setupApplicationTest(hooks);
|
2018-04-16 22:18:46 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.beforeEach(async function () {
|
2018-09-25 16:28:26 +00:00
|
|
|
await authPage.login();
|
2023-03-22 18:19:11 +00:00
|
|
|
this.enginePath = `kv-for-lease-${uuidv4()}`;
|
2018-04-16 22:18:46 +00:00
|
|
|
// need a version 1 mount for leased secrets here
|
2021-12-17 03:44:29 +00:00
|
|
|
return mountSecrets.visit().path(this.enginePath).type('kv').version(1).submit();
|
2018-09-25 16:28:26 +00:00
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.afterEach(function () {
|
2018-09-25 16:28:26 +00:00
|
|
|
return logout.visit();
|
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
const createSecret = async (context, isRenewable) => {
|
2023-03-22 18:19:11 +00:00
|
|
|
context.name = `secret-${uuidv4()}`;
|
2018-09-25 16:28:26 +00:00
|
|
|
await secretList.visitRoot({ backend: context.enginePath });
|
|
|
|
await secretList.create();
|
|
|
|
if (isRenewable) {
|
|
|
|
await secretEdit.createSecret(context.name, 'ttl', '30h');
|
|
|
|
} else {
|
|
|
|
await secretEdit.createSecret(context.name, 'foo', 'bar');
|
|
|
|
}
|
|
|
|
};
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
const navToDetail = async (context) => {
|
2018-09-25 16:28:26 +00:00
|
|
|
await visit('/vault/access/leases/');
|
|
|
|
await click(`[data-test-lease-link="${context.enginePath}/"]`);
|
|
|
|
await click(`[data-test-lease-link="${context.enginePath}/${context.name}/"]`);
|
|
|
|
await click(`[data-test-lease-link]:eq(0)`);
|
|
|
|
};
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
skip('it renders the show page', function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
createSecret(this);
|
|
|
|
navToDetail(this);
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(
|
2018-04-03 14:16:57 +00:00
|
|
|
currentRouteName(),
|
|
|
|
'vault.cluster.access.leases.show',
|
|
|
|
'a lease for the secret is in the list'
|
|
|
|
);
|
2018-05-24 03:10:21 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
// skip for now until we find an easy way to generate a renewable lease
|
2021-12-17 03:44:29 +00:00
|
|
|
skip('it renders the show page with a picker', function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
createSecret(this, true);
|
|
|
|
navToDetail(this);
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(
|
2018-04-03 14:16:57 +00:00
|
|
|
currentRouteName(),
|
|
|
|
'vault.cluster.access.leases.show',
|
|
|
|
'a lease for the secret is in the list'
|
|
|
|
);
|
2018-05-24 03:10:21 +00:00
|
|
|
assert
|
|
|
|
.dom('[data-test-lease-renew-picker]')
|
|
|
|
.exists({ count: 1 }, 'renewable lease renders a renew picker');
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
skip('it removes leases upon revocation', async function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
createSecret(this);
|
|
|
|
navToDetail(this);
|
|
|
|
await click('[data-test-lease-revoke] button');
|
|
|
|
await click('[data-test-confirm-button]');
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(
|
2018-04-03 14:16:57 +00:00
|
|
|
currentRouteName(),
|
|
|
|
'vault.cluster.access.leases.list-root',
|
|
|
|
'it navigates back to the leases root on revocation'
|
|
|
|
);
|
2018-09-25 16:28:26 +00:00
|
|
|
await click(`[data-test-lease-link="${this.enginePath}/"]`);
|
|
|
|
await click('[data-test-lease-link="data/"]');
|
2018-05-24 03:10:21 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
skip('it removes branches when a prefix is revoked', async function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
createSecret(this);
|
|
|
|
await visit(`/vault/access/leases/list/${this.enginePath}`);
|
|
|
|
await click('[data-test-lease-revoke-prefix] button');
|
|
|
|
await click('[data-test-confirm-button]');
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(
|
2018-04-03 14:16:57 +00:00
|
|
|
currentRouteName(),
|
|
|
|
'vault.cluster.access.leases.list-root',
|
|
|
|
'it navigates back to the leases root on revocation'
|
|
|
|
);
|
2018-05-24 03:10:21 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
skip('lease not found', async function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
await visit('/vault/access/leases/show/not-found');
|
2018-05-24 03:10:21 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
});
|