mirror of
https://github.com/status-im/consul.git
synced 2025-01-24 20:51:10 +00:00
5fb9df1640
* 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>
156 lines
3.4 KiB
JavaScript
156 lines
3.4 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
const assertAuthorize = function (assertion, params = {}, token, $, adapter) {
|
|
const rpc = adapter.rpc;
|
|
const env = adapter.env;
|
|
const settings = adapter.settings;
|
|
adapter.env = {
|
|
var: (str) => $[str],
|
|
};
|
|
adapter.settings = {
|
|
findBySlug: (_) => token,
|
|
};
|
|
|
|
adapter.rpc = function (request, respond) {
|
|
request(
|
|
{
|
|
requestForAuthorize: (request, params) => {
|
|
assertion(request, params);
|
|
},
|
|
},
|
|
() => {},
|
|
params,
|
|
params
|
|
);
|
|
};
|
|
adapter.authorize({}, { modelName: 'permission' }, 1, {});
|
|
adapter.rpc = rpc;
|
|
adapter.env = env;
|
|
adapter.settings = settings;
|
|
};
|
|
module('Unit | Adapter | permission', function (hooks) {
|
|
setupTest(hooks);
|
|
|
|
test('it exists', function (assert) {
|
|
let adapter = this.owner.lookup('adapter:permission');
|
|
assert.ok(adapter);
|
|
});
|
|
|
|
test(`authorize adds the tokens default namespace if one isn't specified`, function (assert) {
|
|
const adapter = this.owner.lookup('adapter:permission');
|
|
const expected = 'test';
|
|
const token = {
|
|
Namespace: expected,
|
|
};
|
|
const env = {
|
|
CONSUL_NSPACES_ENABLED: true,
|
|
};
|
|
const cases = [
|
|
undefined,
|
|
{
|
|
ns: undefined,
|
|
},
|
|
{
|
|
ns: '',
|
|
},
|
|
];
|
|
assert.expect(cases.length);
|
|
cases.forEach((params) => {
|
|
assertAuthorize(
|
|
(request, params) => {
|
|
assert.equal(params.ns, expected);
|
|
},
|
|
params,
|
|
token,
|
|
env,
|
|
adapter
|
|
);
|
|
});
|
|
});
|
|
|
|
test(`authorize doesn't add the tokens default namespace if one is specified`, function (assert) {
|
|
assert.expect(1);
|
|
const adapter = this.owner.lookup('adapter:permission');
|
|
const notExpected = 'test';
|
|
const expected = 'default';
|
|
const token = {
|
|
Namespace: notExpected,
|
|
};
|
|
const env = {
|
|
CONSUL_NSPACES_ENABLED: true,
|
|
};
|
|
assertAuthorize(
|
|
(request, params) => {
|
|
assert.equal(params.ns, expected);
|
|
},
|
|
{
|
|
ns: expected,
|
|
},
|
|
token,
|
|
env,
|
|
adapter
|
|
);
|
|
});
|
|
test(`authorize adds the tokens default partition if one isn't specified`, function (assert) {
|
|
const adapter = this.owner.lookup('adapter:permission');
|
|
const expected = 'test';
|
|
const token = {
|
|
Partition: expected,
|
|
};
|
|
const env = {
|
|
CONSUL_PARTITIONS_ENABLED: true,
|
|
};
|
|
const cases = [
|
|
undefined,
|
|
{
|
|
partition: undefined,
|
|
},
|
|
{
|
|
partition: '',
|
|
},
|
|
];
|
|
assert.expect(cases.length);
|
|
cases.forEach((params) => {
|
|
assertAuthorize(
|
|
(request, params) => {
|
|
assert.equal(params.partition, expected);
|
|
},
|
|
params,
|
|
token,
|
|
env,
|
|
adapter
|
|
);
|
|
});
|
|
});
|
|
|
|
test(`authorize doesn't add the tokens default partition if one is specified`, function (assert) {
|
|
assert.expect(1);
|
|
const adapter = this.owner.lookup('adapter:permission');
|
|
const notExpected = 'test';
|
|
const expected = 'default';
|
|
const token = {
|
|
Partition: notExpected,
|
|
};
|
|
const env = {
|
|
CONSUL_PARTITIONS_ENABLED: true,
|
|
};
|
|
assertAuthorize(
|
|
(request, params) => {
|
|
assert.equal(params.partition, expected);
|
|
},
|
|
{
|
|
partition: expected,
|
|
},
|
|
token,
|
|
env,
|
|
adapter
|
|
);
|
|
});
|
|
});
|