* 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
109 lines
4.3 KiB
JavaScript
109 lines
4.3 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 | Auth Method', function (hooks) {
|
|
setupTest(hooks);
|
|
|
|
let abilitiesService;
|
|
let store;
|
|
|
|
hooks.beforeEach(function () {
|
|
abilitiesService = this.owner.lookup('service:abilities');
|
|
store = this.owner.lookup('service:store');
|
|
});
|
|
|
|
test('can read known auth method types when authorized', function (assert) {
|
|
const authMethod = store.createRecord('auth-method', {
|
|
authorized_actions: ['read'],
|
|
type: TYPE_AUTH_METHOD_OIDC,
|
|
});
|
|
assert.true(abilitiesService.can('read auth-method', authMethod));
|
|
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
|
|
assert.true(abilitiesService.can('read auth-method', authMethod));
|
|
authMethod.type = TYPE_AUTH_METHOD_LDAP;
|
|
assert.true(abilitiesService.can('read auth-method', authMethod));
|
|
authMethod.type = 'no-such-type';
|
|
assert.false(abilitiesService.can('read auth-method', authMethod));
|
|
});
|
|
|
|
test('cannot read auth methods when unauthorized', function (assert) {
|
|
const authMethod = store.createRecord('auth-method', {
|
|
authorized_actions: [],
|
|
type: TYPE_AUTH_METHOD_OIDC,
|
|
});
|
|
assert.false(abilitiesService.can('read auth-method', authMethod));
|
|
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
|
|
assert.false(abilitiesService.can('read auth-method', authMethod));
|
|
authMethod.type = TYPE_AUTH_METHOD_LDAP;
|
|
assert.false(abilitiesService.can('read auth-method', authMethod));
|
|
authMethod.type = 'no-such-type';
|
|
assert.false(abilitiesService.can('read auth-method', authMethod));
|
|
});
|
|
|
|
test('can delete known auth method types when authorized', function (assert) {
|
|
const authMethod = store.createRecord('auth-method', {
|
|
authorized_actions: ['delete'],
|
|
type: TYPE_AUTH_METHOD_OIDC,
|
|
});
|
|
assert.true(abilitiesService.can('delete auth-method', authMethod));
|
|
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
|
|
assert.true(abilitiesService.can('delete auth-method', authMethod));
|
|
authMethod.type = TYPE_AUTH_METHOD_LDAP;
|
|
assert.true(abilitiesService.can('delete auth-method', authMethod));
|
|
authMethod.type = 'no-such-type';
|
|
assert.false(abilitiesService.can('delete auth-method', authMethod));
|
|
});
|
|
|
|
test('cannot delete auth methods when unauthorized', function (assert) {
|
|
const authMethod = store.createRecord('auth-method', {
|
|
authorized_actions: ['delete'],
|
|
type: TYPE_AUTH_METHOD_OIDC,
|
|
});
|
|
assert.true(abilitiesService.can('delete auth-method', authMethod));
|
|
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
|
|
assert.true(abilitiesService.can('delete auth-method', authMethod));
|
|
authMethod.type = TYPE_AUTH_METHOD_LDAP;
|
|
assert.true(abilitiesService.can('delete auth-method', authMethod));
|
|
authMethod.type = 'no-such-type';
|
|
assert.false(abilitiesService.can('delete auth-method', authMethod));
|
|
});
|
|
|
|
test('can update known auth method types when authorized', function (assert) {
|
|
const authMethod = store.createRecord('auth-method', {
|
|
authorized_actions: ['update'],
|
|
type: TYPE_AUTH_METHOD_OIDC,
|
|
});
|
|
assert.true(abilitiesService.can('update auth-method', authMethod));
|
|
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
|
|
assert.true(abilitiesService.can('update auth-method', authMethod));
|
|
authMethod.type = TYPE_AUTH_METHOD_LDAP;
|
|
assert.true(abilitiesService.can('update auth-method', authMethod));
|
|
authMethod.type = 'no-such-type';
|
|
assert.false(abilitiesService.can('update auth-method', authMethod));
|
|
});
|
|
|
|
test('cannot update auth methods when unauthorized', function (assert) {
|
|
const authMethod = store.createRecord('auth-method', {
|
|
authorized_actions: [],
|
|
type: TYPE_AUTH_METHOD_OIDC,
|
|
});
|
|
assert.false(abilitiesService.can('update auth-method', authMethod));
|
|
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
|
|
assert.false(abilitiesService.can('update auth-method', authMethod));
|
|
authMethod.type = TYPE_AUTH_METHOD_LDAP;
|
|
assert.false(abilitiesService.can('update auth-method', authMethod));
|
|
authMethod.type = 'no-such-type';
|
|
assert.false(abilitiesService.can('update auth-method', authMethod));
|
|
});
|
|
});
|