Files
threshold-ui/ui/admin/tests/acceptance/managed-groups/read-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

174 lines
5.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { visit, click, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'admin/tests/helpers';
import {
TYPE_AUTH_METHOD_OIDC,
TYPE_AUTH_METHOD_LDAP,
} from 'api/models/auth-method';
import * as commonSelectors from 'admin/tests/helpers/selectors';
import { setRunOptions } from 'ember-a11y-testing/test-support';
module('Acceptance | managed-groups | read', function (hooks) {
setupApplicationTest(hooks);
const instances = {
scopes: {
org: null,
},
authMethod: null,
ldapAuthMethod: null,
managedGroup: null,
ldapManagedGroup: null,
};
const urls = {
orgScope: null,
authMethods: null,
authMethod: null,
ldapAuthMethod: null,
managedGroups: null,
ldapManagedGroups: null,
managedGroup: null,
ldapManagedGroup: 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,
});
instances.ldapAuthMethod = this.server.create('auth-method', {
scope: instances.scopes.org,
type: TYPE_AUTH_METHOD_LDAP,
});
instances.managedGroup = this.server.create('managed-group', {
scope: instances.scopes.org,
authMethod: instances.authMethod,
});
instances.ldapManagedGroup = this.server.create('managed-group', {
scope: instances.scopes.org,
authMethod: instances.ldapAuthMethod,
});
// Generate route URLs for resources
urls.orgScope = `/scopes/${instances.scopes.org.id}`;
urls.authMethods = `${urls.orgScope}/auth-methods`;
urls.authMethod = `${urls.authMethods}/${instances.authMethod.id}`;
urls.ldapAuthMethod = `${urls.authMethods}/${instances.ldapAuthMethod.id}`;
urls.managedGroups = `${urls.authMethod}/managed-groups`;
urls.ldapManagedGroups = `${urls.ldapAuthMethod}/managed-groups`;
urls.managedGroup = `${urls.managedGroups}/${instances.managedGroup.id}`;
urls.ldapManagedGroup = `${urls.ldapManagedGroups}/${instances.ldapManagedGroup.id}`;
});
test('User can navigate to a managed group form', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
await visit(urls.managedGroups);
await click(commonSelectors.HREF(urls.managedGroup));
assert.strictEqual(currentURL(), urls.managedGroup);
});
test('User can navigate to a ldap managed group form', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
await visit(urls.ldapManagedGroups);
await click(commonSelectors.HREF(urls.ldapManagedGroup));
assert.strictEqual(currentURL(), urls.ldapManagedGroup);
});
test('User cannot navigate to a managed group form without proper authorization', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
instances.managedGroup.authorized_actions =
instances.managedGroup.authorized_actions.filter(
(item) => item !== 'read',
);
await visit(urls.authMethod);
await click(commonSelectors.HREF(urls.managedGroups));
assert.dom(commonSelectors.HREF(urls.managedGroup)).doesNotExist();
});
test('User cannot navigate to a ldap managed group form without proper authorization', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
instances.ldapManagedGroup.authorized_actions =
instances.ldapManagedGroup.authorized_actions.filter(
(item) => item !== 'read',
);
await visit(urls.ldapAuthMethod);
await click(commonSelectors.HREF(urls.ldapManagedGroups));
assert.dom(commonSelectors.HREF(urls.ldapManagedGroup)).doesNotExist();
});
test('User can navigate to managed group and incorrect url autocorrects', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
const authMethod = this.server.create('auth-method', {
scope: instances.scopes.org,
type: TYPE_AUTH_METHOD_LDAP,
});
const managedGroup = this.server.create('managed-group', {
scope: instances.scopes.org,
authMethod,
});
const incorrectUrl = `${urls.managedGroups}/${managedGroup.id}`;
const correctUrl = `${urls.orgScope}/auth-methods/${authMethod.id}/managed-groups/${managedGroup.id}`;
await visit(incorrectUrl);
assert.notEqual(currentURL(), incorrectUrl);
assert.strictEqual(currentURL(), correctUrl);
});
});