* chore: 🤖 reapply previous ember-can upgrade from #3093 * chore: 🤖 add missing ember-inflector dependency * chore: 🤖 move @ember/string to be a dependency in desktop * chore: 🤖 re-run pnpm install to resolve lockfile dupe key error * chore: 🤖 remove unused abilities service injections Co-Authored-By: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com> --------- Co-authored-by: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com>
92 lines
3.5 KiB
JavaScript
92 lines
3.5 KiB
JavaScript
/**
|
|
* Copyright IBM Corp. 2021, 2026
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupTest } from 'ember-qunit';
|
|
import {
|
|
TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
|
|
TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
|
} from 'api/models/credential-library';
|
|
|
|
module('Unit | Abilities | credential-library', function (hooks) {
|
|
setupTest(hooks);
|
|
|
|
let features;
|
|
|
|
hooks.beforeEach(function () {
|
|
features = this.owner.lookup('service:features');
|
|
});
|
|
|
|
test('can read credential library type when authorized and feature is enabled', function (assert) {
|
|
features.enable('ssh-target');
|
|
const abilitiesService = this.owner.lookup('service:abilities');
|
|
const store = this.owner.lookup('service:store');
|
|
const credentialLibrary = store.createRecord('credential-library', {
|
|
authorized_actions: ['read'],
|
|
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
|
});
|
|
assert.true(
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
);
|
|
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
|
|
assert.true(
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
);
|
|
});
|
|
|
|
test('cannot read credential library type when unauthorized and feature is enabled', function (assert) {
|
|
features.enable('ssh-target');
|
|
const abilitiesService = this.owner.lookup('service:abilities');
|
|
const store = this.owner.lookup('service:store');
|
|
const credentialLibrary = store.createRecord('credential-library', {
|
|
authorized_actions: [],
|
|
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
|
});
|
|
assert.false(
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
);
|
|
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
|
|
assert.false(
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
);
|
|
});
|
|
|
|
test('cannot read credential library type when unauthorized and feature is disabled', function (assert) {
|
|
const abilitiesService = this.owner.lookup('service:abilities');
|
|
const store = this.owner.lookup('service:store');
|
|
const featuresService = this.owner.lookup('service:features');
|
|
const credentialLibrary = store.createRecord('credential-library', {
|
|
authorized_actions: [],
|
|
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
|
});
|
|
assert.false(featuresService.isEnabled('ssh-target'));
|
|
assert.false(
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
);
|
|
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
|
|
assert.false(
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
);
|
|
});
|
|
|
|
test('can read vault-generic but not vault-ssh-certificate when authorized and feature is disabled', function (assert) {
|
|
const abilitiesService = this.owner.lookup('service:abilities');
|
|
const store = this.owner.lookup('service:store');
|
|
const featuresService = this.owner.lookup('service:features');
|
|
const credentialLibrary = store.createRecord('credential-library', {
|
|
authorized_actions: ['read'],
|
|
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
|
});
|
|
assert.false(featuresService.isEnabled('ssh-target'));
|
|
assert.false(
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
);
|
|
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
|
|
assert.true(
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
);
|
|
});
|
|
});
|