Files
threshold-ui/addons/api/tests/unit/abilities/auth-method-test.js
T
Lisbet Alvarez 3ba93927fe Update copyright headers (#3146)
* empty commit

* Add missing copyright headers

* chore: 🤖 update copywrite config file with correct year

* Add missing copyright headers

* empty commit (gh action merge checks are stuck)
2026-01-28 17:09:06 -08:00

109 lines
4.2 KiB
JavaScript

/**
* 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_PASSWORD,
TYPE_AUTH_METHOD_OIDC,
TYPE_AUTH_METHOD_LDAP,
} from 'api/models/auth-method';
module('Unit | Abilities | Auth Method', function (hooks) {
setupTest(hooks);
let canService;
let store;
hooks.beforeEach(function () {
canService = this.owner.lookup('service:can');
store = this.owner.lookup('service:store');
});
test('can read known auth method types when authorized', function (assert) {
const authMethod = store.createRecord('auth-method', {
authorized_actions: ['read'],
type: TYPE_AUTH_METHOD_OIDC,
});
assert.true(canService.can('read auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
assert.true(canService.can('read auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_LDAP;
assert.true(canService.can('read auth-method', authMethod));
authMethod.type = 'no-such-type';
assert.false(canService.can('read auth-method', authMethod));
});
test('cannot read auth methods when unauthorized', function (assert) {
const authMethod = store.createRecord('auth-method', {
authorized_actions: [],
type: TYPE_AUTH_METHOD_OIDC,
});
assert.false(canService.can('read auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
assert.false(canService.can('read auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_LDAP;
assert.false(canService.can('read auth-method', authMethod));
authMethod.type = 'no-such-type';
assert.false(canService.can('read auth-method', authMethod));
});
test('can delete known auth method types when authorized', function (assert) {
const authMethod = store.createRecord('auth-method', {
authorized_actions: ['delete'],
type: TYPE_AUTH_METHOD_OIDC,
});
assert.true(canService.can('delete auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
assert.true(canService.can('delete auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_LDAP;
assert.true(canService.can('delete auth-method', authMethod));
authMethod.type = 'no-such-type';
assert.false(canService.can('delete auth-method', authMethod));
});
test('cannot delete auth methods when unauthorized', function (assert) {
const authMethod = store.createRecord('auth-method', {
authorized_actions: ['delete'],
type: TYPE_AUTH_METHOD_OIDC,
});
assert.true(canService.can('delete auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
assert.true(canService.can('delete auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_LDAP;
assert.true(canService.can('delete auth-method', authMethod));
authMethod.type = 'no-such-type';
assert.false(canService.can('delete auth-method', authMethod));
});
test('can update known auth method types when authorized', function (assert) {
const authMethod = store.createRecord('auth-method', {
authorized_actions: ['update'],
type: TYPE_AUTH_METHOD_OIDC,
});
assert.true(canService.can('update auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
assert.true(canService.can('update auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_LDAP;
assert.true(canService.can('update auth-method', authMethod));
authMethod.type = 'no-such-type';
assert.false(canService.can('update auth-method', authMethod));
});
test('cannot update auth methods when unauthorized', function (assert) {
const authMethod = store.createRecord('auth-method', {
authorized_actions: [],
type: TYPE_AUTH_METHOD_OIDC,
});
assert.false(canService.can('update auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
assert.false(canService.can('update auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_LDAP;
assert.false(canService.can('update auth-method', authMethod));
authMethod.type = 'no-such-type';
assert.false(canService.can('update auth-method', authMethod));
});
});