Files
threshold-ui/addons/api/tests/unit/abilities/account-test.js
T
hashicc b5d33948dc chore: 🤖 bump ember-can (#3093)
* chore: 🤖 bump ember-can

* chore: 🤖 rename "can" service (deprecated) to abilities

See https://github.com/minutebase/ember-can/pull/152

* chore: 🤖 bump to ember-can@^8

* chore: 🤖 extend resolver for ember-can v7 breaking change

https://github.com/minutebase/ember-can/pull/186
2025-12-08 10:41:38 -05:00

118 lines
4.4 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* 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 | Account', function (hooks) {
setupTest(hooks);
let abilitiesService;
let store;
hooks.beforeEach(function () {
abilitiesService = this.owner.lookup('service:abilities');
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'],
});
assert.true(abilitiesService.can('setPassword account', account));
account.authorized_actions = [];
assert.false(abilitiesService.can('setPassword account', account));
});
test('can read known account types when authorized', function (assert) {
const account = store.createRecord('account', {
authorized_actions: ['read'],
type: TYPE_AUTH_METHOD_OIDC,
});
assert.true(abilitiesService.can('read account', account));
account.type = TYPE_AUTH_METHOD_PASSWORD;
assert.true(abilitiesService.can('read account', account));
account.type = TYPE_AUTH_METHOD_LDAP;
assert.true(abilitiesService.can('read account', account));
account.type = 'no-such-type';
assert.false(abilitiesService.can('read account', account));
});
test('cannot read accounts when unauthorized', function (assert) {
const account = store.createRecord('account', {
authorized_actions: [],
type: TYPE_AUTH_METHOD_OIDC,
});
assert.false(abilitiesService.can('read account', account));
account.type = TYPE_AUTH_METHOD_PASSWORD;
assert.false(abilitiesService.can('read account', account));
account.type = TYPE_AUTH_METHOD_LDAP;
assert.false(abilitiesService.can('read account', account));
account.type = 'no-such-type';
assert.false(abilitiesService.can('read account', account));
});
test('can delete known account types when authorized', function (assert) {
const account = store.createRecord('account', {
authorized_actions: ['delete'],
type: TYPE_AUTH_METHOD_OIDC,
});
assert.true(abilitiesService.can('delete account', account));
account.type = TYPE_AUTH_METHOD_PASSWORD;
assert.true(abilitiesService.can('delete account', account));
account.type = TYPE_AUTH_METHOD_LDAP;
assert.true(abilitiesService.can('delete account', account));
account.type = 'no-such-type';
assert.false(abilitiesService.can('delete account', account));
});
test('cannot delete accounts when unauthorized', function (assert) {
const account = store.createRecord('account', {
authorized_actions: ['delete'],
type: TYPE_AUTH_METHOD_OIDC,
});
assert.true(abilitiesService.can('delete account', account));
account.type = TYPE_AUTH_METHOD_PASSWORD;
assert.true(abilitiesService.can('delete account', account));
account.type = TYPE_AUTH_METHOD_LDAP;
assert.true(abilitiesService.can('delete account', account));
account.type = 'no-such-type';
assert.false(abilitiesService.can('delete account', account));
});
test('can update known account types when authorized', function (assert) {
const account = store.createRecord('account', {
authorized_actions: ['update'],
type: TYPE_AUTH_METHOD_OIDC,
});
assert.true(abilitiesService.can('update account', account));
account.type = TYPE_AUTH_METHOD_PASSWORD;
assert.true(abilitiesService.can('update account', account));
account.type = TYPE_AUTH_METHOD_LDAP;
assert.true(abilitiesService.can('update account', account));
account.type = 'no-such-type';
assert.false(abilitiesService.can('update account', account));
});
test('cannot update accounts when unauthorized', function (assert) {
const account = store.createRecord('account', {
authorized_actions: [],
type: TYPE_AUTH_METHOD_OIDC,
});
assert.false(abilitiesService.can('update account', account));
account.type = TYPE_AUTH_METHOD_PASSWORD;
assert.false(abilitiesService.can('update account', account));
account.type = TYPE_AUTH_METHOD_LDAP;
assert.false(abilitiesService.can('update account', account));
account.type = 'no-such-type';
assert.false(abilitiesService.can('update account', account));
});
});