* feat: 🎸 load edition from controller-metadata.json * refactor: 💡 rename edition and add licensed features support * chore: 🤖 support dev toggling of licensed features * chore: 🤖 rename ent edition * Update ui/admin/app/services/feature-edition.js * Update ui/admin/app/instance-initializers/feature-edition.js Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> * chore: 🤖 cleanup * chore: 🤖 feature edition disabled in tests / fix test cases * test: 💍 remove feature disable calls in tests * test: 💍 fix broken tests * fix: 🐛 fix config bug * fix: 🐛 fix broken test due to feature flags --------- Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
83 lines
3.2 KiB
JavaScript
83 lines
3.2 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
module('Unit | Abilities | credential', function (hooks) {
|
|
setupTest(hooks);
|
|
|
|
let featuresService;
|
|
|
|
hooks.beforeEach(function () {
|
|
// Enable json-credentials feature by default
|
|
featuresService = this.owner.lookup('service:features');
|
|
});
|
|
|
|
test('can read credentials, including JSON credentials, when authorized and json-credentials feature is enabled', function (assert) {
|
|
assert.expect(3);
|
|
featuresService.enable('json-credentials');
|
|
const service = this.owner.lookup('service:can');
|
|
const store = this.owner.lookup('service:store');
|
|
const credential = store.createRecord('credential', {
|
|
authorized_actions: ['read'],
|
|
type: 'json',
|
|
});
|
|
assert.true(service.can('read credential', credential));
|
|
credential.type = 'username_password';
|
|
assert.true(service.can('read credential', credential));
|
|
credential.type = 'ssh_private_key';
|
|
assert.true(service.can('read credential', credential));
|
|
});
|
|
|
|
test('cannot read credentials, including JSON credentials, when unauthorized and json-credentials feature is enabled', function (assert) {
|
|
assert.expect(3);
|
|
featuresService.enable('json-credentials');
|
|
const service = this.owner.lookup('service:can');
|
|
const store = this.owner.lookup('service:store');
|
|
const credential = store.createRecord('credential', {
|
|
authorized_actions: [],
|
|
type: 'json',
|
|
});
|
|
assert.false(service.can('read credential', credential));
|
|
credential.type = 'username_password';
|
|
assert.false(service.can('read credential', credential));
|
|
credential.type = 'ssh_private_key';
|
|
assert.false(service.can('read credential', credential));
|
|
});
|
|
|
|
test('cannot read credentials, including JSON credentials, when unauthorized and json-credentials feature is disabled', function (assert) {
|
|
assert.expect(4);
|
|
const service = this.owner.lookup('service:can');
|
|
const store = this.owner.lookup('service:store');
|
|
const credential = store.createRecord('credential', {
|
|
authorized_actions: [],
|
|
type: 'json',
|
|
});
|
|
assert.false(featuresService.isEnabled('json-credentials'));
|
|
assert.false(service.can('read credential', credential));
|
|
credential.type = 'username_password';
|
|
assert.false(service.can('read credential', credential));
|
|
credential.type = 'ssh_private_key';
|
|
assert.false(service.can('read credential', credential));
|
|
});
|
|
|
|
test('can read credentials, excepting JSON credentials, when authorized and json-credentials feature is disabled', function (assert) {
|
|
assert.expect(4);
|
|
const service = this.owner.lookup('service:can');
|
|
const store = this.owner.lookup('service:store');
|
|
const credential = store.createRecord('credential', {
|
|
authorized_actions: ['read'],
|
|
type: 'json',
|
|
});
|
|
assert.false(featuresService.isEnabled('json-credentials'));
|
|
assert.false(service.can('read credential', credential));
|
|
credential.type = 'username_password';
|
|
assert.true(service.can('read credential', credential));
|
|
credential.type = 'ssh_private_key';
|
|
assert.true(service.can('read credential', credential));
|
|
});
|
|
});
|