2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2021-09-27 15:46:26 +00:00
|
|
|
/* globals requirejs */
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
|
2022-09-15 08:43:17 +00:00
|
|
|
module('Unit | Ability | *', function (hooks) {
|
2021-09-27 15:46:26 +00:00
|
|
|
setupTest(hooks);
|
|
|
|
|
2024-03-13 20:59:00 +00:00
|
|
|
// Replace this with your real tests.
|
2022-09-15 08:43:17 +00:00
|
|
|
test('it exists', function (assert) {
|
2024-03-13 20:59:00 +00:00
|
|
|
assert.expect(228);
|
2023-02-10 21:32:19 +00:00
|
|
|
|
2021-09-27 15:46:26 +00:00
|
|
|
const abilities = Object.keys(requirejs.entries)
|
2022-09-15 08:43:17 +00:00
|
|
|
.filter((key) => key.indexOf('/abilities/') !== -1)
|
|
|
|
.map((key) => key.split('/').pop())
|
|
|
|
.filter((item) => item !== '-test');
|
|
|
|
abilities.forEach((item) => {
|
2021-09-27 15:46:26 +00:00
|
|
|
const ability = this.owner.factoryFor(`ability:${item}`).create();
|
2022-09-15 08:43:17 +00:00
|
|
|
[true, false].forEach((bool) => {
|
2021-09-27 15:46:26 +00:00
|
|
|
const permissions = this.owner.lookup(`service:repository/permission`);
|
|
|
|
ability.permissions = {
|
2022-09-15 08:43:17 +00:00
|
|
|
has: (_) => bool,
|
2021-09-27 15:46:26 +00:00
|
|
|
permissions: bool ? ['more-than-zero'] : [],
|
2022-09-15 08:43:17 +00:00
|
|
|
generate: function () {
|
2021-09-27 15:46:26 +00:00
|
|
|
return permissions.generate(...arguments);
|
|
|
|
},
|
|
|
|
};
|
2022-09-15 08:43:17 +00:00
|
|
|
['Create', 'Read', 'Update', 'Delete', 'Write', 'List'].forEach((perm) => {
|
2021-09-27 15:46:26 +00:00
|
|
|
switch (item) {
|
|
|
|
case 'permission':
|
|
|
|
ability.item = {
|
|
|
|
ID: bool ? 'not-anonymous' : 'anonymous',
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 'acl':
|
|
|
|
ability.item = {
|
|
|
|
ID: bool ? 'not-anonymous' : 'anonymous',
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 'token':
|
|
|
|
ability.item = {
|
|
|
|
AccessorID: 'not-anonymous',
|
|
|
|
};
|
|
|
|
ability.token = {
|
|
|
|
AccessorID: bool ? 'different-to-item' : 'not-anonymous',
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 'nspace':
|
|
|
|
case 'partition':
|
|
|
|
ability.item = {
|
|
|
|
ID: bool ? 'not-default' : 'default',
|
|
|
|
};
|
|
|
|
break;
|
2022-07-04 10:31:58 +00:00
|
|
|
case 'peer':
|
|
|
|
ability.item = {
|
|
|
|
State: bool ? 'ACTIVE' : 'DELETING',
|
|
|
|
};
|
|
|
|
break;
|
2021-09-27 15:46:26 +00:00
|
|
|
case 'kv':
|
|
|
|
// TODO: We currently hardcode KVs to always be true
|
2023-02-10 21:32:19 +00:00
|
|
|
assert.true(ability[`can${perm}`], `Expected ${item}.can${perm} to be true`);
|
|
|
|
// eslint-disable-next-line qunit/no-early-return
|
2021-09-27 15:46:26 +00:00
|
|
|
return;
|
2022-04-18 20:05:16 +00:00
|
|
|
case 'license':
|
2022-04-04 08:45:03 +00:00
|
|
|
case 'zone':
|
|
|
|
// Zone permissions depend on NSPACES_ENABLED
|
2022-04-18 20:05:16 +00:00
|
|
|
// License permissions also depend on NSPACES_ENABLED;
|
|
|
|
// behavior works as expected when verified manually but test
|
|
|
|
// fails due to this dependency. -@evrowe 2022-04-18
|
2023-02-10 21:32:19 +00:00
|
|
|
// eslint-disable-next-line qunit/no-early-return
|
2022-04-04 08:45:03 +00:00
|
|
|
return;
|
2021-09-27 15:46:26 +00:00
|
|
|
}
|
|
|
|
assert.equal(
|
|
|
|
bool,
|
|
|
|
ability[`can${perm}`],
|
|
|
|
`Expected ${item}.can${perm} to be ${bool ? 'true' : 'false'}`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|