Files
nomad/ui/tests/acceptance/access-control-test.js
Phil Renaud 86c858cdc3 [ui] Sentinel Policies CRUD UI (#20483)
* Gallery allows picking stuff

* Small fixes

* added sentinel templates

* Can set enforcement level on policies

* Working on the interactive sentinel dev mode

* Very rough development flow on FE

* Changed position in gutter menu

* More sentinel stuff

* PR cleanup: removed testmode, removed unneeded mixins and deps

* Heliosification

* Index-level sentinel policy deletion and page title fixes

* Makes the Canaries sentinel policy real and then comments out the unfinished ones

* rename Access Control to Administration in prep for moving Sentinel Policies and Node Pool admin there

* Sentinel policies moved within the Administration section

* Mirage fixture for sentinel policy endpoints

* Description length check and 500 prevention

* Sync review PR feedback addressed, implied butons on radio cards

* Cull un-used sentinel policies

---------

Co-authored-by: Mike Nomitch <mail@mikenomitch.com>
2024-05-22 16:41:50 -04:00

165 lines
4.8 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { currentURL, triggerKeyEvent } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import Administration from 'nomad-ui/tests/pages/administration';
import Tokens from 'nomad-ui/tests/pages/settings/tokens';
import { allScenarios } from '../../mirage/scenarios/default';
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
// Several related tests within Access Control are contained in the Tokens, Roles,
// and Policies acceptance tests.
module('Acceptance | access control', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
hooks.beforeEach(function () {
window.localStorage.clear();
window.sessionStorage.clear();
// server.create('token');
allScenarios.rolesTestCluster(server);
});
test('Access Control is only accessible by a management user', async function (assert) {
assert.expect(7);
await Administration.visit();
assert.equal(
currentURL(),
'/jobs',
'redirected to the jobs page if a non-management token on /administration'
);
await Administration.visitTokens();
assert.equal(
currentURL(),
'/jobs',
'redirected to the jobs page if a non-management token on /tokens'
);
assert.dom('[data-test-gutter-link="administration"]').doesNotExist();
await Tokens.visit();
const managementToken = server.db.tokens.findBy(
(t) => t.type === 'management'
);
const { secretId } = managementToken;
await Tokens.secret(secretId).submit();
assert.dom('[data-test-gutter-link="administration"]').exists();
await Administration.visit();
assert.equal(
currentURL(),
'/administration',
'management token can access /administration'
);
await a11yAudit(assert);
await Administration.visitTokens();
assert.equal(
currentURL(),
'/administration/tokens',
'management token can access /administration/tokens'
);
});
test('Access control index content', async function (assert) {
await Tokens.visit();
const managementToken = server.db.tokens.findBy(
(t) => t.type === 'management'
);
const { secretId } = managementToken;
await Tokens.secret(secretId).submit();
await Administration.visit();
assert.dom('[data-test-tokens-card]').exists();
assert.dom('[data-test-roles-card]').exists();
assert.dom('[data-test-policies-card]').exists();
assert.dom('[data-test-namespaces-card]').exists();
const numberOfTokens = server.db.tokens.length;
const numberOfRoles = server.db.roles.length;
const numberOfPolicies = server.db.policies.length;
const numberOfNamespaces = server.db.namespaces.length;
assert
.dom('[data-test-tokens-card] a')
.includesText(`${numberOfTokens} Tokens`);
assert
.dom('[data-test-roles-card] a')
.includesText(`${numberOfRoles} Roles`);
assert
.dom('[data-test-policies-card] a')
.includesText(`${numberOfPolicies} Policies`);
assert
.dom('[data-test-namespaces-card] a')
.includesText(`${numberOfNamespaces} Namespaces`);
});
test('Access control subnav', async function (assert) {
await Tokens.visit();
const managementToken = server.db.tokens.findBy(
(t) => t.type === 'management'
);
const { secretId } = managementToken;
await Tokens.secret(secretId).submit();
await Administration.visit();
assert.equal(currentURL(), '/administration');
await triggerKeyEvent('.page-layout', 'keydown', 'ArrowRight', {
shiftKey: true,
});
assert.equal(
currentURL(),
`/administration/tokens`,
'Shift+ArrowRight takes you to the next tab (Tokens)'
);
await triggerKeyEvent('.page-layout', 'keydown', 'ArrowRight', {
shiftKey: true,
});
assert.equal(
currentURL(),
`/administration/roles`,
'Shift+ArrowRight takes you to the next tab (Roles)'
);
await triggerKeyEvent('.page-layout', 'keydown', 'ArrowRight', {
shiftKey: true,
});
assert.equal(
currentURL(),
`/administration/policies`,
'Shift+ArrowRight takes you to the next tab (Policies)'
);
await triggerKeyEvent('.page-layout', 'keydown', 'ArrowRight', {
shiftKey: true,
});
assert.equal(
currentURL(),
`/administration/namespaces`,
'Shift+ArrowRight takes you to the next tab (Namespaces)'
);
await triggerKeyEvent('.page-layout', 'keydown', 'ArrowRight', {
shiftKey: true,
});
assert.equal(
currentURL(),
`/administration`,
'Shift+ArrowLeft takes you back to the Access Control index page'
);
});
});