Files
threshold-ui/ui/admin/tests/unit/abilities/auth-method-test.js
T

91 lines
3.3 KiB
JavaScript
Raw Normal View History

/**
2026-01-28 17:09:06 -08:00
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import {
TYPE_AUTH_METHOD_LDAP,
TYPE_AUTH_METHOD_OIDC,
TYPE_AUTH_METHOD_PASSWORD,
} from 'api/models/auth-method';
module('Unit | Abilities | auth-method', function (hooks) {
setupTest(hooks);
2026-02-24 13:48:34 -05:00
let abilitiesService;
let store;
let features;
hooks.beforeEach(function () {
2026-02-24 13:48:34 -05:00
abilitiesService = this.owner.lookup('service:abilities');
store = this.owner.lookup('service:store');
features = this.owner.lookup('service:features');
});
test('can read LDAP auth-method when authorized and feature flag enabled', function (assert) {
features.enable('ldap-auth-methods');
const authMethod = store.createRecord('auth-method', {
authorized_actions: ['read'],
type: TYPE_AUTH_METHOD_LDAP,
});
2026-02-24 13:48:34 -05:00
assert.true(abilitiesService.can('read auth-method', authMethod));
authMethod.authorized_actions = [];
2026-02-24 13:48:34 -05:00
assert.false(abilitiesService.can('read auth-method', authMethod));
});
test('cannot read LDAP auth-method when authorized and feature flag disabled', function (assert) {
const authMethod = store.createRecord('auth-method', {
authorized_actions: ['read'],
type: TYPE_AUTH_METHOD_LDAP,
});
2026-02-24 13:48:34 -05:00
assert.false(abilitiesService.can('read auth-method', authMethod));
authMethod.authorized_actions = [];
2026-02-24 13:48:34 -05:00
assert.false(abilitiesService.can('read auth-method', authMethod));
});
test('can read non-LDAP auth-method when authorized', function (assert) {
const authMethod = store.createRecord('auth-method', {
authorized_actions: ['read'],
type: TYPE_AUTH_METHOD_OIDC,
});
2026-02-24 13:48:34 -05:00
assert.true(abilitiesService.can('read auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
2026-02-24 13:48:34 -05:00
assert.true(abilitiesService.can('read auth-method', authMethod));
});
test('cannot read non-LDAP auth-method when unauthorized', function (assert) {
const authMethod = store.createRecord('auth-method', {
authorized_actions: [],
type: TYPE_AUTH_METHOD_OIDC,
});
2026-02-24 13:48:34 -05:00
assert.false(abilitiesService.can('read auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
2026-02-24 13:48:34 -05:00
assert.false(abilitiesService.can('read auth-method', authMethod));
});
test('cannot make LDAP auth-method primary when feature flag disabled', function (assert) {
const authMethod = store.createRecord('auth-method', {
type: TYPE_AUTH_METHOD_LDAP,
});
2026-02-24 13:48:34 -05:00
assert.false(abilitiesService.can('makePrimary auth-method', authMethod));
});
test('can make LDAP auth-method primary when feature flag enabled', function (assert) {
features.enable('ldap-auth-methods');
const authMethod = store.createRecord('auth-method', {
type: TYPE_AUTH_METHOD_LDAP,
});
2026-02-24 13:48:34 -05:00
assert.true(abilitiesService.can('makePrimary auth-method', authMethod));
});
test('can make non-LDAP auth-method primary', function (assert) {
const authMethod = store.createRecord('auth-method', {
type: TYPE_AUTH_METHOD_OIDC,
});
2026-02-24 13:48:34 -05:00
assert.true(abilitiesService.can('makePrimary auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
2026-02-24 13:48:34 -05:00
assert.true(abilitiesService.can('makePrimary auth-method', authMethod));
});
});