2023-05-17 14:31:12 -07:00
|
|
|
/**
|
2026-01-28 17:09:06 -08:00
|
|
|
* Copyright IBM Corp. 2021, 2026
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-05-17 14:31:12 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
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 | Account', function (hooks) {
|
|
|
|
|
setupTest(hooks);
|
|
|
|
|
|
2026-02-24 13:48:34 -05:00
|
|
|
let abilitiesService;
|
2023-05-17 14:31:12 -07:00
|
|
|
let store;
|
|
|
|
|
|
|
|
|
|
hooks.beforeEach(function () {
|
2026-02-24 13:48:34 -05:00
|
|
|
abilitiesService = this.owner.lookup('service:abilities');
|
2023-05-17 14:31:12 -07:00
|
|
|
store = this.owner.lookup('service:store');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it reflects when a given account may set password based on authorized_actions', function (assert) {
|
|
|
|
|
const account = store.createRecord('auth-method', {
|
|
|
|
|
authorized_actions: ['set-password'],
|
|
|
|
|
});
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(abilitiesService.can('setPassword account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.authorized_actions = [];
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(abilitiesService.can('setPassword account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('can read known account types when authorized', function (assert) {
|
|
|
|
|
const account = store.createRecord('account', {
|
|
|
|
|
authorized_actions: ['read'],
|
|
|
|
|
type: TYPE_AUTH_METHOD_OIDC,
|
|
|
|
|
});
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(abilitiesService.can('read account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = TYPE_AUTH_METHOD_PASSWORD;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(abilitiesService.can('read account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = TYPE_AUTH_METHOD_LDAP;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(abilitiesService.can('read account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = 'no-such-type';
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(abilitiesService.can('read account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cannot read accounts when unauthorized', function (assert) {
|
|
|
|
|
const account = store.createRecord('account', {
|
|
|
|
|
authorized_actions: [],
|
|
|
|
|
type: TYPE_AUTH_METHOD_OIDC,
|
|
|
|
|
});
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(abilitiesService.can('read account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = TYPE_AUTH_METHOD_PASSWORD;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(abilitiesService.can('read account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = TYPE_AUTH_METHOD_LDAP;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(abilitiesService.can('read account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = 'no-such-type';
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(abilitiesService.can('read account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('can delete known account types when authorized', function (assert) {
|
|
|
|
|
const account = store.createRecord('account', {
|
|
|
|
|
authorized_actions: ['delete'],
|
|
|
|
|
type: TYPE_AUTH_METHOD_OIDC,
|
|
|
|
|
});
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(abilitiesService.can('delete account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = TYPE_AUTH_METHOD_PASSWORD;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(abilitiesService.can('delete account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = TYPE_AUTH_METHOD_LDAP;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(abilitiesService.can('delete account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = 'no-such-type';
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(abilitiesService.can('delete account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cannot delete accounts when unauthorized', function (assert) {
|
|
|
|
|
const account = store.createRecord('account', {
|
|
|
|
|
authorized_actions: ['delete'],
|
|
|
|
|
type: TYPE_AUTH_METHOD_OIDC,
|
|
|
|
|
});
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(abilitiesService.can('delete account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = TYPE_AUTH_METHOD_PASSWORD;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(abilitiesService.can('delete account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = TYPE_AUTH_METHOD_LDAP;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(abilitiesService.can('delete account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = 'no-such-type';
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(abilitiesService.can('delete account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('can update known account types when authorized', function (assert) {
|
|
|
|
|
const account = store.createRecord('account', {
|
|
|
|
|
authorized_actions: ['update'],
|
|
|
|
|
type: TYPE_AUTH_METHOD_OIDC,
|
|
|
|
|
});
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(abilitiesService.can('update account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = TYPE_AUTH_METHOD_PASSWORD;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(abilitiesService.can('update account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = TYPE_AUTH_METHOD_LDAP;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(abilitiesService.can('update account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = 'no-such-type';
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(abilitiesService.can('update account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cannot update accounts when unauthorized', function (assert) {
|
|
|
|
|
const account = store.createRecord('account', {
|
|
|
|
|
authorized_actions: [],
|
|
|
|
|
type: TYPE_AUTH_METHOD_OIDC,
|
|
|
|
|
});
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(abilitiesService.can('update account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = TYPE_AUTH_METHOD_PASSWORD;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(abilitiesService.can('update account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = TYPE_AUTH_METHOD_LDAP;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(abilitiesService.can('update account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
account.type = 'no-such-type';
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(abilitiesService.can('update account', account));
|
2023-05-17 14:31:12 -07:00
|
|
|
});
|
|
|
|
|
});
|