Skip to content

Commit 5ce3f49

Browse files
committed
UI: Add auth tests (#30033)
* rename page test to login form * add username/password tests to auth page test * add github and generalize tests * finish standard auth types for page test * add tests for onNamespaceInput * fix accessibility violation * add oidc provider qp test * move helper into test * move destructured arg * address oidc auth method flakiness...maybe? * cleanup unused fake window methods * add comment why... * fix diff * fix header * finish mfa acceptance tests move mfa selectors to folder
1 parent 0bdc84b commit 5ce3f49

File tree

4 files changed

+10
-137
lines changed

4 files changed

+10
-137
lines changed

ui/tests/acceptance/auth/mfa-test.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { callbackData, WindowStub } from 'vault/tests/helpers/oidc-window-stub';
1616
import sinon from 'sinon';
1717

1818
const ENT_ONLY = ['saml'];
19-
const DELAY_IN_MS = 500;
2019

2120
// See AUTH_METHOD_TEST_CASES for how request data maps to method types
2221
// authRequest is the request made on submit and what returns mfa_validation requirements (if any)
@@ -106,7 +105,7 @@ for (const method of AUTH_METHOD_TEST_CASES) {
106105
setTimeout(() => {
107106
// set path which is used to set :mount param in the callback url => /auth/:mount/oidc/callback
108107
window.postMessage(callbackData({ path: this.mountPath }), window.origin);
109-
}, DELAY_IN_MS);
108+
}, 50);
110109
}
111110

112111
await click(AUTH_FORM.login);
@@ -142,7 +141,7 @@ for (const method of AUTH_METHOD_TEST_CASES) {
142141
setTimeout(() => {
143142
// set path which is used to set :mount param in the callback url => /auth/:mount/oidc/callback
144143
window.postMessage(callbackData({ path: this.mountPath }), window.origin);
145-
}, DELAY_IN_MS);
144+
}, 50);
146145
}
147146

148147
await click(AUTH_FORM.login);
@@ -180,7 +179,7 @@ for (const method of AUTH_METHOD_TEST_CASES) {
180179
setTimeout(() => {
181180
// set path which is used to set :mount param in the callback url => /auth/:mount/oidc/callback
182181
window.postMessage(callbackData({ path: this.mountPath }), window.origin);
183-
}, DELAY_IN_MS);
182+
}, 50);
184183
}
185184

186185
await click(AUTH_FORM.login);
@@ -214,7 +213,7 @@ for (const method of AUTH_METHOD_TEST_CASES) {
214213
setTimeout(() => {
215214
// set path which is used to set :mount param in the callback url => /auth/:mount/oidc/callback
216215
window.postMessage(callbackData({ path: this.mountPath }), window.origin);
217-
}, DELAY_IN_MS);
216+
}, 50);
218217
}
219218

220219
await click(AUTH_FORM.login);

ui/tests/acceptance/oidc-auth-method-test.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import sinon from 'sinon';
1313
import { Response } from 'miragejs';
1414
import { setupTotpMfaResponse } from 'vault/tests/helpers/mfa/mfa-helpers';
1515

16-
const DELAY_IN_MS = 500;
17-
1816
module('Acceptance | oidc auth method', function (hooks) {
1917
setupApplicationTest(hooks);
2018
setupMirage(hooks);
@@ -70,7 +68,7 @@ module('Acceptance | oidc auth method', function (hooks) {
7068
await this.selectMethod('oidc');
7169
setTimeout(() => {
7270
window.postMessage(buildMessage().data, window.origin);
73-
}, DELAY_IN_MS);
71+
}, 50);
7472

7573
await click('[data-test-auth-submit]');
7674
});
@@ -99,7 +97,7 @@ module('Acceptance | oidc auth method', function (hooks) {
9997
await this.selectMethod('oidc', true);
10098
setTimeout(() => {
10199
window.postMessage(buildMessage().data, window.origin);
102-
}, DELAY_IN_MS);
100+
}, 50);
103101
await click('[data-test-auth-submit]');
104102
});
105103

@@ -112,7 +110,7 @@ module('Acceptance | oidc auth method', function (hooks) {
112110

113111
setTimeout(() => {
114112
window.postMessage(buildMessage().data, window.origin);
115-
}, 500);
113+
}, 50);
116114

117115
await click('[data-test-auth-submit]');
118116
assert
@@ -169,7 +167,7 @@ module('Acceptance | oidc auth method', function (hooks) {
169167
await this.selectMethod('oidc');
170168
setTimeout(() => {
171169
window.postMessage(buildMessage().data, window.origin);
172-
}, DELAY_IN_MS);
170+
}, 50);
173171

174172
await click('[data-test-auth-submit]');
175173
await waitUntil(() => find('[data-test-mfa-form]'));

ui/tests/integration/components/auth/login-form-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ module('Integration | Component | auth | login-form', function (hooks) {
145145
this.server.post('/sys/wrapping/unwrap', (_, req) => {
146146
assert.strictEqual(req.url, '/v1/sys/wrapping/unwrap', 'makes call to unwrap the token');
147147
assert.strictEqual(
148-
req.requestHeaders['X-Vault-Token'],
148+
req.requestHeaders['x-vault-token'],
149149
this.wrappedToken,
150150
'uses passed wrapped token for the unwrap'
151151
);

ui/tests/integration/components/auth/page-test.js

Lines changed: 1 addition & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -46,131 +46,7 @@ module('Integration | Component | auth | page', function (hooks) {
4646
await this.renderComponent();
4747
assert.dom(AUTH_FORM.logo).exists();
4848
assert
49-
.dom(GENERAL.messageError)
50-
.hasText('Error Authentication failed: API Error here', 'shows the error from the API');
51-
});
52-
53-
test('it calls auth service authenticate method with expected args', async function (assert) {
54-
assert.expect(1);
55-
const authenticateStub = sinon.stub(this.auth, 'authenticate');
56-
this.selectedAuth = 'foo/'; // set to a non-default path
57-
this.server.get('/sys/internal/ui/mounts', () => {
58-
return {
59-
data: {
60-
auth: {
61-
'foo/': {
62-
type: 'userpass',
63-
},
64-
},
65-
},
66-
};
67-
});
68-
69-
await this.renderComponent();
70-
await fillIn(AUTH_FORM.input('username'), 'sandy');
71-
await fillIn(AUTH_FORM.input('password'), '1234');
72-
await click(AUTH_FORM.login);
73-
const [actual] = authenticateStub.lastCall.args;
74-
const expectedArgs = {
75-
backend: 'userpass',
76-
clusterId: '1',
77-
data: {
78-
username: 'sandy',
79-
password: '1234',
80-
path: 'foo',
81-
},
82-
selectedAuth: 'foo/',
83-
};
84-
assert.propEqual(
85-
actual,
86-
expectedArgs,
87-
`it calls auth service authenticate method with expected args: ${JSON.stringify(actual)} `
88-
);
89-
});
90-
91-
test('it calls onSuccess with expected args', async function (assert) {
92-
assert.expect(3);
93-
this.server.get(`auth/token/lookup-self`, () => {
94-
return {
95-
data: {
96-
policies: ['default'],
97-
},
98-
};
99-
});
100-
101-
await this.renderComponent();
102-
await fillIn(AUTH_FORM.input('token'), 'mytoken');
103-
await click(AUTH_FORM.login);
104-
const [authResponse, backendType, data] = this.onSuccess.lastCall.args;
105-
const expected = { isRoot: false, namespace: '', token: 'vault-token☃1' };
106-
107-
assert.propEqual(
108-
authResponse,
109-
expected,
110-
`it calls onSuccess with response: ${JSON.stringify(authResponse)} `
111-
);
112-
assert.strictEqual(backendType, 'token', `it calls onSuccess with backend type: ${backendType}`);
113-
assert.propEqual(data, { token: 'mytoken' }, `it calls onSuccess with data: ${JSON.stringify(data)}`);
114-
});
115-
116-
test('it makes a request to unwrap if passed a wrappedToken and logs in', async function (assert) {
117-
assert.expect(3);
118-
const authenticateStub = sinon.stub(this.auth, 'authenticate');
119-
this.wrappedToken = '54321';
120-
121-
this.server.post('/sys/wrapping/unwrap', (_, req) => {
122-
assert.strictEqual(req.url, '/v1/sys/wrapping/unwrap', 'makes call to unwrap the token');
123-
assert.strictEqual(
124-
req.requestHeaders['x-vault-token'],
125-
this.wrappedToken,
126-
'uses passed wrapped token for the unwrap'
127-
);
128-
return {
129-
auth: {
130-
client_token: '12345',
131-
},
132-
};
133-
});
134-
135-
await this.renderComponent();
136-
later(() => cancelTimers(), 50);
137-
await settled();
138-
const [actual] = authenticateStub.lastCall.args;
139-
assert.propEqual(
140-
actual,
141-
{
142-
backend: 'token',
143-
clusterId: '1',
144-
data: {
145-
token: '12345',
146-
},
147-
selectedAuth: 'token',
148-
},
149-
`it calls auth service authenticate method with correct args: ${JSON.stringify(actual)} `
150-
);
151-
});
152-
153-
test('it should set nonce value as uuid for okta method type', async function (assert) {
154-
assert.expect(4);
155-
this.server.post('/auth/okta/login/foo', (_, req) => {
156-
const { nonce } = JSON.parse(req.requestBody);
157-
assert.true(validate(nonce), 'Nonce value passed as uuid for okta login');
158-
return {
159-
auth: {
160-
client_token: '12345',
161-
policies: ['default'],
162-
},
163-
};
164-
});
165-
166-
await this.renderComponent();
167-
168-
await fillIn(GENERAL.selectByAttr('auth-method'), 'okta');
169-
await fillIn(AUTH_FORM.input('username'), 'foo');
170-
await fillIn(AUTH_FORM.input('password'), 'bar');
171-
await click(AUTH_FORM.login);
172-
assert
173-
.dom('[data-test-okta-number-challenge]')
49+
.dom(AUTH_FORM.helpText)
17450
.hasText(
17551
'Once you log in, you will be redirected back to your application. If you require login credentials, contact your administrator.'
17652
);

0 commit comments

Comments
 (0)