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-08-16 13:31:28 -07:00
|
|
|
import { module, test } from 'qunit';
|
2023-07-27 14:25:40 -07:00
|
|
|
import { visit, click, currentURL } from '@ember/test-helpers';
|
2024-12-02 12:51:24 -06:00
|
|
|
import { setupApplicationTest } from 'admin/tests/helpers';
|
2021-08-16 13:31:28 -07:00
|
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
2024-04-12 10:31:32 -07:00
|
|
|
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
2021-08-16 13:31:28 -07:00
|
|
|
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
|
|
|
|
import { Response } from 'miragejs';
|
2024-11-22 11:27:53 -08:00
|
|
|
import { authenticateSession } from 'ember-simple-auth/test-support';
|
2023-07-27 14:25:40 -07:00
|
|
|
import { TYPE_AUTH_METHOD_LDAP } from 'api/models/auth-method';
|
2021-08-16 13:31:28 -07:00
|
|
|
|
2023-11-02 16:08:25 -07:00
|
|
|
module('Acceptance | auth-methods | delete', function (hooks) {
|
2021-08-16 13:31:28 -07:00
|
|
|
setupApplicationTest(hooks);
|
|
|
|
|
setupMirage(hooks);
|
2024-04-12 10:31:32 -07:00
|
|
|
setupIndexedDb(hooks);
|
2021-08-16 13:31:28 -07:00
|
|
|
|
2023-07-27 14:25:40 -07:00
|
|
|
let featuresService;
|
|
|
|
|
let getAuthMethodCount;
|
|
|
|
|
|
|
|
|
|
const DIALOG_DELETE_BTN_SELECTOR = '.rose-dialog .rose-button-primary';
|
|
|
|
|
const DIALOG_CANCEL_BTN_SELECTOR = '.rose-dialog .rose-button-secondary';
|
2024-11-19 15:18:18 -08:00
|
|
|
const ERROR_MSG_SELECTOR =
|
|
|
|
|
'[data-test-toast-notification] .hds-alert__description';
|
2023-07-27 14:25:40 -07:00
|
|
|
|
2024-08-26 15:30:57 -04:00
|
|
|
const MANAGE_DROPDOWN_SELECTOR =
|
2024-11-04 12:29:56 -05:00
|
|
|
'[data-test-manage-auth-method] button:first-child';
|
2024-08-26 15:30:57 -04:00
|
|
|
const DELETE_ACTION_SELECTOR =
|
2024-10-25 15:58:09 -05:00
|
|
|
'[data-test-manage-auth-method] ul li:last-child button';
|
2024-08-26 15:30:57 -04:00
|
|
|
|
2021-08-16 13:31:28 -07:00
|
|
|
const instances = {
|
|
|
|
|
scopes: {
|
|
|
|
|
global: null,
|
|
|
|
|
org: null,
|
|
|
|
|
},
|
|
|
|
|
authMethod: null,
|
2023-07-27 14:25:40 -07:00
|
|
|
ldapAuthMethod: null,
|
2021-08-16 13:31:28 -07:00
|
|
|
};
|
|
|
|
|
const urls = {
|
|
|
|
|
orgScope: null,
|
|
|
|
|
authMethods: null,
|
|
|
|
|
authMethod: null,
|
2023-07-27 14:25:40 -07:00
|
|
|
ldapAuthMethod: null,
|
2021-08-16 13:31:28 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
hooks.beforeEach(function () {
|
|
|
|
|
// Setup Mirage mock resources for this test
|
2024-09-04 13:04:14 -07:00
|
|
|
authenticateSession({ username: 'admin' });
|
2021-08-16 13:31:28 -07:00
|
|
|
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,
|
|
|
|
|
});
|
2023-07-27 14:25:40 -07:00
|
|
|
instances.ldapAuthMethod = this.server.create('auth-method', {
|
|
|
|
|
scope: instances.scopes.org,
|
|
|
|
|
type: TYPE_AUTH_METHOD_LDAP,
|
|
|
|
|
});
|
2021-08-16 13:31:28 -07:00
|
|
|
|
|
|
|
|
// 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}`;
|
2023-07-27 14:25:40 -07:00
|
|
|
urls.ldapAuthMethod = `${urls.authMethods}/${instances.ldapAuthMethod.id}`;
|
|
|
|
|
featuresService = this.owner.lookup('service:features');
|
|
|
|
|
getAuthMethodCount = () =>
|
|
|
|
|
this.server.schema.authMethods.all().models.length;
|
2021-08-16 13:31:28 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('can delete an auth method', async function (assert) {
|
2023-07-27 14:25:40 -07:00
|
|
|
const authMethodsCount = getAuthMethodCount();
|
|
|
|
|
await visit(urls.authMethods);
|
|
|
|
|
|
|
|
|
|
await click(`[href="${urls.authMethod}"]`);
|
2024-08-26 15:30:57 -04:00
|
|
|
await click(MANAGE_DROPDOWN_SELECTOR);
|
|
|
|
|
await click(DELETE_ACTION_SELECTOR);
|
2023-07-27 14:25:40 -07:00
|
|
|
|
|
|
|
|
assert.strictEqual(getAuthMethodCount(), authMethodsCount - 1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('can delete an ldap auth method', async function (assert) {
|
|
|
|
|
featuresService.enable('ldap-auth-methods');
|
|
|
|
|
const authMethodsCount = getAuthMethodCount();
|
|
|
|
|
await visit(urls.authMethods);
|
|
|
|
|
|
|
|
|
|
await click(`[href="${urls.ldapAuthMethod}"]`);
|
2024-08-26 15:30:57 -04:00
|
|
|
await click(MANAGE_DROPDOWN_SELECTOR);
|
|
|
|
|
await click(DELETE_ACTION_SELECTOR);
|
2023-07-27 14:25:40 -07:00
|
|
|
|
|
|
|
|
assert.strictEqual(getAuthMethodCount(), authMethodsCount - 1);
|
2021-08-16 13:31:28 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('errors are displayed when delete on an auth method fails', async function (assert) {
|
|
|
|
|
this.server.del('/auth-methods/:id', () => {
|
|
|
|
|
return new Response(
|
|
|
|
|
490,
|
|
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
status: 490,
|
|
|
|
|
code: 'error',
|
|
|
|
|
message: 'Oops.',
|
2023-11-22 14:07:41 -05:00
|
|
|
},
|
2021-08-16 13:31:28 -07:00
|
|
|
);
|
|
|
|
|
});
|
2023-07-27 14:25:40 -07:00
|
|
|
await visit(urls.authMethods);
|
|
|
|
|
|
|
|
|
|
await click(`[href="${urls.authMethod}"]`);
|
2024-08-26 15:30:57 -04:00
|
|
|
await click(MANAGE_DROPDOWN_SELECTOR);
|
|
|
|
|
await click(DELETE_ACTION_SELECTOR);
|
2021-08-16 13:31:28 -07:00
|
|
|
await a11yAudit();
|
2023-07-27 14:25:40 -07:00
|
|
|
|
|
|
|
|
assert.dom(ERROR_MSG_SELECTOR).hasText('Oops.');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('errors are displayed when delete on an ldap auth method fails', async function (assert) {
|
|
|
|
|
featuresService.enable('ldap-auth-methods');
|
|
|
|
|
this.server.del('/auth-methods/:id', () => {
|
|
|
|
|
return new Response(
|
|
|
|
|
490,
|
|
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
status: 490,
|
|
|
|
|
code: 'error',
|
|
|
|
|
message: 'Oops.',
|
2023-11-22 14:07:41 -05:00
|
|
|
},
|
2023-07-27 14:25:40 -07:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
await visit(urls.authMethods);
|
|
|
|
|
|
|
|
|
|
await click(`[href="${urls.ldapAuthMethod}"]`);
|
2024-08-26 15:30:57 -04:00
|
|
|
await click(MANAGE_DROPDOWN_SELECTOR);
|
|
|
|
|
await click(DELETE_ACTION_SELECTOR);
|
2023-07-27 14:25:40 -07:00
|
|
|
await a11yAudit();
|
|
|
|
|
|
|
|
|
|
assert.dom(ERROR_MSG_SELECTOR).hasText('Oops.');
|
2021-08-16 13:31:28 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cannot delete an auth method without proper authorization', async function (assert) {
|
|
|
|
|
instances.authMethod.authorized_actions =
|
|
|
|
|
instances.authMethod.authorized_actions.filter(
|
2023-11-22 14:07:41 -05:00
|
|
|
(item) => item !== 'delete',
|
2021-08-16 13:31:28 -07:00
|
|
|
);
|
2023-07-27 14:25:40 -07:00
|
|
|
await visit(urls.authMethods);
|
|
|
|
|
|
|
|
|
|
await click(`[href="${urls.authMethod}"]`);
|
2024-08-26 15:30:57 -04:00
|
|
|
await click(MANAGE_DROPDOWN_SELECTOR);
|
2023-07-27 14:25:40 -07:00
|
|
|
|
2024-08-26 15:30:57 -04:00
|
|
|
assert.dom(DELETE_ACTION_SELECTOR).doesNotExist();
|
2023-07-27 14:25:40 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cannot delete an ldap auth method without proper authorization', async function (assert) {
|
|
|
|
|
featuresService.enable('ldap-auth-methods');
|
|
|
|
|
instances.ldapAuthMethod.authorized_actions =
|
|
|
|
|
instances.ldapAuthMethod.authorized_actions.filter(
|
2023-11-22 14:07:41 -05:00
|
|
|
(item) => item !== 'delete',
|
2023-07-27 14:25:40 -07:00
|
|
|
);
|
|
|
|
|
await visit(urls.authMethods);
|
|
|
|
|
|
|
|
|
|
await click(`[href="${urls.ldapAuthMethod}"]`);
|
2024-08-26 15:30:57 -04:00
|
|
|
await click(MANAGE_DROPDOWN_SELECTOR);
|
2023-07-27 14:25:40 -07:00
|
|
|
|
2024-08-26 15:30:57 -04:00
|
|
|
assert.dom(DELETE_ACTION_SELECTOR).doesNotExist();
|
2023-07-27 14:25:40 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('user can accept delete auth method via dialog', async function (assert) {
|
|
|
|
|
const confirmService = this.owner.lookup('service:confirm');
|
|
|
|
|
confirmService.enabled = true;
|
|
|
|
|
const authMethodCount = getAuthMethodCount();
|
|
|
|
|
await visit(urls.authMethods);
|
|
|
|
|
|
|
|
|
|
await click(`[href="${urls.authMethod}"]`);
|
2024-08-26 15:30:57 -04:00
|
|
|
await click(MANAGE_DROPDOWN_SELECTOR);
|
|
|
|
|
await click(DELETE_ACTION_SELECTOR);
|
2023-07-27 14:25:40 -07:00
|
|
|
await click(DIALOG_DELETE_BTN_SELECTOR);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(currentURL(), urls.authMethods);
|
|
|
|
|
assert.strictEqual(getAuthMethodCount(), authMethodCount - 1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('user can accept delete ldap auth method via dialog', async function (assert) {
|
|
|
|
|
const confirmService = this.owner.lookup('service:confirm');
|
|
|
|
|
confirmService.enabled = true;
|
|
|
|
|
featuresService.enable('ldap-auth-methods');
|
|
|
|
|
const authMethodCount = getAuthMethodCount();
|
|
|
|
|
await visit(urls.authMethods);
|
|
|
|
|
|
|
|
|
|
await click(`[href="${urls.ldapAuthMethod}"]`);
|
2024-08-26 15:30:57 -04:00
|
|
|
await click(MANAGE_DROPDOWN_SELECTOR);
|
|
|
|
|
await click(DELETE_ACTION_SELECTOR);
|
2023-07-27 14:25:40 -07:00
|
|
|
await click(DIALOG_DELETE_BTN_SELECTOR);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(currentURL(), urls.authMethods);
|
|
|
|
|
assert.strictEqual(getAuthMethodCount(), authMethodCount - 1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('user can cancel delete auth method via dialog', async function (assert) {
|
|
|
|
|
const confirmService = this.owner.lookup('service:confirm');
|
|
|
|
|
confirmService.enabled = true;
|
|
|
|
|
const authMethodCount = getAuthMethodCount();
|
|
|
|
|
await visit(urls.authMethods);
|
|
|
|
|
|
|
|
|
|
await click(`[href="${urls.authMethod}"]`);
|
2024-08-26 15:30:57 -04:00
|
|
|
await click(MANAGE_DROPDOWN_SELECTOR);
|
|
|
|
|
await click(DELETE_ACTION_SELECTOR);
|
2023-07-27 14:25:40 -07:00
|
|
|
await click(DIALOG_CANCEL_BTN_SELECTOR);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(currentURL(), urls.authMethod);
|
|
|
|
|
assert.strictEqual(getAuthMethodCount(), authMethodCount);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('user can cancel delete ldap auth method via dialog', async function (assert) {
|
|
|
|
|
const confirmService = this.owner.lookup('service:confirm');
|
|
|
|
|
confirmService.enabled = true;
|
|
|
|
|
featuresService.enable('ldap-auth-methods');
|
|
|
|
|
const authMethodCount = getAuthMethodCount();
|
|
|
|
|
await visit(urls.authMethods);
|
|
|
|
|
|
|
|
|
|
await click(`[href="${urls.ldapAuthMethod}"]`);
|
2024-08-26 15:30:57 -04:00
|
|
|
await click(MANAGE_DROPDOWN_SELECTOR);
|
|
|
|
|
await click(DELETE_ACTION_SELECTOR);
|
2023-07-27 14:25:40 -07:00
|
|
|
await click(DIALOG_CANCEL_BTN_SELECTOR);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(currentURL(), urls.ldapAuthMethod);
|
|
|
|
|
assert.strictEqual(getAuthMethodCount(), authMethodCount);
|
2021-08-16 13:31:28 -07:00
|
|
|
});
|
|
|
|
|
});
|