-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathaccess-control-test.js
More file actions
196 lines (166 loc) · 5.92 KB
/
access-control-test.js
File metadata and controls
196 lines (166 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**
* Copyright IBM Corp. 2015, 2025
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { currentURL, triggerKeyEvent, click } 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';
import faker from 'nomad-ui/mirage/faker';
// 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 () {
faker.seed(1);
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 does not show Sentinel Policies if they are not present in license', async function (assert) {
allScenarios.policiesTestCluster(server);
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-sentinel-policies-card]').doesNotExist();
});
test('Access control shows Sentinel Policies if they are present in license', async function (assert) {
assert.expect(2);
allScenarios.policiesTestCluster(server, { sentinel: true });
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-sentinel-policies-card]').exists();
await click('[data-test-sentinel-policies-card] a');
assert.equal(currentURL(), '/administration/sentinel-policies');
});
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'
);
});
});