-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
auth-list-test.js
156 lines (139 loc) · 5.97 KB
/
auth-list-test.js
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
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
/* eslint qunit/no-conditional-assertions: "warn" */
import { click, fillIn, settled, visit, currentURL } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { v4 as uuidv4 } from 'uuid';
import authPage from 'vault/tests/pages/auth';
import enablePage from 'vault/tests/pages/settings/auth/enable';
import { allSupportedAuthBackends, supportedAuthBackends } from 'vault/helpers/supported-auth-backends';
import { supportedManagedAuthBackends } from 'vault/helpers/supported-managed-auth-backends';
import { deleteAuthCmd, mountAuthCmd, runCmd } from 'vault/tests/helpers/commands';
const SELECTORS = {
backendLink: (path) => `[data-test-auth-backend-link="${path}"]`,
createUser: '[data-test-entity-create-link="user"]',
input: (attr) => `[data-test-input="${attr}"]`,
password: '[data-test-textarea]',
saveBtn: '[data-test-save-config]',
methods: '[data-test-access-methods]',
listItem: '[data-test-list-item-content]',
};
module('Acceptance | auth backend list', function (hooks) {
setupApplicationTest(hooks);
hooks.beforeEach(async function () {
await authPage.login();
this.path1 = `userpass-${uuidv4()}`;
this.path2 = `userpass-${uuidv4()}`;
this.user1 = 'user1';
this.user2 = 'user2';
await runCmd(mountAuthCmd('userpass', this.path1));
await runCmd(mountAuthCmd('userpass', this.path2));
});
hooks.afterEach(async function () {
await authPage.login();
await runCmd(deleteAuthCmd(this.path1));
await runCmd(deleteAuthCmd(this.path2));
return;
});
test('userpass secret backend', async function (assert) {
assert.expect(5);
// enable a user in first userpass backend
await visit('/vault/access');
await click(SELECTORS.backendLink(this.path1));
await click(SELECTORS.createUser);
await fillIn(SELECTORS.input('username'), this.user1);
await fillIn(SELECTORS.password, this.user1);
await click(SELECTORS.saveBtn);
assert.strictEqual(currentURL(), `/vault/access/${this.path1}/item/user`);
await click(SELECTORS.methods);
assert.strictEqual(currentURL(), '/vault/access');
// enable a user in second userpass backend
await click(SELECTORS.backendLink(this.path2));
await click(SELECTORS.createUser);
await fillIn(SELECTORS.input('username'), this.user2);
await fillIn(SELECTORS.password, this.user2);
await click(SELECTORS.saveBtn);
assert.strictEqual(currentURL(), `/vault/access/${this.path2}/item/user`);
// Confirm that the user was created. There was a bug where the apiPath was not being updated when toggling between auth routes.
assert.dom(SELECTORS.listItem).hasText(this.user2, 'user2 exists in the list');
// Confirm that the auth method 1 shows user1. There was a bug where the user was not listed when toggling between auth routes.
await click(SELECTORS.methods);
await click(SELECTORS.backendLink(this.path1));
assert.dom(SELECTORS.listItem).hasText(this.user1, 'user1 exists in the list');
});
test('auth methods are linkable and link to correct view', async function (assert) {
assert.expect(16);
const uid = uuidv4();
await click('[data-test-root-warning-confirm]');
await visit('/vault/access');
const supportManaged = supportedManagedAuthBackends();
const backends = supportedAuthBackends();
for (const backend of backends) {
const { type } = backend;
const path = `auth-list-${type}-${uid}`;
if (type !== 'token') {
await enablePage.enable(type, path);
}
await settled();
await visit('/vault/access');
// all auth methods should be linkable
await click(`[data-test-auth-backend-link="${type === 'token' ? type : path}"]`);
if (!supportManaged.includes(type)) {
assert.dom('[data-test-auth-section-tab]').exists({ count: 1 });
assert
.dom('[data-test-auth-section-tab]')
.hasText('Configuration', `only shows configuration tab for ${type} auth method`);
assert.dom('[data-test-doc-link] .doc-link').exists(`includes doc link for ${type} auth method`);
} else {
let expectedTabs = 2;
if (type == 'ldap' || type === 'okta') {
expectedTabs = 3;
}
assert
.dom('[data-test-auth-section-tab]')
.exists({ count: expectedTabs }, `has management tabs for ${type} auth method`);
// cleanup method
await runCmd(deleteAuthCmd(path));
}
}
});
test('enterprise: auth methods are linkable and link to correct view', async function (assert) {
assert.expect(19);
const uid = uuidv4();
await click('[data-test-root-warning-confirm]');
await visit('/vault/access');
const supportManaged = supportedManagedAuthBackends();
const backends = allSupportedAuthBackends();
for (const backend of backends) {
const { type } = backend;
const path = `auth-list-${type}-${uid}`;
if (type !== 'token') {
await enablePage.enable(type, path);
}
await settled();
await visit('/vault/access');
// all auth methods should be linkable
await click(`[data-test-auth-backend-link="${type === 'token' ? type : path}"]`);
if (!supportManaged.includes(type)) {
assert.dom('[data-test-auth-section-tab]').exists({ count: 1 });
assert
.dom('[data-test-auth-section-tab]')
.hasText('Configuration', `only shows configuration tab for ${type} auth method`);
assert.dom('[data-test-doc-link] .doc-link').exists(`includes doc link for ${type} auth method`);
} else {
let expectedTabs = 2;
if (type == 'ldap' || type === 'okta') {
expectedTabs = 3;
}
assert
.dom('[data-test-auth-section-tab]')
.exists({ count: expectedTabs }, `has management tabs for ${type} auth method`);
// cleanup method
await runCmd(deleteAuthCmd(path));
}
}
});
});