refactor: 💡 account and auth-method abilities (#1691)

* refactor: 💡 account and auth-method abilities

* refactor: 💡 add update & delete abilities & unit tests
This commit is contained in:
lisbet-alvarez authored and GitHub committed 2023-05-17 14:31:12 -07:00
1 parent e8a10b3131
commit 6dd0423923
14 files changed
+551 -51

No files matched your search

@@ -8,6 +8,7 @@ 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 | auth-method', function (hooks) {
@@ -15,49 +16,60 @@ module('Unit | Abilities | auth-method', function (hooks) {
let canService;
let store;
let features;
hooks.beforeEach(function () {
canService = this.owner.lookup('service:can');
store = this.owner.lookup('service:store');
features = this.owner.lookup('service:features');
});
test('cannot read LDAP auth-method when authorized', function (assert) {
assert.expect(1);
test('can read LDAP auth-method when authorized and feature flag enabled', function (assert) {
assert.expect(2);
features.enable('ldap-auth-methods');
const authMethod = store.createRecord('auth-method', {
authorized_actions: ['read'],
type: TYPE_AUTH_METHOD_LDAP,
});
assert.true(canService.can('read auth-method', authMethod));
authMethod.authorized_actions = [];
assert.false(canService.can('read auth-method', authMethod));
});
test('cannot read LDAP auth-method when authorized and feature flag disabled', function (assert) {
assert.expect(2);
const authMethod = store.createRecord('auth-method', {
authorized_actions: ['read'],
type: TYPE_AUTH_METHOD_LDAP,
});
assert.false(canService.can('read auth-method', authMethod));
});
test('cannot read LDAP auth-method when unauthorized', function (assert) {
assert.expect(1);
const authMethod = store.createRecord('auth-method', {
authorized_actions: [],
type: TYPE_AUTH_METHOD_LDAP,
});
authMethod.authorized_actions = [];
assert.false(canService.can('read auth-method', authMethod));
});
test('can read non-LDAP auth-method when authorized', function (assert) {
assert.expect(1);
assert.expect(2);
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));
});
test('cannot read non-LDAP auth-method when unauthorized', function (assert) {
assert.expect(1);
assert.expect(2);
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));
});
test('cannot make LDAP auth-method primary', function (assert) {
test('cannot make LDAP auth-method primary when feature flag disabled', function (assert) {
assert.expect(1);
const authMethod = store.createRecord('auth-method', {
type: TYPE_AUTH_METHOD_LDAP,
@@ -65,11 +77,22 @@ module('Unit | Abilities | auth-method', function (hooks) {
assert.false(canService.can('makePrimary auth-method', authMethod));
});
test('can make non-LDAP auth-method primary', function (assert) {
test('can make LDAP auth-method primary when feature flag enabled', function (assert) {
assert.expect(1);
features.enable('ldap-auth-methods');
const authMethod = store.createRecord('auth-method', {
type: TYPE_AUTH_METHOD_LDAP,
});
assert.true(canService.can('makePrimary auth-method', authMethod));
});
test('can make non-LDAP auth-method primary', function (assert) {
assert.expect(2);
const authMethod = store.createRecord('auth-method', {
type: TYPE_AUTH_METHOD_OIDC,
});
assert.true(canService.can('makePrimary auth-method', authMethod));
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
assert.true(canService.can('makePrimary auth-method', authMethod));
});
});