2023-05-22 11:16:48 -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-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-11-22 14:07:41 -05:00
|
|
|
}),
|
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-11-22 14:07:41 -05:00
|
|
|
}),
|
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-11-22 14:07:41 -05:00
|
|
|
}),
|
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-11-22 14:07:41 -05:00
|
|
|
}),
|
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-11-22 14:07:41 -05:00
|
|
|
}),
|
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-11-22 14:07:41 -05:00
|
|
|
}),
|
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-11-22 14:07:41 -05:00
|
|
|
}),
|
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-11-22 14:07:41 -05:00
|
|
|
}),
|
2023-05-22 11:16:48 -07:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|