Files
threshold-ui/addons/api/tests/unit/abilities/target-test.js
T

99 lines
3.0 KiB
JavaScript
Raw Normal View History

/**
2026-01-28 17:09:06 -08:00
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
2021-09-16 14:49:48 -04:00
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Abilities | Target', function (hooks) {
setupTest(hooks);
2026-02-24 13:48:34 -05:00
let abilitiesService;
hooks.beforeEach(function () {
2026-02-24 13:48:34 -05:00
abilitiesService = this.owner.lookup('service:abilities');
});
2021-09-16 14:49:48 -04:00
test('it reflects when a given target may connect based on authorized_actions', function (assert) {
const model = {
authorized_actions: ['authorize-session'],
};
2026-02-24 13:48:34 -05:00
assert.true(abilitiesService.can('connect target', model));
2021-09-16 14:49:48 -04:00
model.authorized_actions = [];
2026-02-24 13:48:34 -05:00
assert.false(abilitiesService.can('connect target', model));
2021-09-16 14:49:48 -04:00
});
2021-09-28 14:09:11 -04:00
test('it reflects when a given target may add host sources', function (assert) {
const model = {
authorized_actions: ['add-host-sources'],
};
2026-02-24 13:48:34 -05:00
assert.true(abilitiesService.can('addHostSources target', model));
2021-09-28 14:09:11 -04:00
model.authorized_actions = [];
2026-02-24 13:48:34 -05:00
assert.false(abilitiesService.can('addHostSources target', model));
2021-09-28 14:09:11 -04:00
});
test('it reflects when a given target may remove host sources', function (assert) {
const model = {
authorized_actions: ['remove-host-sources'],
};
2026-02-24 13:48:34 -05:00
assert.true(abilitiesService.can('removeHostSources target', model));
model.authorized_actions = [];
2026-02-24 13:48:34 -05:00
assert.false(abilitiesService.can('removeHostSources target', model));
});
test('it reflects when a given target may add brokered credential sources', function (assert) {
2021-09-28 14:09:11 -04:00
const model = {
authorized_actions: ['add-credential-sources'],
};
2026-02-24 13:48:34 -05:00
assert.true(
abilitiesService.can('addBrokeredCredentialSources target', model),
);
2021-09-28 14:09:11 -04:00
model.authorized_actions = [];
2026-02-24 13:48:34 -05:00
assert.false(
abilitiesService.can('addBrokeredCredentialSources target', model),
);
2021-09-28 14:09:11 -04:00
});
test('it reflects when a given target may remove credential sources', function (assert) {
const model = {
authorized_actions: ['remove-credential-sources'],
};
2026-02-24 13:48:34 -05:00
assert.true(abilitiesService.can('removeCredentialSources target', model));
model.authorized_actions = [];
2026-02-24 13:48:34 -05:00
assert.false(abilitiesService.can('removeCredentialSources target', model));
});
test('it reflects when a given ssh target may add injected application credential sources', function (assert) {
const model = {
authorized_actions: ['add-credential-sources'],
isSSH: true,
};
const modelWithoutAuthorizedActions = {
authorized_actions: [],
isSSH: true,
};
const modelWithoutSSHType = {
authorized_actions: ['add-credential-sources'],
};
assert.true(
2026-02-24 13:48:34 -05:00
abilitiesService.can(
'addInjectedApplicationCredentialSources target',
model,
),
);
assert.false(
2026-02-24 13:48:34 -05:00
abilitiesService.can(
'addInjectedApplicationCredentialSources target',
modelWithoutAuthorizedActions,
),
);
assert.false(
2026-02-24 13:48:34 -05:00
abilitiesService.can(
'addInjectedApplicationCredentialSources target',
modelWithoutSSHType,
),
);
});
2021-09-16 14:49:48 -04:00
});