Files
threshold-ui/ui/admin/tests/unit/abilities/credential-library-test.js
T
Randall MoreyandZhihe Li 7350c0e08c Feature metadata (#1661)
* 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>
2023-03-31 17:38:17 -07:00

80 lines
3.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import {
TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
} from 'api/models/credential-library';
module('Unit | Abilities | credential-library', function (hooks) {
setupTest(hooks);
let features;
hooks.beforeEach(function () {
features = this.owner.lookup('service:features');
});
test('can read credential library type when authorized and feature is enabled', function (assert) {
assert.expect(2);
features.enable('ssh-target');
const canService = this.owner.lookup('service:can');
const store = this.owner.lookup('service:store');
const credentialLibrary = store.createRecord('credential-library', {
authorized_actions: ['read'],
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
});
assert.true(canService.can('read credential-library', credentialLibrary));
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
assert.true(canService.can('read credential-library', credentialLibrary));
});
test('cannot read credential library type when unauthorized and feature is enabled', function (assert) {
assert.expect(2);
features.enable('ssh-target');
const canService = this.owner.lookup('service:can');
const store = this.owner.lookup('service:store');
const credentialLibrary = store.createRecord('credential-library', {
authorized_actions: [],
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
});
assert.false(canService.can('read credential-library', credentialLibrary));
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
assert.false(canService.can('read credential-library', credentialLibrary));
});
test('cannot read credential library type when unauthorized and feature is disabled', function (assert) {
assert.expect(3);
const canService = this.owner.lookup('service:can');
const store = this.owner.lookup('service:store');
const featuresService = this.owner.lookup('service:features');
const credentialLibrary = store.createRecord('credential-library', {
authorized_actions: [],
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
});
assert.false(featuresService.isEnabled('ssh-target'));
assert.false(canService.can('read credential-library', credentialLibrary));
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
assert.false(canService.can('read credential-library', credentialLibrary));
});
test('can read vault-generic but not vault-ssh-certificate when authorized and feature is disabled', function (assert) {
assert.expect(3);
const canService = this.owner.lookup('service:can');
const store = this.owner.lookup('service:store');
const featuresService = this.owner.lookup('service:features');
const credentialLibrary = store.createRecord('credential-library', {
authorized_actions: ['read'],
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
});
assert.false(featuresService.isEnabled('ssh-target'));
assert.false(canService.can('read credential-library', credentialLibrary));
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
assert.true(canService.can('read credential-library', credentialLibrary));
});
});