2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2019-01-18 22:04:40 +00:00
|
|
|
import { create } from 'ember-cli-page-object';
|
2023-05-03 01:36:15 +00:00
|
|
|
import { settled, click, visit } from '@ember/test-helpers';
|
2019-01-18 22:04:40 +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';
|
|
|
|
|
2019-01-18 22:04:40 +00:00
|
|
|
import authPage from 'vault/tests/pages/auth';
|
|
|
|
import logout from 'vault/tests/pages/logout';
|
2022-05-26 20:13:47 +00:00
|
|
|
import enablePage from 'vault/tests/pages/settings/auth/enable';
|
2019-01-18 22:04:40 +00:00
|
|
|
import consoleClass from 'vault/tests/pages/components/console/ui-panel';
|
|
|
|
|
|
|
|
const consoleComponent = create(consoleClass);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
const tokenWithPolicy = async function (name, policy) {
|
2019-01-18 22:04:40 +00:00
|
|
|
await consoleComponent.runCommands([
|
2019-05-22 21:07:42 +00:00
|
|
|
`write sys/policies/acl/${name} policy=${btoa(policy)}`,
|
2019-01-18 22:04:40 +00:00
|
|
|
`write -field=client_token auth/token/create policies=${name}`,
|
|
|
|
]);
|
|
|
|
|
|
|
|
return consoleComponent.lastLogOutput;
|
|
|
|
};
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Acceptance | cluster', function (hooks) {
|
2019-01-18 22:04:40 +00:00
|
|
|
setupApplicationTest(hooks);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.beforeEach(async function () {
|
2019-01-18 22:04:40 +00:00
|
|
|
await logout.visit();
|
|
|
|
return authPage.login();
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('hides nav item if user does not have permission', async function (assert) {
|
2019-05-22 21:07:42 +00:00
|
|
|
const deny_policies_policy = `
|
2019-01-18 22:04:40 +00:00
|
|
|
path "sys/policies/*" {
|
|
|
|
capabilities = ["deny"]
|
|
|
|
},
|
2019-05-22 21:07:42 +00:00
|
|
|
`;
|
2019-01-18 22:04:40 +00:00
|
|
|
|
|
|
|
const userToken = await tokenWithPolicy('hide-policies-nav', deny_policies_policy);
|
|
|
|
await logout.visit();
|
|
|
|
await authPage.login(userToken);
|
2023-05-03 01:36:15 +00:00
|
|
|
await visit('/vault/access');
|
2019-01-18 22:04:40 +00:00
|
|
|
|
2023-05-03 01:36:15 +00:00
|
|
|
assert.dom('[data-test-sidebar-nav-link="Policies"]').doesNotExist();
|
2019-01-18 22:04:40 +00:00
|
|
|
await logout.visit();
|
|
|
|
});
|
|
|
|
|
2022-05-26 20:13:47 +00:00
|
|
|
test('it hides mfa setup if user has not entityId (ex: is a root user)', async function (assert) {
|
2023-05-03 01:36:15 +00:00
|
|
|
const user = 'end-user';
|
|
|
|
const password = 'mypassword';
|
|
|
|
const path = `cluster-userpass-${uuidv4()}`;
|
|
|
|
|
|
|
|
await enablePage.enable('userpass', path);
|
|
|
|
await consoleComponent.runCommands([`write auth/${path}/users/end-user password="${password}"`]);
|
2022-05-26 20:13:47 +00:00
|
|
|
|
|
|
|
await logout.visit();
|
|
|
|
await settled();
|
2023-05-03 01:36:15 +00:00
|
|
|
await authPage.loginUsername(user, password, path);
|
|
|
|
await click('[data-test-user-menu-trigger]');
|
|
|
|
assert.dom('[data-test-user-menu-item="mfa"]').exists();
|
2022-05-26 20:13:47 +00:00
|
|
|
await logout.visit();
|
|
|
|
|
|
|
|
await authPage.login('root');
|
|
|
|
await settled();
|
2023-05-03 01:36:15 +00:00
|
|
|
await click('[data-test-user-menu-trigger]');
|
|
|
|
assert.dom('[data-test-user-menu-item="mfa"]').doesNotExist();
|
2022-05-26 20:13:47 +00:00
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('enterprise nav item links to first route that user has access to', async function (assert) {
|
2019-05-22 21:07:42 +00:00
|
|
|
const read_rgp_policy = `
|
2019-01-18 22:04:40 +00:00
|
|
|
path "sys/policies/rgp" {
|
|
|
|
capabilities = ["read"]
|
|
|
|
},
|
2019-05-22 21:07:42 +00:00
|
|
|
`;
|
2019-01-18 22:04:40 +00:00
|
|
|
|
|
|
|
const userToken = await tokenWithPolicy('show-policies-nav', read_rgp_policy);
|
|
|
|
await logout.visit();
|
|
|
|
await authPage.login(userToken);
|
2023-05-03 01:36:15 +00:00
|
|
|
await visit('/vault/access');
|
|
|
|
|
|
|
|
assert.dom('[data-test-sidebar-nav-link="Policies"]').hasAttribute('href', '/ui/vault/policies/rgp');
|
2019-01-18 22:04:40 +00:00
|
|
|
await logout.visit();
|
|
|
|
});
|
|
|
|
});
|