2023-03-01 09:39:41 -06: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-03-01 09:39:41 -06:00
|
|
|
*/
|
|
|
|
|
|
2023-02-01 13:46:23 -05:00
|
|
|
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) {
|
2023-03-31 17:38:17 -07:00
|
|
|
features.enable('ssh-target');
|
2026-02-24 13:48:34 -05:00
|
|
|
const abilitiesService = this.owner.lookup('service:abilities');
|
2023-02-01 13:46:23 -05:00
|
|
|
const store = this.owner.lookup('service:store');
|
|
|
|
|
const credentialLibrary = store.createRecord('credential-library', {
|
|
|
|
|
authorized_actions: ['read'],
|
|
|
|
|
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
|
|
|
|
});
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(
|
|
|
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
|
|
|
);
|
2023-02-01 13:46:23 -05:00
|
|
|
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(
|
|
|
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
|
|
|
);
|
2023-02-01 13:46:23 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cannot read credential library type when unauthorized and feature is enabled', function (assert) {
|
2023-03-31 17:38:17 -07:00
|
|
|
features.enable('ssh-target');
|
2026-02-24 13:48:34 -05:00
|
|
|
const abilitiesService = this.owner.lookup('service:abilities');
|
2023-02-01 13:46:23 -05:00
|
|
|
const store = this.owner.lookup('service:store');
|
|
|
|
|
const credentialLibrary = store.createRecord('credential-library', {
|
|
|
|
|
authorized_actions: [],
|
|
|
|
|
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
|
|
|
|
});
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(
|
|
|
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
|
|
|
);
|
2023-02-01 13:46:23 -05:00
|
|
|
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(
|
|
|
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
|
|
|
);
|
2023-02-01 13:46:23 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cannot read credential library type when unauthorized and feature is disabled', function (assert) {
|
2026-02-24 13:48:34 -05:00
|
|
|
const abilitiesService = this.owner.lookup('service:abilities');
|
2023-02-01 13:46:23 -05:00
|
|
|
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,
|
|
|
|
|
});
|
2023-03-31 17:38:17 -07:00
|
|
|
assert.false(featuresService.isEnabled('ssh-target'));
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(
|
|
|
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
|
|
|
);
|
2023-02-01 13:46:23 -05:00
|
|
|
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(
|
|
|
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
|
|
|
);
|
2023-02-01 13:46:23 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('can read vault-generic but not vault-ssh-certificate when authorized and feature is disabled', function (assert) {
|
2026-02-24 13:48:34 -05:00
|
|
|
const abilitiesService = this.owner.lookup('service:abilities');
|
2023-02-01 13:46:23 -05:00
|
|
|
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,
|
|
|
|
|
});
|
2023-03-31 17:38:17 -07:00
|
|
|
assert.false(featuresService.isEnabled('ssh-target'));
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.false(
|
|
|
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
|
|
|
);
|
2023-02-01 13:46:23 -05:00
|
|
|
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
|
2026-02-24 13:48:34 -05:00
|
|
|
assert.true(
|
|
|
|
|
abilitiesService.can('read credential-library', credentialLibrary),
|
|
|
|
|
);
|
2023-02-01 13:46:23 -05:00
|
|
|
});
|
|
|
|
|
});
|