2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-01 09:39:41 -06:00
|
|
|
*/
|
|
|
|
|
|
2021-06-01 22:29:19 -04:00
|
|
|
import { module, test } from 'qunit';
|
2025-03-13 08:39:11 -07:00
|
|
|
import { visit, currentURL, click } from '@ember/test-helpers';
|
2024-12-02 12:51:24 -06:00
|
|
|
import { setupApplicationTest } from 'admin/tests/helpers';
|
2023-05-11 15:15:31 -07:00
|
|
|
import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method';
|
2025-02-13 15:54:40 -05:00
|
|
|
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
2025-03-13 08:39:11 -07:00
|
|
|
import * as selectors from './selectors';
|
2024-11-19 13:03:29 -08:00
|
|
|
|
2023-11-02 16:08:25 -07:00
|
|
|
module('Acceptance | auth-methods | oidc', function (hooks) {
|
2021-06-01 22:29:19 -04:00
|
|
|
setupApplicationTest(hooks);
|
|
|
|
|
|
|
|
|
|
const instances = {
|
|
|
|
|
scopes: {
|
|
|
|
|
org: null,
|
|
|
|
|
},
|
|
|
|
|
authMethod: null,
|
|
|
|
|
};
|
|
|
|
|
const urls = {
|
|
|
|
|
orgScope: null,
|
|
|
|
|
authMethods: null,
|
|
|
|
|
authMethod: null,
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-03 10:27:27 -08:00
|
|
|
hooks.beforeEach(async function () {
|
2021-06-01 22:29:19 -04:00
|
|
|
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,
|
2023-05-11 15:15:31 -07:00
|
|
|
type: TYPE_AUTH_METHOD_OIDC,
|
2021-06-01 22:29:19 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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);
|
2025-03-13 08:39:11 -07:00
|
|
|
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(currentURL(), urls.authMethod);
|
2021-06-01 22:29:19 -04:00
|
|
|
});
|
|
|
|
|
|
2021-06-02 14:03:53 -04:00
|
|
|
test('can view oidc state', async function (assert) {
|
2021-06-01 22:29:19 -04:00
|
|
|
await visit(urls.authMethod);
|
2025-03-13 08:39:11 -07:00
|
|
|
|
|
|
|
|
await click(selectors.CHANGE_STATE_DROPDOWN);
|
|
|
|
|
|
|
|
|
|
assert
|
|
|
|
|
.dom(selectors.CHANGE_STATE_DROPDOWN_CHECKED)
|
|
|
|
|
.hasValue(instances.authMethod.attributes.state);
|
2021-06-01 22:29:19 -04:00
|
|
|
});
|
|
|
|
|
|
2021-06-02 14:03:53 -04:00
|
|
|
test('can update oidc state', async function (assert) {
|
2021-06-01 22:29:19 -04:00
|
|
|
const updateValue = 'inactive';
|
|
|
|
|
await visit(urls.authMethod);
|
2025-03-13 08:39:11 -07:00
|
|
|
|
|
|
|
|
await click(selectors.CHANGE_STATE_DROPDOWN);
|
|
|
|
|
await click(selectors.CHANGE_STATE_DROPDOWN_STATE(updateValue));
|
|
|
|
|
|
2024-11-19 13:03:29 -08:00
|
|
|
const authMethod = this.server.schema.authMethods.findBy({
|
|
|
|
|
id: instances.authMethod.id,
|
|
|
|
|
});
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(authMethod.attributes.state, updateValue);
|
2021-06-01 22:29:19 -04:00
|
|
|
});
|
|
|
|
|
|
2021-06-02 14:03:53 -04:00
|
|
|
test('can update oidc state to active-private', async function (assert) {
|
2021-06-01 22:29:19 -04:00
|
|
|
const updateValue = 'active-private';
|
|
|
|
|
await visit(urls.authMethod);
|
2025-03-13 08:39:11 -07:00
|
|
|
|
|
|
|
|
await click(selectors.CHANGE_STATE_DROPDOWN);
|
|
|
|
|
await click(selectors.CHANGE_STATE_DROPDOWN_STATE(updateValue));
|
|
|
|
|
|
2024-11-19 13:03:29 -08:00
|
|
|
const authMethod = this.server.schema.authMethods.findBy({
|
|
|
|
|
id: instances.authMethod.id,
|
|
|
|
|
});
|
2025-03-13 08:39:11 -07:00
|
|
|
|
|
|
|
|
assert
|
|
|
|
|
.dom(selectors.CHANGE_STATE_DROPDOWN_CHECKED)
|
|
|
|
|
.hasValue(instances.authMethod.attributes.state);
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(authMethod.attributes.state, updateValue);
|
2021-06-01 22:29:19 -04:00
|
|
|
});
|
|
|
|
|
|
2021-06-02 14:03:53 -04:00
|
|
|
test('can update oidc state to active-public', async function (assert) {
|
2021-06-01 22:29:19 -04:00
|
|
|
instances.authMethod.attributes.state = 'inactive';
|
|
|
|
|
const updateValue = 'active-public';
|
|
|
|
|
await visit(urls.authMethod);
|
2025-03-13 08:39:11 -07:00
|
|
|
|
|
|
|
|
await click(selectors.CHANGE_STATE_DROPDOWN);
|
|
|
|
|
await click(selectors.CHANGE_STATE_DROPDOWN_STATE(updateValue));
|
|
|
|
|
|
2024-11-19 13:03:29 -08:00
|
|
|
const authMethod = this.server.schema.authMethods.findBy({
|
|
|
|
|
id: instances.authMethod.id,
|
|
|
|
|
});
|
|
|
|
|
|
2025-03-13 08:39:11 -07:00
|
|
|
assert
|
|
|
|
|
.dom(selectors.CHANGE_STATE_DROPDOWN_CHECKED)
|
|
|
|
|
.hasValue(instances.authMethod.attributes.state);
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(authMethod.attributes.state, updateValue);
|
2021-06-01 22:29:19 -04:00
|
|
|
});
|
|
|
|
|
|
2021-06-02 22:44:40 -04:00
|
|
|
// FIXME: How to mock just one request routed to /auth-methods and let everything else passthrough?
|
2021-10-23 11:48:10 -04:00
|
|
|
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!',
|
2023-11-22 14:07:41 -05:00
|
|
|
},
|
2021-10-23 11:48:10 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return request;
|
|
|
|
|
});
|
|
|
|
|
const newState = 'inactive';
|
|
|
|
|
await visit(urls.authMethod);
|
2025-06-02 16:20:50 -05:00
|
|
|
await click('.hds-page-header__actions .rose-dropdown-trigger');
|
2021-10-23 11:48:10 -04:00
|
|
|
await click(`.rose-dropdown[open] input[value="${newState}"]`);
|
|
|
|
|
const authMethod = this.server.db.authMethods.find(instances.authMethod.id);
|
|
|
|
|
assert.notEqual(
|
|
|
|
|
newState,
|
|
|
|
|
authMethod.attributes.state,
|
2023-11-22 14:07:41 -05:00
|
|
|
'Auth method state is not be updated.',
|
2021-10-23 11:48:10 -04:00
|
|
|
);
|
2025-02-13 15:54:40 -05:00
|
|
|
assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText('Sorry!');
|
2021-10-23 11:48:10 -04:00
|
|
|
});
|
2021-06-01 22:29:19 -04:00
|
|
|
});
|