* refactor: 💡 auth-method, account, & managed abilities & routes * refactor: 💡 credential store resources abilities & routes * refactor: 💡 group abilities & routes * refactor: 💡 host-catalog resources abilities & routes * refactor: 💡 role abilities & routes * test: 💍 fix route-info-test * test: 💍 fix host serializer tests * test: 💍 fix create-test for host-sets * refactor: 💡 session recording resources abilities & routes * refactor: 💡 storage bucket abilities & routes * refactor: 💡 target abilities & routes * refactor: 💡 user abilities & routes * refactor: 💡 worker abilities & routes * refactor: 💡 remove ability changes and add comments * Update ui/admin/app/utils/route-info.js Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> * test: 💍 add test cases and rename util file * refactor: 💡 remove dup file and update imports ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-11282 * docs: ✏️ update comments & remove console.log ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-11282 * Update ui/admin/app/routes/scopes/scope/auth-methods/auth-method.js Co-authored-by: Dharini Jeeva <dharini@hashicorp.com> --------- Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>
146 lines
4.7 KiB
JavaScript
146 lines
4.7 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import {
|
|
visit,
|
|
currentURL,
|
|
click,
|
|
// fillIn,
|
|
find,
|
|
// findAll,
|
|
} from '@ember/test-helpers';
|
|
import { setupApplicationTest } from 'ember-qunit';
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
|
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
|
//import { Response } from 'miragejs';
|
|
import {
|
|
authenticateSession,
|
|
// These are left here intentionally for future reference.
|
|
//currentSession,
|
|
//invalidateSession,
|
|
} from 'ember-simple-auth/test-support';
|
|
|
|
import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method';
|
|
|
|
module('Acceptance | auth-methods | oidc', function (hooks) {
|
|
setupApplicationTest(hooks);
|
|
setupMirage(hooks);
|
|
|
|
const instances = {
|
|
scopes: {
|
|
global: null,
|
|
org: null,
|
|
},
|
|
authMethod: null,
|
|
};
|
|
const urls = {
|
|
orgScope: null,
|
|
authMethods: null,
|
|
authMethod: null,
|
|
};
|
|
|
|
hooks.beforeEach(function () {
|
|
authenticateSession({});
|
|
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
|
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) {
|
|
assert.expect(1);
|
|
await visit(urls.authMethod);
|
|
await a11yAudit();
|
|
assert.strictEqual(currentURL(), urls.authMethod);
|
|
});
|
|
|
|
test('can view oidc state', async function (assert) {
|
|
assert.expect(1);
|
|
await visit(urls.authMethod);
|
|
await click('.rose-layout-page-actions .rose-dropdown-trigger');
|
|
assert.strictEqual(
|
|
find('.rose-dropdown[open] input:checked').value,
|
|
instances.authMethod.attributes.state
|
|
);
|
|
});
|
|
|
|
test('can update oidc state', async function (assert) {
|
|
assert.expect(1);
|
|
const updateValue = 'inactive';
|
|
await visit(urls.authMethod);
|
|
await click('.rose-layout-page-actions .rose-dropdown-trigger');
|
|
await click(`.rose-dropdown[open] input[value="${updateValue}"]`);
|
|
const authMethod = this.server.db.authMethods.find(instances.authMethod.id);
|
|
assert.strictEqual(authMethod.attributes.state, updateValue);
|
|
});
|
|
|
|
test('can update oidc state to active-private', async function (assert) {
|
|
assert.expect(1);
|
|
const updateValue = 'active-private';
|
|
await visit(urls.authMethod);
|
|
await click('.rose-layout-page-actions .rose-dropdown-trigger');
|
|
await click(`.rose-dropdown[open] input[value="${updateValue}"]`);
|
|
const authMethod = this.server.db.authMethods.find(instances.authMethod.id);
|
|
assert.strictEqual(authMethod.attributes.state, updateValue);
|
|
});
|
|
|
|
test('can update oidc state to active-public', async function (assert) {
|
|
assert.expect(1);
|
|
// Update default 'active-public' state to inactive
|
|
instances.authMethod.attributes.state = 'inactive';
|
|
const updateValue = 'active-public';
|
|
await visit(urls.authMethod);
|
|
await click('.rose-layout-page-actions .rose-dropdown-trigger');
|
|
await click(`.rose-dropdown[open] input[value="${updateValue}"]`);
|
|
const authMethod = this.server.db.authMethods.find(instances.authMethod.id);
|
|
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) {
|
|
assert.expect(2);
|
|
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('.rose-layout-page-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.ok(
|
|
find('.rose-notification-body').textContent.trim(),
|
|
'Sorry!',
|
|
'Displays error message.'
|
|
);
|
|
});
|
|
});
|