2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2022-11-19 01:29:04 +00:00
|
|
|
import { click, fillIn, find, currentURL, waitUntil } from '@ember/test-helpers';
|
2018-09-25 16:28:26 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
2023-03-22 18:19:11 +00:00
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
|
|
2018-04-03 14:16:57 +00:00
|
|
|
import page from 'vault/tests/pages/policies/index';
|
2018-09-25 16:28:26 +00:00
|
|
|
import authPage from 'vault/tests/pages/auth';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Acceptance | policies (old)', 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('policies', async function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
const policyString = 'path "*" { capabilities = ["update"]}';
|
2023-03-22 18:19:11 +00:00
|
|
|
const policyName = `Policy test ${this.uid}`;
|
2018-09-25 16:28:26 +00:00
|
|
|
const policyLower = policyName.toLowerCase();
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await page.visit({ type: 'acl' });
|
|
|
|
// new policy creation
|
|
|
|
await click('[data-test-policy-create-link]');
|
2021-12-17 03:44:29 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await fillIn('[data-test-policy-input="name"]', policyName);
|
|
|
|
await click('[data-test-policy-save]');
|
2022-11-19 01:29:04 +00:00
|
|
|
assert
|
|
|
|
.dom('[data-test-error]')
|
|
|
|
.hasText(`Error 'policy' parameter not supplied or empty`, 'renders error message on save');
|
2021-12-17 03:44:29 +00:00
|
|
|
find('.CodeMirror').CodeMirror.setValue(policyString);
|
2018-09-25 16:28:26 +00:00
|
|
|
await click('[data-test-policy-save]');
|
2021-12-17 03:44:29 +00:00
|
|
|
|
|
|
|
await waitUntil(() => currentURL() === `/vault/policy/acl/${encodeURIComponent(policyLower)}`);
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(
|
2018-04-03 14:16:57 +00:00
|
|
|
currentURL(),
|
|
|
|
`/vault/policy/acl/${encodeURIComponent(policyLower)}`,
|
|
|
|
'navigates to policy show on successful save'
|
|
|
|
);
|
2018-04-27 16:33:19 +00:00
|
|
|
assert.dom('[data-test-policy-name]').hasText(policyLower, 'displays the policy name on the show page');
|
|
|
|
assert.dom('[data-test-flash-message].is-info').doesNotExist('no flash message is displayed on save');
|
2018-09-25 16:28:26 +00:00
|
|
|
await click('[data-test-policy-list-link]');
|
2021-12-17 03:44:29 +00:00
|
|
|
|
2018-05-24 03:10:21 +00:00
|
|
|
assert
|
|
|
|
.dom(`[data-test-policy-link="${policyLower}"]`)
|
|
|
|
.exists({ count: 1 }, 'new policy shown in the list');
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
// policy deletion
|
|
|
|
await click(`[data-test-policy-link="${policyLower}"]`);
|
2021-12-17 03:44:29 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await click('[data-test-policy-edit-toggle]');
|
2021-12-17 03:44:29 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await click('[data-test-policy-delete] button');
|
2021-12-17 03:44:29 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await click('[data-test-confirm-button]');
|
2021-12-17 03:44:29 +00:00
|
|
|
await waitUntil(() => currentURL() === `/vault/policies/acl`);
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
currentURL(),
|
|
|
|
`/vault/policies/acl`,
|
|
|
|
'navigates to policy list on successful deletion'
|
|
|
|
);
|
2018-05-24 03:10:21 +00:00
|
|
|
assert
|
|
|
|
.dom(`[data-test-policy-item="${policyLower}"]`)
|
|
|
|
.doesNotExist('deleted policy is not shown in the list');
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
2018-04-20 01:51:41 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
// https://github.com/hashicorp/vault/issues/4395
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it properly fetches policies when the name ends in a ,', async function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
const policyString = 'path "*" { capabilities = ["update"]}';
|
2023-03-22 18:19:11 +00:00
|
|
|
const policyName = `${this.uid}-policy-symbol,.`;
|
2018-04-20 01:51:41 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await page.visit({ type: 'acl' });
|
|
|
|
// new policy creation
|
|
|
|
await click('[data-test-policy-create-link]');
|
2021-12-17 03:44:29 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await fillIn('[data-test-policy-input="name"]', policyName);
|
2021-12-17 03:44:29 +00:00
|
|
|
find('.CodeMirror').CodeMirror.setValue(policyString);
|
2018-09-25 16:28:26 +00:00
|
|
|
await click('[data-test-policy-save]');
|
2021-12-17 03:44:29 +00:00
|
|
|
assert.ok(
|
|
|
|
await waitUntil(() => currentURL() === `/vault/policy/acl/${policyName}`),
|
2018-04-20 20:39:45 +00:00
|
|
|
'navigates to policy show on successful save'
|
|
|
|
);
|
2018-04-27 16:33:19 +00:00
|
|
|
assert.dom('[data-test-policy-edit-toggle]').exists({ count: 1 }, 'shows the edit toggle');
|
2018-04-20 01:51:41 +00:00
|
|
|
});
|
|
|
|
});
|