Files
threshold-ui/ui/admin/tests/acceptance/auth-methods/oidc-test.js
T
Lisbet Alvarez 72f7c8a92d fix: 🐛 OIDC authentications not properly showing username (#2930)
* fix: 🐛 properly show username for oidc auth method in user menu

* test: 💍 fix admin ui tests

* test: 💍 fix desktop ui tests

* refactor: 💡 admin to not store username in authenticated object

* refactor: 💡 use getter in app controller

* test: 💍 POC for how we could update our tests to use auth account

* refactor: 💡 remove unused service

* test: 💍 fix all tests in ui/admin

* test: 💍 revert one change

* refactor: 💡 update ui/desktop w/ feedback + fix tests

* refactor: 💡 add in error handling

* refactor: 💡 cleanup unused service

* test: 💍 fix e2e test selector

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-17231
2025-10-30 12:49:30 -07:00

137 lines
4.2 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { visit, currentURL, click } from '@ember/test-helpers';
import { setupApplicationTest } from 'admin/tests/helpers';
import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method';
import * as commonSelectors from 'admin/tests/helpers/selectors';
import * as selectors from './selectors';
module('Acceptance | auth-methods | oidc', function (hooks) {
setupApplicationTest(hooks);
const instances = {
scopes: {
org: null,
},
authMethod: null,
};
const urls = {
orgScope: null,
authMethods: null,
authMethod: null,
};
hooks.beforeEach(async function () {
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.authMethod = this.server.create('auth-method', {
scope: instances.scopes.org,
type: TYPE_AUTH_METHOD_OIDC,
});
urls.orgScope = `/scopes/${instances.scopes.org.id}`;
urls.authMethods = `${urls.orgScope}/auth-methods`;
urls.authMethod = `${urls.authMethods}/${instances.authMethod.id}`;
});
test('visiting oidc auth method', async function (assert) {
await visit(urls.authMethod);
assert.strictEqual(currentURL(), urls.authMethod);
});
test('can view oidc state', async function (assert) {
await visit(urls.authMethod);
await click(selectors.CHANGE_STATE_DROPDOWN);
assert
.dom(selectors.CHANGE_STATE_DROPDOWN_CHECKED)
.hasValue(instances.authMethod.attributes.state);
});
test('can update oidc state', async function (assert) {
const updateValue = 'inactive';
await visit(urls.authMethod);
await click(selectors.CHANGE_STATE_DROPDOWN);
await click(selectors.CHANGE_STATE_DROPDOWN_STATE(updateValue));
const authMethod = this.server.schema.authMethods.findBy({
id: instances.authMethod.id,
});
assert.strictEqual(authMethod.attributes.state, updateValue);
});
test('can update oidc state to active-private', async function (assert) {
const updateValue = 'active-private';
await visit(urls.authMethod);
await click(selectors.CHANGE_STATE_DROPDOWN);
await click(selectors.CHANGE_STATE_DROPDOWN_STATE(updateValue));
const authMethod = this.server.schema.authMethods.findBy({
id: instances.authMethod.id,
});
assert
.dom(selectors.CHANGE_STATE_DROPDOWN_CHECKED)
.hasValue(instances.authMethod.attributes.state);
assert.strictEqual(authMethod.attributes.state, updateValue);
});
test('can update oidc state to active-public', async function (assert) {
instances.authMethod.attributes.state = 'inactive';
const updateValue = 'active-public';
await visit(urls.authMethod);
await click(selectors.CHANGE_STATE_DROPDOWN);
await click(selectors.CHANGE_STATE_DROPDOWN_STATE(updateValue));
const authMethod = this.server.schema.authMethods.findBy({
id: instances.authMethod.id,
});
assert
.dom(selectors.CHANGE_STATE_DROPDOWN_CHECKED)
.hasValue(instances.authMethod.attributes.state);
assert.strictEqual(authMethod.attributes.state, updateValue);
});
// FIXME: How to mock just one request routed to /auth-methods and let everything else passthrough?
test.skip('errors are displayed when state update fails', async function (assert) {
this.server.post('/auth-methods/:idMethod', (_, request) => {
// Only respond to state update with error
if (request.params.idMethod.match(/(change-state)/i)) {
return new Response(
400,
{},
{
status: 400,
code: 'error',
message: 'Sorry!',
},
);
}
return request;
});
const newState = 'inactive';
await visit(urls.authMethod);
await click('.hds-page-header__actions .rose-dropdown-trigger');
await click(`.rose-dropdown[open] input[value="${newState}"]`);
const authMethod = this.server.db.authMethods.find(instances.authMethod.id);
assert.notEqual(
newState,
authMethod.attributes.state,
'Auth method state is not be updated.',
);
assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText('Sorry!');
});
});