-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathscopes-test.js
More file actions
429 lines (360 loc) · 12.2 KB
/
Copy pathscopes-test.js
File metadata and controls
429 lines (360 loc) · 12.2 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import {
visit,
currentURL,
click,
find,
findAll,
waitFor,
} from '@ember/test-helpers';
import { setupApplicationTest } from 'desktop/tests/helpers';
import { Response } from 'miragejs';
import {
currentSession,
invalidateSession,
} from 'ember-simple-auth/test-support';
import WindowMockIPC from '../helpers/window-mock-ipc';
import setupStubs from 'api/test-support/handlers/cache-daemon-search';
import { setRunOptions } from 'ember-a11y-testing/test-support';
module('Acceptance | scopes', function (hooks) {
setupApplicationTest(hooks);
setupStubs(hooks);
const APP_STATE_TITLE = '.hds-application-state__title';
const META_DATA_RESPONSE = {
builds: [
{ os: 'windows', url: 'windows.fake.download.zip' },
{ os: 'darwin', url: 'darwin.fake.download.dmg' },
{ os: 'linux', url: 'linux.fake.download.deb' },
],
};
const instances = {
scopes: {
global: null,
org: null,
project: null,
},
authMethods: {
global: null,
},
target: null,
session: null,
};
const urls = {
index: '/',
clusterUrl: '/cluster-url',
scopes: {
global: null,
org: null,
org2: null,
},
authenticate: {
global: null,
methods: {
global: null,
},
},
projects: null,
org2Projects: null,
globalProjects: null,
targets: null,
org2Targets: null,
globalTargets: null,
target: null,
};
const setDefaultClusterUrl = (test) => {
const windowOrigin = window.location.origin;
const clusterUrl = test.owner.lookup('service:clusterUrl');
clusterUrl.rendererClusterUrl = windowOrigin;
};
hooks.beforeEach(async function () {
// bypass mirage config that expects recursive to be passed in as queryParam
this.server.get('/targets', ({ targets }) => targets.all());
// create scopes
instances.scopes.global = this.server.schema.scopes.find('global');
const globalScope = { id: 'global', type: 'global' };
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: globalScope,
});
instances.scopes.org2 = this.server.create('scope', {
type: 'org',
scope: globalScope,
});
const orgScope = { id: instances.scopes.org.id, type: 'org' };
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: orgScope,
});
instances.authMethods.global = this.server.schema.authMethods.first();
instances.hostCatalog = this.server.create(
'host-catalog',
{ scope: instances.scopes.project },
'withChildren',
);
instances.target = this.server.create(
'target',
{ scope: instances.scopes.project, address: 'localhost' },
'withAssociations',
);
instances.session = this.server.create(
'session',
{
scope: instances.scopes.project,
status: 'active',
},
'withAssociations',
);
urls.scopes.global = `/scopes/${instances.scopes.global.id}`;
urls.scopes.org = `/scopes/${instances.scopes.org.id}`;
urls.scopes.org2 = `/scopes/${instances.scopes.org2.id}`;
urls.authenticate.global = `${urls.scopes.global}/authenticate`;
urls.authenticate.methods.global = `${urls.authenticate.global}/${instances.authMethods.global.id}`;
urls.projects = `${urls.scopes.org}/projects`;
urls.org2Projects = `${urls.scopes.org2}/projects`;
urls.globalProjects = `${urls.scopes.global}/projects`;
urls.targets = `${urls.projects}/targets`;
urls.org2Targets = `${urls.org2Projects}/targets`;
urls.globalTargets = `${urls.globalProjects}/targets`;
urls.target = `${urls.targets}/${instances.target.id}`;
this.owner.register('service:browser/window', WindowMockIPC);
setDefaultClusterUrl(this);
this.ipcStub.withArgs('isCacheDaemonRunning').returns(true);
this.stubCacheDaemonSearch('sessions', 'targets', 'aliases');
});
test('visiting index', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
assert.expect(2);
const targetsCount = this.server.schema.targets.all().models.length;
await visit(urls.targets);
assert.strictEqual(currentURL(), urls.targets);
assert.strictEqual(findAll('tbody tr').length, targetsCount);
});
test('visiting global scope', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
assert.expect(1);
await visit(urls.scopes.global);
assert.strictEqual(currentURL(), urls.globalTargets);
});
// TODO: this probably shouldn't be the case, but was setup to enable
// authentication when the global scope couldn't be loaded.
// In order to resolve this, we might hoist authentication routes up from
// under scopes.
test('visiting global scope is not successful when the global scope cannot be fetched', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
assert.expect(1);
this.server.get('/scopes/:id', ({ scopes }, { params: { id } }) => {
const scope = scopes.find(id);
const response = id === 'global' ? new Response(404) : scope;
return response;
});
await visit(urls.scopes.global);
assert.strictEqual(currentURL(), urls.globalTargets);
});
test('visiting org scope', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
assert.expect(1);
await visit(urls.scopes.org);
assert.strictEqual(currentURL(), urls.targets);
});
test('can navigate among org scopes via header navigation', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
assert.expect(3);
this.stubCacheDaemonSearch(
'sessions',
'targets',
'aliases',
'sessions',
'targets',
'aliases',
'sessions',
'targets',
'aliases',
'sessions',
'targets',
'aliases',
);
await visit(urls.targets);
await click('.rose-header-nav .hds-dropdown-toggle-button');
await click('.rose-header-nav .hds-dropdown-list-item:nth-of-type(3) a');
assert.strictEqual(currentURL(), urls.targets);
await click('.rose-header-nav .hds-dropdown-list-item:nth-of-type(4) a');
assert.strictEqual(currentURL(), urls.org2Targets);
await click('.rose-header-nav .hds-dropdown-list-item:nth-of-type(1) a');
assert.strictEqual(currentURL(), urls.globalTargets);
});
test('visiting index while unauthenticated redirects to global authenticate method', async function (assert) {
await invalidateSession();
assert.expect(2);
this.stubCacheDaemonSearch();
await visit(urls.targets);
assert.notOk(currentSession().isAuthenticated);
assert.strictEqual(currentURL(), urls.authenticate.methods.global);
});
test('visiting a target', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
assert.expect(1);
await visit(urls.targets);
await click('[data-test-visit-target]');
assert.strictEqual(currentURL(), urls.target);
});
test('visiting empty targets', async function (assert) {
this.server.schema.targets.all().destroy();
this.server.schema.sessions.all().destroy();
this.stubCacheDaemonSearch('sessions', 'targets', 'aliases');
await visit(urls.targets);
assert.ok(find(APP_STATE_TITLE).textContent.trim(), 'No Targets Available');
});
test.skip('pagination is not supported - windows build', async function (assert) {
this.ipcStub.withArgs('checkOS').returns({
isWindows: true,
isMac: false,
isLinux: false,
});
this.server.get('https://api.releases.hashicorp.com/*', () => {
return new Response(200, {}, META_DATA_RESPONSE);
});
this.server.get('/scopes', () => {
// no "response_type" field
return new Response(200, {}, { scopes: [] });
});
await visit(urls.targets);
await waitFor('[data-test-unsupported-controller]');
assert.dom('[data-test-unsupported-controller]').exists();
assert
.dom('[data-test-download-link]')
.hasAttribute('href', 'windows.fake.download.zip');
});
test.skip('pagination is not supported - mac build', async function (assert) {
this.ipcStub.withArgs('checkOS').returns({
isWindows: false,
isMac: true,
isLinux: false,
});
this.server.get('/scopes', () => {
// no "response_type" field
return new Response(200, {}, { scopes: [] });
});
this.server.get('https://api.releases.hashicorp.com/*', () => {
return new Response(200, {}, META_DATA_RESPONSE);
});
await visit(urls.targets);
await waitFor('[data-test-unsupported-controller]');
assert.dom('[data-test-unsupported-controller]').exists();
assert
.dom('[data-test-download-link]')
.hasAttribute('href', 'darwin.fake.download.dmg');
});
test.skip('pagination is not supported - linux build', async function (assert) {
this.ipcStub.withArgs('checkOS').returns({
isWindows: false,
isMac: false,
isLinux: true,
});
this.server.get('/scopes', () => {
// no "response_type" field
return new Response(200, {}, { scopes: [] });
});
this.server.get('https://api.releases.hashicorp.com/*', () => {
return new Response(200, {}, META_DATA_RESPONSE);
});
await visit(urls.targets);
await waitFor('[data-test-unsupported-controller]');
assert.dom('[data-test-unsupported-controller]').exists();
assert
.dom('[data-test-download-link]')
.hasAttribute('href', 'linux.fake.download.deb');
});
test.skip('pagination is not supported - failed to fetch metaData', async function (assert) {
this.ipcStub.withArgs('checkOS').returns({
isWindows: true,
isMac: false,
isLinux: false,
});
this.server.get('/scopes', () => {
// no "response_type" field
return new Response(200, {}, { scopes: [] });
});
this.server.get('https://api.releases.hashicorp.com/*', () => {
return new Response(500);
});
await visit(urls.targets);
await waitFor('[data-test-unsupported-controller-alert]');
assert.dom('[data-test-unsupported-controller-alert]').exists();
assert
.dom('[data-test-releases-link]')
.hasAttribute('href', 'https://releases.hashicorp.com/boundary-desktop/');
});
test('pagination is not supported - navigate to cluster url page', async function (assert) {
await invalidateSession();
this.stubCacheDaemonSearch();
this.ipcStub.withArgs('checkOS').returns({
isWindows: true,
isMac: false,
isLinux: false,
});
this.server.get('/scopes', () => {
// no "response_type" field
return new Response(200, {}, { scopes: [] });
});
this.server.get('https://api.releases.hashicorp.com/*', () => {
return new Response(200, {}, META_DATA_RESPONSE);
});
await visit(urls.targets);
await waitFor('[data-test-unsupported-controller]');
assert.dom('[data-test-unsupported-controller]').exists();
assert
.dom('[data-test-download-link]')
.hasAttribute('href', 'windows.fake.download.zip');
assert
.dom('[data-test-change-cluster-url]')
.hasAttribute('href', '/cluster-url');
await click('[data-test-change-cluster-url]');
assert.strictEqual(currentURL(), urls.clusterUrl);
});
});