hashicorp-copywrite[bot] 5fb9df1640
[COMPLIANCE] License changes (#18443)
* Adding explicit MPL license for sub-package

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Adding explicit MPL license for sub-package

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Updating the license from MPL to Business Source License

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl.

* add missing license headers

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-11 09:12:13 -04:00

87 lines
2.8 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
/* globals requirejs */
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Ability | *', function (hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function (assert) {
assert.expect(228);
const abilities = Object.keys(requirejs.entries)
.filter((key) => key.indexOf('/abilities/') !== -1)
.map((key) => key.split('/').pop())
.filter((item) => item !== '-test');
abilities.forEach((item) => {
const ability = this.owner.factoryFor(`ability:${item}`).create();
[true, false].forEach((bool) => {
const permissions = this.owner.lookup(`service:repository/permission`);
ability.permissions = {
has: (_) => bool,
permissions: bool ? ['more-than-zero'] : [],
generate: function () {
return permissions.generate(...arguments);
},
};
['Create', 'Read', 'Update', 'Delete', 'Write', 'List'].forEach((perm) => {
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;
case 'peer':
ability.item = {
State: bool ? 'ACTIVE' : 'DELETING',
};
break;
case 'kv':
// TODO: We currently hardcode KVs to always be true
assert.true(ability[`can${perm}`], `Expected ${item}.can${perm} to be true`);
// eslint-disable-next-line qunit/no-early-return
return;
case 'license':
case 'zone':
// Zone permissions depend on NSPACES_ENABLED
// 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
// eslint-disable-next-line qunit/no-early-return
return;
}
assert.equal(
bool,
ability[`can${perm}`],
`Expected ${item}.can${perm} to be ${bool ? 'true' : 'false'}`
);
});
});
});
});
});