2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2022-12-16 21:26:43 +00:00
|
|
|
import { currentRouteName, currentURL, settled } from '@ember/test-helpers';
|
2023-02-16 17:03:15 +00:00
|
|
|
import { module, test } from 'qunit';
|
2018-09-25 16:28:26 +00:00
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
2023-03-22 18:19:11 +00:00
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
|
|
2021-09-15 18:14:18 +00:00
|
|
|
import { create } from 'ember-cli-page-object';
|
2018-04-03 14:16:57 +00:00
|
|
|
import page from 'vault/tests/pages/settings/mount-secret-backend';
|
2018-05-23 16:25:52 +00:00
|
|
|
import configPage from 'vault/tests/pages/secrets/backend/configuration';
|
2018-09-25 16:28:26 +00:00
|
|
|
import authPage from 'vault/tests/pages/auth';
|
2021-09-15 18:14:18 +00:00
|
|
|
import consoleClass from 'vault/tests/pages/components/console/ui-panel';
|
|
|
|
import logout from 'vault/tests/pages/logout';
|
|
|
|
import mountSecrets from 'vault/tests/pages/settings/mount-secret-backend';
|
2022-12-16 21:26:43 +00:00
|
|
|
import { allEngines } from 'vault/helpers/mountable-secret-engines';
|
2021-09-15 18:14:18 +00:00
|
|
|
|
|
|
|
const consoleComponent = create(consoleClass);
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Acceptance | settings/mount-secret-backend', function (hooks) {
|
2018-09-25 16:28:26 +00:00
|
|
|
setupApplicationTest(hooks);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.beforeEach(function () {
|
2023-03-22 18:19:11 +00:00
|
|
|
this.uid = uuidv4();
|
2018-09-25 16:28:26 +00:00
|
|
|
return authPage.login();
|
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it sets the ttl correctly when mounting', async function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
// always force the new mount to the top of the list
|
2023-03-22 18:19:11 +00:00
|
|
|
const path = `mount-kv-${this.uid}`;
|
2018-09-25 16:28:26 +00:00
|
|
|
const defaultTTLHours = 100;
|
|
|
|
const maxTTLHours = 300;
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await page.visit();
|
2019-08-01 21:35:18 +00:00
|
|
|
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(currentRouteName(), 'vault.cluster.settings.mount-secret-backend');
|
2018-09-25 16:28:26 +00:00
|
|
|
await page.selectType('kv');
|
2019-04-10 14:36:32 +00:00
|
|
|
await page
|
|
|
|
.next()
|
|
|
|
.path(path)
|
|
|
|
.toggleOptions()
|
2020-04-20 15:17:50 +00:00
|
|
|
.enableDefaultTtl()
|
2019-04-10 14:36:32 +00:00
|
|
|
.defaultTTLUnit('h')
|
2020-04-20 15:17:50 +00:00
|
|
|
.defaultTTLVal(defaultTTLHours)
|
|
|
|
.enableMaxTtl()
|
2019-04-10 14:36:32 +00:00
|
|
|
.maxTTLUnit('h')
|
2020-04-20 15:17:50 +00:00
|
|
|
.maxTTLVal(maxTTLHours)
|
2019-04-10 14:36:32 +00:00
|
|
|
.submit();
|
2018-09-25 16:28:26 +00:00
|
|
|
await configPage.visit({ backend: path });
|
2023-04-07 21:05:29 +00:00
|
|
|
assert.strictEqual(configPage.defaultTTL, `${defaultTTLHours}h`, 'shows the proper TTL');
|
|
|
|
assert.strictEqual(configPage.maxTTL, `${maxTTLHours}h`, 'shows the proper max TTL');
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
2020-05-08 17:08:04 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it sets the ttl when enabled then disabled', async function (assert) {
|
2020-05-08 17:08:04 +00:00
|
|
|
// always force the new mount to the top of the list
|
2023-03-22 18:19:11 +00:00
|
|
|
const path = `mount-kv-${this.uid}`;
|
2020-05-08 17:08:04 +00:00
|
|
|
const maxTTLHours = 300;
|
|
|
|
|
|
|
|
await page.visit();
|
|
|
|
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(currentRouteName(), 'vault.cluster.settings.mount-secret-backend');
|
2020-05-08 17:08:04 +00:00
|
|
|
await page.selectType('kv');
|
|
|
|
await page
|
|
|
|
.next()
|
|
|
|
.path(path)
|
|
|
|
.toggleOptions()
|
|
|
|
.enableDefaultTtl()
|
|
|
|
.enableDefaultTtl()
|
|
|
|
.enableMaxTtl()
|
|
|
|
.maxTTLUnit('h')
|
|
|
|
.maxTTLVal(maxTTLHours)
|
|
|
|
.submit();
|
|
|
|
await configPage.visit({ backend: path });
|
2023-04-07 21:05:29 +00:00
|
|
|
assert.strictEqual(configPage.defaultTTL, '0s', 'shows the proper TTL');
|
|
|
|
assert.strictEqual(configPage.maxTTL, `${maxTTLHours}h`, 'shows the proper max TTL');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it sets the max ttl after pki chosen, resets after', async function (assert) {
|
|
|
|
await page.visit();
|
|
|
|
assert.strictEqual(currentRouteName(), 'vault.cluster.settings.mount-secret-backend');
|
|
|
|
await page.selectType('pki');
|
|
|
|
await page.next();
|
|
|
|
assert.dom('[data-test-input="maxLeaseTtl"]').exists();
|
|
|
|
assert
|
|
|
|
.dom('[data-test-input="maxLeaseTtl"] [data-test-ttl-toggle]')
|
|
|
|
.isChecked('Toggle is checked by default');
|
|
|
|
assert.dom('[data-test-input="maxLeaseTtl"] [data-test-ttl-value]').hasValue('3650');
|
|
|
|
assert.dom('[data-test-input="maxLeaseTtl"] [data-test-select="ttl-unit"]').hasValue('d');
|
|
|
|
|
|
|
|
// Go back and choose a different type
|
|
|
|
await page.back();
|
|
|
|
await page.selectType('database');
|
|
|
|
await page.next();
|
|
|
|
assert.dom('[data-test-input="maxLeaseTtl"]').exists('3650');
|
|
|
|
assert
|
|
|
|
.dom('[data-test-input="maxLeaseTtl"] [data-test-ttl-toggle]')
|
|
|
|
.isNotChecked('Toggle is unchecked by default');
|
|
|
|
await page.enableMaxTtl();
|
|
|
|
assert.dom('[data-test-input="maxLeaseTtl"] [data-test-ttl-value]').hasValue('');
|
|
|
|
assert.dom('[data-test-input="maxLeaseTtl"] [data-test-select="ttl-unit"]').hasValue('s');
|
2020-05-08 17:08:04 +00:00
|
|
|
});
|
2021-09-15 18:14:18 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it throws error if setting duplicate path name', async function (assert) {
|
2021-09-15 18:14:18 +00:00
|
|
|
const path = `kv-duplicate`;
|
|
|
|
|
|
|
|
await consoleComponent.runCommands([
|
|
|
|
// delete any kv-duplicate previously written here so that tests can be re-run
|
|
|
|
`delete sys/mounts/${path}`,
|
|
|
|
]);
|
|
|
|
|
|
|
|
await page.visit();
|
|
|
|
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(currentRouteName(), 'vault.cluster.settings.mount-secret-backend');
|
2021-09-15 18:14:18 +00:00
|
|
|
await page.selectType('kv');
|
2021-12-17 03:44:29 +00:00
|
|
|
await page.next().path(path).submit();
|
2021-09-15 18:14:18 +00:00
|
|
|
await page.secretList();
|
|
|
|
await settled();
|
|
|
|
await page.enableEngine();
|
|
|
|
await page.selectType('kv');
|
2021-12-17 03:44:29 +00:00
|
|
|
await page.next().path(path).submit();
|
2022-05-05 12:20:40 +00:00
|
|
|
assert.dom('[data-test-alert-banner="alert"]').containsText(`path is already in use at ${path}`);
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(currentRouteName(), 'vault.cluster.settings.mount-secret-backend');
|
2021-09-15 18:14:18 +00:00
|
|
|
|
|
|
|
await page.secretList();
|
|
|
|
await settled();
|
|
|
|
assert
|
|
|
|
.dom(`[data-test-secret-backend-row=${path}]`)
|
|
|
|
.exists({ count: 1 }, 'renders only one instance of the engine');
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('version 2 with no update to config endpoint still allows mount of secret engine', async function (assert) {
|
2023-03-22 18:19:11 +00:00
|
|
|
const enginePath = `kv-noUpdate-${this.uid}`;
|
2021-09-15 18:14:18 +00:00
|
|
|
const V2_POLICY = `
|
2021-10-14 17:47:10 +00:00
|
|
|
path "${enginePath}/*" {
|
2021-09-15 18:14:18 +00:00
|
|
|
capabilities = ["list","create","read","sudo","delete"]
|
|
|
|
}
|
|
|
|
path "sys/mounts/*"
|
|
|
|
{
|
|
|
|
capabilities = ["create", "read", "update", "delete", "list", "sudo"]
|
|
|
|
}
|
|
|
|
|
|
|
|
# List existing secrets engines.
|
|
|
|
path "sys/mounts"
|
|
|
|
{
|
|
|
|
capabilities = ["read"]
|
|
|
|
}
|
2022-12-16 21:26:43 +00:00
|
|
|
# Allow page to load after mount
|
|
|
|
path "sys/internal/ui/mounts/${enginePath}" {
|
|
|
|
capabilities = ["read"]
|
|
|
|
}
|
2021-09-15 18:14:18 +00:00
|
|
|
`;
|
|
|
|
await consoleComponent.runCommands([
|
2021-10-14 17:47:10 +00:00
|
|
|
// delete any previous mount with same name
|
|
|
|
`delete sys/mounts/${enginePath}`,
|
2021-09-15 18:14:18 +00:00
|
|
|
`write sys/policies/acl/kv-v2-degrade policy=${btoa(V2_POLICY)}`,
|
|
|
|
'write -field=client_token auth/token/create policies=kv-v2-degrade',
|
|
|
|
]);
|
2021-10-22 21:16:02 +00:00
|
|
|
await settled();
|
2022-11-09 23:15:31 +00:00
|
|
|
const userToken = consoleComponent.lastLogOutput;
|
2021-09-15 18:14:18 +00:00
|
|
|
await logout.visit();
|
|
|
|
await authPage.login(userToken);
|
|
|
|
// create the engine
|
|
|
|
await mountSecrets.visit();
|
|
|
|
await mountSecrets.selectType('kv');
|
2021-12-17 03:44:29 +00:00
|
|
|
await mountSecrets.next().path(enginePath).setMaxVersion(101).submit();
|
2021-09-15 18:14:18 +00:00
|
|
|
await settled();
|
2022-03-31 19:07:48 +00:00
|
|
|
assert
|
|
|
|
.dom('[data-test-flash-message]')
|
|
|
|
.containsText(
|
|
|
|
`You do not have access to the config endpoint. The secret engine was mounted, but the configuration settings were not saved.`
|
|
|
|
);
|
2022-12-16 21:26:43 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
currentURL(),
|
|
|
|
`/vault/secrets/${enginePath}/list`,
|
|
|
|
'After mounting, redirects to secrets list page'
|
|
|
|
);
|
2021-10-14 17:47:10 +00:00
|
|
|
await configPage.visit({ backend: enginePath });
|
2021-09-15 18:14:18 +00:00
|
|
|
await settled();
|
|
|
|
assert.dom('[data-test-row-value="Maximum number of versions"]').hasText('Not set');
|
|
|
|
});
|
2023-02-16 17:03:15 +00:00
|
|
|
|
|
|
|
test('it should transition to engine route on success if defined in mount config', async function (assert) {
|
2022-12-16 21:26:43 +00:00
|
|
|
await consoleComponent.runCommands([
|
|
|
|
// delete any previous mount with same name
|
2023-02-16 17:03:15 +00:00
|
|
|
`delete sys/mounts/kubernetes`,
|
2022-12-16 21:26:43 +00:00
|
|
|
]);
|
|
|
|
await mountSecrets.visit();
|
|
|
|
await mountSecrets.selectType('kubernetes');
|
|
|
|
await mountSecrets.next().path('kubernetes').submit();
|
|
|
|
const { engineRoute } = allEngines().findBy('type', 'kubernetes');
|
|
|
|
assert.strictEqual(
|
|
|
|
currentRouteName(),
|
|
|
|
`vault.cluster.secrets.backend.${engineRoute}`,
|
|
|
|
'Transitions to engine route on mount success'
|
|
|
|
);
|
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|