mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 02:57:59 +00:00
UI: address flaky auth-jwt and control group tests (#28297)
* address flaky auth-jwt test * refactor control group success test
This commit is contained in:
@@ -6,16 +6,17 @@
|
||||
import { _cancelTimers as cancelTimers } from '@ember/runloop';
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'ember-qunit';
|
||||
import { render, settled, waitUntil } from '@ember/test-helpers';
|
||||
import { fillIn, render, settled, waitUntil } from '@ember/test-helpers';
|
||||
import hbs from 'htmlbars-inline-precompile';
|
||||
import sinon from 'sinon';
|
||||
import { resolve } from 'rsvp';
|
||||
import { create } from 'ember-cli-page-object';
|
||||
import form from '../../pages/components/auth-jwt';
|
||||
import { ERROR_WINDOW_CLOSED, ERROR_MISSING_PARAMS, ERROR_JWT_LOGIN } from 'vault/components/auth-jwt';
|
||||
import { fakeWindow, buildMessage } from '../../helpers/oidc-window-stub';
|
||||
import { fakeWindow, buildMessage } from 'vault/tests/helpers/oidc-window-stub';
|
||||
import { setupMirage } from 'ember-cli-mirage/test-support';
|
||||
import { overrideResponse } from 'vault/tests/helpers/stubs';
|
||||
import { AUTH_FORM } from 'vault/tests/helpers/auth/auth-form-selectors';
|
||||
|
||||
const component = create(form);
|
||||
const windows = [];
|
||||
@@ -33,12 +34,6 @@ fakeWindow.reopen({
|
||||
},
|
||||
});
|
||||
|
||||
const OIDC_AUTH_RESPONSE = {
|
||||
auth: {
|
||||
client_token: 'token',
|
||||
},
|
||||
};
|
||||
|
||||
const renderIt = async (context, path = 'jwt') => {
|
||||
const handler = (data, e) => {
|
||||
if (e && e.preventDefault) e.preventDefault();
|
||||
@@ -75,11 +70,11 @@ module('Integration | Component | auth jwt', function (hooks) {
|
||||
},
|
||||
});
|
||||
this.server.get('/auth/:path/oidc/callback', function () {
|
||||
return OIDC_AUTH_RESPONSE;
|
||||
return { auth: { client_token: 'token' } };
|
||||
});
|
||||
this.server.post('/auth/:path/oidc/auth_url', (_, request) => {
|
||||
const { role } = JSON.parse(request.requestBody);
|
||||
if (['test', 'bar'].includes(role)) {
|
||||
if (['okta', 'test', 'bar'].includes(role)) {
|
||||
const auth_url = role === 'test' ? 'http://example.com' : role === 'okta' ? 'http://okta.com' : '';
|
||||
return {
|
||||
data: { auth_url },
|
||||
@@ -127,35 +122,46 @@ module('Integration | Component | auth jwt', function (hooks) {
|
||||
});
|
||||
|
||||
test('oidc: test role: it renders', async function (assert) {
|
||||
// setting the path also fires off a request to auth_url but this happens inconsistently in tests
|
||||
// setting here so it doesn't affect the postCount because it's not relevant to what's being tested
|
||||
this.set('selectedAuthPath', 'foo');
|
||||
let postCount = 0;
|
||||
this.server.post('/auth/:path/oidc/auth_url', (_, request) => {
|
||||
postCount++;
|
||||
const { role } = JSON.parse(request.requestBody);
|
||||
if (['test', 'okta', 'bar'].includes(role)) {
|
||||
const auth_url = role === 'test' ? 'http://example.com' : role === 'okta' ? 'http://okta.com' : '';
|
||||
return {
|
||||
data: { auth_url },
|
||||
};
|
||||
}
|
||||
const errors = role === 'foo' ? ['role "foo" could not be found'] : [ERROR_JWT_LOGIN];
|
||||
return overrideResponse(400, { errors });
|
||||
const auth_url = role === 'test' ? 'http://example.com' : role === 'okta' ? 'http://okta.com' : '';
|
||||
return {
|
||||
data: { auth_url },
|
||||
};
|
||||
});
|
||||
await renderIt(this);
|
||||
await settled();
|
||||
this.set('selectedAuthPath', 'foo');
|
||||
await component.role('test');
|
||||
await settled();
|
||||
assert.notOk(component.jwtPresent, 'does not show jwt input for OIDC type login');
|
||||
assert.strictEqual(component.loginButtonText, 'Sign in with OIDC Provider');
|
||||
|
||||
await component.role('okta');
|
||||
await fillIn(AUTH_FORM.roleInput, 'test');
|
||||
assert
|
||||
.dom(AUTH_FORM.input('jwt'))
|
||||
.doesNotExist('does not show jwt token input if role matches OIDC login url');
|
||||
assert.dom(AUTH_FORM.login).hasText('Sign in with OIDC Provider');
|
||||
await fillIn(AUTH_FORM.roleInput, 'okta');
|
||||
// 1 for initial render, 1 for each time role changed = 3
|
||||
assert.strictEqual(postCount, 3, 'fetches the auth_url when the path changes');
|
||||
assert.strictEqual(
|
||||
component.loginButtonText,
|
||||
'Sign in with Okta',
|
||||
'recognizes auth methods with certain urls'
|
||||
);
|
||||
assert.strictEqual(postCount, 3, 'fetches the auth_url when the role changes');
|
||||
assert.dom(AUTH_FORM.login).hasText('Sign in with Okta', 'recognizes auth methods with certain urls');
|
||||
});
|
||||
|
||||
test('oidc: it fetches auth_url when path changes', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.set('selectedAuthPath', 'foo');
|
||||
await renderIt(this);
|
||||
// auth_url is requested on initial render so stubbing after rendering the component
|
||||
// to test auth_url is called when the :path changes
|
||||
this.server.post('/auth/:path/oidc/auth_url', (_, request) => {
|
||||
assert.true(true, 'request is made to auth_url');
|
||||
assert.strictEqual(request?.params?.path, 'foo', 'request params are { path: foo }');
|
||||
return {
|
||||
data: { auth_url: '' },
|
||||
};
|
||||
});
|
||||
this.set('selectedAuthPath', 'foo');
|
||||
await settled();
|
||||
});
|
||||
|
||||
test('oidc: it calls window.open popup window on login', async function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user