Files
threshold-ui/ui/admin/tests/unit/abilities/session-recording-test.js
T
Randall Morey 8d883073e1 fix: 🐛 fix mismtach between fe/be feature flag strings (#264)
* fix: 🐛 fix mismtach between fe/be feature flag strings

* chore: 🤖 add development can helper to recompute on flags
2023-05-22 08:49:30 -07:00

187 lines
5.2 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { TYPE_SESSION_RECORDING_SSH } from 'api/models/session-recording';
module('Unit | Abilities | session-recording', function (hooks) {
setupTest(hooks);
let features;
let canService;
let store;
hooks.beforeEach(function () {
features = this.owner.lookup('service:features');
canService = this.owner.lookup('service:can');
store = this.owner.lookup('service:store');
});
test('can read session recording feature is enabled', function (assert) {
assert.expect(2);
features.enable('ssh-session-recording');
const recordingWithAuthorizedAction = store.createRecord(
'session-recording',
{
authorized_actions: ['read'],
type: TYPE_SESSION_RECORDING_SSH,
}
);
const recordingWithoutAuthorizedAction = store.createRecord(
'session-recording',
{
authorized_actions: [],
type: TYPE_SESSION_RECORDING_SSH,
}
);
assert.true(
canService.can('read session-recording', recordingWithAuthorizedAction)
);
assert.false(
canService.can('read session-recording', recordingWithoutAuthorizedAction)
);
});
test('cannot read session recording when feature is disabled', function (assert) {
assert.expect(2);
const recordingWithAuthorizedAction = store.createRecord(
'session-recording',
{
authorized_actions: ['read'],
type: TYPE_SESSION_RECORDING_SSH,
}
);
const recordingWithoutAuthorizedAction = store.createRecord(
'session-recording',
{
authorized_actions: [],
type: TYPE_SESSION_RECORDING_SSH,
}
);
assert.false(
canService.can('read session-recording', recordingWithAuthorizedAction)
);
assert.false(
canService.can('read session-recording', recordingWithoutAuthorizedAction)
);
});
test('can list session recording when in global scope', function (assert) {
assert.expect(2);
features.enable('ssh-session-recording');
const scopeModelWithAuthorizedAction = store.createRecord('scope', {
authorized_collection_actions: { ['session-recordings']: ['list'] },
type: 'global',
id: 'first',
});
const scopeModelWithoutAuthorizedAction = store.createRecord('scope', {
authorized_collection_actions: { ['session-recordings']: [] },
type: 'global',
id: 'second',
});
assert.true(
canService.can('list scope', scopeModelWithAuthorizedAction, {
collection: 'session-recordings',
})
);
assert.false(
canService.can('list scope', scopeModelWithoutAuthorizedAction, {
collection: 'session-recordings',
})
);
});
test('can list session recording when in org scope when authorized', function (assert) {
assert.expect(2);
features.enable('ssh-session-recording');
const scopeModelWithAuthorizedAction = store.createRecord('scope', {
authorized_collection_actions: { ['session-recordings']: ['list'] },
type: 'org',
id: 'first',
});
const scopeModelWithoutAuthorizedAction = store.createRecord('scope', {
authorized_collection_actions: { ['session-recordings']: [] },
type: 'org',
id: 'second',
});
assert.true(
canService.can('list scope', scopeModelWithAuthorizedAction, {
collection: 'session-recordings',
})
);
assert.false(
canService.can('list scope', scopeModelWithoutAuthorizedAction, {
collection: 'session-recordings',
})
);
});
test('can navigate to session recording when feature is enabled', function (assert) {
assert.expect(2);
features.enable('ssh-session-recording');
const scopeModelWithAuthorizedAction = store.createRecord('scope', {
authorized_collection_actions: { ['session-recordings']: ['list'] },
type: 'global',
id: 'first',
});
const scopeModelWithoutAuthorizedAction = store.createRecord('scope', {
authorized_collection_actions: { ['session-recordings']: [] },
type: 'global',
id: 'second',
});
assert.true(
canService.can('navigate scope', scopeModelWithAuthorizedAction, {
collection: 'session-recordings',
})
);
assert.false(
canService.can('navigate scope', scopeModelWithoutAuthorizedAction, {
collection: 'session-recordings',
})
);
});
test('cannot navigate to session recording when feature is disabled', function (assert) {
assert.expect(2);
const scopeModelWithAuthorizedAction = store.createRecord('scope', {
authorized_collection_actions: { ['session-recordings']: ['list'] },
type: 'global',
id: 'first',
});
const scopeModelWithoutAuthorizedAction = store.createRecord('scope', {
authorized_collection_actions: { ['session-recordings']: [] },
type: 'global',
id: 'second',
});
assert.false(
canService.can('navigate scope', scopeModelWithAuthorizedAction, {
collection: 'session-recordings',
})
);
assert.false(
canService.can('navigate scope', scopeModelWithoutAuthorizedAction, {
collection: 'session-recordings',
})
);
});
});