Files
threshold-ui/ui/admin/tests/unit/abilities/storage-bucket-test.js
T
hashicc b5d33948dc chore: 🤖 bump ember-can (#3093)
* 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
2025-12-08 10:41:38 -05:00

212 lines
6.1 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import {
TYPE_STORAGE_BUCKET_PLUGIN,
TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3,
} from 'api/models/storage-bucket';
module('Unit | Abilities | storage-bucket', function (hooks) {
setupTest(hooks);
let features;
let abilitiesService;
let store;
hooks.beforeEach(function () {
store = this.owner.lookup('service:store');
abilitiesService = this.owner.lookup('service:abilities');
features = this.owner.lookup('service:features');
});
test('can read storage bucket when authorized and feature is enabled', function (assert) {
features.enable('ssh-session-recording');
const storageBucket = store.createRecord('storage-bucket', {
authorized_actions: ['read'],
type: TYPE_STORAGE_BUCKET_PLUGIN,
compositeType: TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3,
});
assert.true(abilitiesService.can('read storage-bucket', storageBucket));
});
test('cannot read storage bucket when unauthorized and feature is enabled', function (assert) {
features.enable('ssh-session-recording');
const storageBucket = store.createRecord('storage-bucket', {
authorized_actions: [],
type: TYPE_STORAGE_BUCKET_PLUGIN,
compositeType: TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3,
});
assert.false(abilitiesService.can('read storage-bucket', storageBucket));
});
test('cannot read storage bucket when authorized and feature is disabled', function (assert) {
const storageBucket = store.createRecord('storage-bucket', {
authorized_actions: ['read'],
type: TYPE_STORAGE_BUCKET_PLUGIN,
compositeType: TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3,
});
assert.false(abilitiesService.can('read storage-bucket', storageBucket));
});
test('cannot read storage bucket when unauthorized and feature is disabled', function (assert) {
const storageBucket = store.createRecord('storage-bucket', {
authorized_actions: [],
type: TYPE_STORAGE_BUCKET_PLUGIN,
compositeType: TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3,
});
assert.false(abilitiesService.can('read storage-bucket', storageBucket));
});
test('can list storage bucket when authorized and in global scope', function (assert) {
features.enable('ssh-session-recording');
const scopeModel = store.createRecord('scope', {
authorized_collection_actions: { 'storage-buckets': ['list'] },
type: 'global',
id: 'global',
});
assert.true(
abilitiesService.can('list scope', scopeModel, {
collection: 'storage-buckets',
}),
);
});
test('cannot list storage bucket when unauthorized and in global scope', function (assert) {
features.enable('ssh-session-recording');
const scopeModel = store.createRecord('scope', {
authorized_collection_actions: { 'storage-buckets': [] },
type: 'global',
id: 'global',
});
assert.false(
abilitiesService.can('list scope', scopeModel, {
collection: 'storage-buckets',
}),
);
});
test('can list storage bucket when authorized and in org scope', function (assert) {
features.enable('ssh-session-recording');
const scopeModel = store.createRecord('scope', {
authorized_collection_actions: { 'storage-buckets': ['list'] },
type: 'org',
id: 'o_123',
});
assert.true(
abilitiesService.can('list scope', scopeModel, {
collection: 'storage-buckets',
}),
);
});
test('can create storage bucket when authorized and in global scope', function (assert) {
features.enable('ssh-session-recording');
const scopeModel = store.createRecord('scope', {
authorized_collection_actions: { 'storage-buckets': ['create'] },
type: 'global',
id: 'global',
});
assert.true(
abilitiesService.can('create scope', scopeModel, {
collection: 'storage-buckets',
}),
);
});
test('can create storage bucket when authorized and in org scope', function (assert) {
features.enable('ssh-session-recording');
const scopeModel = store.createRecord('scope', {
authorized_collection_actions: { 'storage-buckets': ['create'] },
type: 'org',
id: 'o_123',
});
assert.true(
abilitiesService.can('create scope', scopeModel, {
collection: 'storage-buckets',
}),
);
});
test('can create storage bucket when authorized and in project scope', function (assert) {
features.enable('ssh-session-recording');
const scopeModel = store.createRecord('scope', {
authorized_collection_actions: { 'storage-buckets': ['create'] },
type: 'project',
id: 'p_123',
});
assert.true(
abilitiesService.can('create scope', scopeModel, {
collection: 'storage-buckets',
}),
);
});
test('cannot create storage bucket when unauthorized', function (assert) {
features.enable('ssh-session-recording');
const scopeModel = store.createRecord('scope', {
authorized_collection_actions: { 'storage-buckets': [] },
type: 'global',
id: 'global',
});
assert.false(
abilitiesService.can('create scope', scopeModel, {
collection: 'storage-buckets',
}),
);
});
test('can navigate to storage bucket when authorized', function (assert) {
features.enable('ssh-session-recording');
const scopeModel = store.createRecord('scope', {
authorized_collection_actions: { 'storage-buckets': ['create'] },
type: 'global',
id: 'global',
});
assert.true(
abilitiesService.can('navigate scope', scopeModel, {
collection: 'storage-buckets',
}),
);
});
test('cannot navigate to storage bucket when authorized and feature is disabled', function (assert) {
const scopeModel = store.createRecord('scope', {
authorized_collection_actions: { 'storage-buckets': ['create'] },
type: 'global',
id: 'global',
});
assert.false(
abilitiesService.can('navigate scope', scopeModel, {
collection: 'storage-buckets',
}),
);
});
});