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

103 lines
2.9 KiB
JavaScript
Raw Normal View History

2023-05-22 11:16:48 -07:00
/**
2026-01-28 17:09:06 -08:00
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
2023-05-22 11:16:48 -07:00
*/
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 | user', function (hooks) {
setupTest(hooks);
2026-02-24 13:48:34 -05:00
let abilitiesService;
2023-05-22 11:16:48 -07:00
let store;
let features;
const instances = {
account: null,
user: null,
};
hooks.beforeEach(function () {
2026-02-24 13:48:34 -05:00
abilitiesService = this.owner.lookup('service:abilities');
2023-05-22 11:16:48 -07:00
store = this.owner.lookup('service:store');
features = this.owner.lookup('service:features');
instances.user = store.createRecord('user', {
authorized_actions: ['add-accounts', 'remove-accounts'],
});
instances.account = store.createRecord('account');
});
test('can add ldap account to user when feature flag enabled', function (assert) {
features.enable('ldap-auth-methods');
instances.account.type = TYPE_AUTH_METHOD_LDAP;
assert.true(
2026-02-24 13:48:34 -05:00
abilitiesService.can('addAccount user', instances.user, {
2023-05-22 11:16:48 -07:00
account: instances.account,
}),
2023-05-22 11:16:48 -07:00
);
});
test('can add non-ldap account to user', function (assert) {
instances.account.type = TYPE_AUTH_METHOD_OIDC;
assert.true(
2026-02-24 13:48:34 -05:00
abilitiesService.can('addAccount user', instances.user, {
2023-05-22 11:16:48 -07:00
account: instances.account,
}),
2023-05-22 11:16:48 -07:00
);
instances.account.type = TYPE_AUTH_METHOD_PASSWORD;
assert.true(
2026-02-24 13:48:34 -05:00
abilitiesService.can('addAccount user', instances.user, {
2023-05-22 11:16:48 -07:00
account: instances.account,
}),
2023-05-22 11:16:48 -07:00
);
});
test('cannot add ldap account to user when feature flag disabled', function (assert) {
instances.account.type = TYPE_AUTH_METHOD_LDAP;
assert.false(
2026-02-24 13:48:34 -05:00
abilitiesService.can('addAccount user', instances.user, {
2023-05-22 11:16:48 -07:00
account: instances.account,
}),
2023-05-22 11:16:48 -07:00
);
});
test('can remove ldap account from user when feature flag enabled', function (assert) {
features.enable('ldap-auth-methods');
instances.account.type = TYPE_AUTH_METHOD_LDAP;
assert.true(
2026-02-24 13:48:34 -05:00
abilitiesService.can('removeAccount user', instances.user, {
2023-05-22 11:16:48 -07:00
account: instances.account,
}),
2023-05-22 11:16:48 -07:00
);
});
test('cannot remove ldap account from user when feature flag disabled', function (assert) {
instances.account.type = TYPE_AUTH_METHOD_LDAP;
assert.false(
2026-02-24 13:48:34 -05:00
abilitiesService.can('removeAccount user', instances.user, {
2023-05-22 11:16:48 -07:00
account: instances.account,
}),
2023-05-22 11:16:48 -07:00
);
});
test('can remove non-ldap account from user', function (assert) {
instances.account.type = TYPE_AUTH_METHOD_OIDC;
assert.true(
2026-02-24 13:48:34 -05:00
abilitiesService.can('removeAccount user', instances.user, {
2023-05-22 11:16:48 -07:00
account: instances.account,
}),
2023-05-22 11:16:48 -07:00
);
instances.account.type = TYPE_AUTH_METHOD_PASSWORD;
assert.true(
2026-02-24 13:48:34 -05:00
abilitiesService.can('removeAccount user', instances.user, {
2023-05-22 11:16:48 -07:00
account: instances.account,
}),
2023-05-22 11:16:48 -07:00
);
});
});