chore: 🤖 clean-up json-credentials feature flag (#3049)
This commit is contained in:
1 parent
905a8f1951
commit
bbb5808875
8 files changed
+3
-221
No files matched your search
@@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
import CredentialAbility from 'api/abilities/credential';
|
||||
import { service } from '@ember/service';
|
||||
|
||||
export default class OverrideCredentialAbility extends CredentialAbility {
|
||||
// =service
|
||||
@service features;
|
||||
|
||||
/**
|
||||
* This override ensures that JSON credentials may be read only if the
|
||||
* json-credentials feature flag is enabled. All other types are subject
|
||||
* to the standard logic found in the api addon.
|
||||
*/
|
||||
get canRead() {
|
||||
return this.features.isEnabled('json-credentials') || !this.model.isJSON
|
||||
? super.canRead
|
||||
: false;
|
||||
}
|
||||
}
|
||||
@@ -4,21 +4,16 @@
|
||||
*/
|
||||
|
||||
import Component from '@glimmer/component';
|
||||
import { service } from '@ember/service';
|
||||
import { TYPES_CREDENTIAL } from 'api/models/credential';
|
||||
|
||||
export default class FormCredentialComponent extends Component {
|
||||
// =services
|
||||
@service features;
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Returns an array of available credential types the user can create
|
||||
* @type {object}
|
||||
*/
|
||||
get credentialTypes() {
|
||||
return this.features.isEnabled('json-credentials')
|
||||
? TYPES_CREDENTIAL
|
||||
: TYPES_CREDENTIAL.filter((type) => type !== 'json');
|
||||
return TYPES_CREDENTIAL;
|
||||
}
|
||||
}
|
||||
@@ -22,19 +22,17 @@ const baseEdition = {
|
||||
...licensedFeatures,
|
||||
byow: false,
|
||||
'byow-pki-hcp-cluster-id': false,
|
||||
'json-credentials': false,
|
||||
'static-credentials': false,
|
||||
'target-network-address': false,
|
||||
'ldap-auth-methods': false,
|
||||
'worker-filter': false,
|
||||
'worker-filter-hcp': false,
|
||||
};
|
||||
// Editions maps edition keys to their associated featuresets.
|
||||
// Editions maps edition keys to their associated feature sets.
|
||||
const featureEditions = {};
|
||||
featureEditions.oss = {
|
||||
...baseEdition,
|
||||
byow: true,
|
||||
'json-credentials': true,
|
||||
'static-credentials': true,
|
||||
'target-network-address': true,
|
||||
'ldap-auth-methods': true,
|
||||
|
||||
@@ -236,7 +236,6 @@ module(
|
||||
},
|
||||
});
|
||||
|
||||
featuresService.enable('json-credentials');
|
||||
const credentialsCount = getCredentialsCount();
|
||||
const jsonCredentialCount = getJsonCredentialCount();
|
||||
await visit(urls.credentials);
|
||||
@@ -319,7 +318,6 @@ module(
|
||||
},
|
||||
});
|
||||
|
||||
featuresService.enable('json-credentials');
|
||||
const credentialsCount = getCredentialsCount();
|
||||
await visit(urls.credentials);
|
||||
|
||||
@@ -377,8 +375,6 @@ module(
|
||||
},
|
||||
});
|
||||
|
||||
featuresService.enable('json-credentials');
|
||||
|
||||
await visit(urls.credentials);
|
||||
await click(commonSelectors.HREF(urls.newCredential));
|
||||
await click(selectors.TYPE_SELECT);
|
||||
@@ -572,7 +568,6 @@ module(
|
||||
},
|
||||
});
|
||||
|
||||
featuresService.enable('json-credentials');
|
||||
const errorMessage = 'Error in provided request.';
|
||||
await visit(urls.credentials);
|
||||
this.server.post('/credentials', () => {
|
||||
@@ -603,37 +598,6 @@ module(
|
||||
assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText(errorMessage);
|
||||
});
|
||||
|
||||
test.skip('cannot navigate to json credential when feature is disabled', async function (assert) {
|
||||
setRunOptions({
|
||||
rules: {
|
||||
'color-contrast': {
|
||||
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await visit(urls.credentials);
|
||||
|
||||
await click(commonSelectors.HREF(urls.newCredential));
|
||||
|
||||
assert.false(featuresService.isEnabled('json-credentials'));
|
||||
assert.true(
|
||||
instances.staticCredentialStore.authorized_collection_actions.credentials.includes(
|
||||
'create',
|
||||
),
|
||||
);
|
||||
assert
|
||||
.dom(selectors.FIELD_TYPE_USERNAME_PASSWORD)
|
||||
.exists()
|
||||
.hasAttribute('value', 'username_password');
|
||||
assert
|
||||
.dom(selectors.FIELD_TYPE_SSH)
|
||||
.exists()
|
||||
.hasAttribute('value', 'ssh_private_key');
|
||||
assert.dom(selectors.FIELD_TYPE_JSON).doesNotExist();
|
||||
});
|
||||
|
||||
test('users cannot create a new credential without proper authorization', async function (assert) {
|
||||
setRunOptions({
|
||||
rules: {
|
||||
|
||||
@@ -14,8 +14,6 @@ module('Acceptance | credential-stores | credentials | read', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupSqlite(hooks);
|
||||
|
||||
let featuresService;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
org: null,
|
||||
@@ -88,7 +86,6 @@ module('Acceptance | credential-stores | credentials | read', function (hooks) {
|
||||
urls.jsonCredential = `${urls.credentials}/${instances.jsonCredential.id}`;
|
||||
urls.usernamePasswordDomainCredential = `${urls.credentials}/${instances.usernamePasswordDomainCredential.id}`;
|
||||
urls.unknownCredential = `${urls.credentials}/foo`;
|
||||
featuresService = this.owner.lookup('service:features');
|
||||
});
|
||||
|
||||
test('visiting username & password credential', async function (assert) {
|
||||
@@ -141,7 +138,6 @@ module('Acceptance | credential-stores | credentials | read', function (hooks) {
|
||||
},
|
||||
});
|
||||
|
||||
featuresService.enable('json-credentials');
|
||||
await visit(urls.staticCredentialStore);
|
||||
await click(commonSelectors.HREF(urls.credentials));
|
||||
|
||||
@@ -270,27 +266,6 @@ module('Acceptance | credential-stores | credentials | read', function (hooks) {
|
||||
.doesNotExist();
|
||||
});
|
||||
|
||||
test('cannot navigate to a JSON credential form when feature not enabled', async function (assert) {
|
||||
setRunOptions({
|
||||
rules: {
|
||||
'color-contrast': {
|
||||
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await visit(urls.credentials);
|
||||
|
||||
assert.false(featuresService.isEnabled('json-credentials'));
|
||||
assert
|
||||
.dom(commonSelectors.TABLE_RESOURCE_LINK(urls.usernamePasswordCredential))
|
||||
.isVisible();
|
||||
assert
|
||||
.dom(commonSelectors.TABLE_RESOURCE_LINK(urls.jsonCredential))
|
||||
.doesNotExist();
|
||||
});
|
||||
|
||||
test('visiting an unknown credential displays 404 message', async function (assert) {
|
||||
setRunOptions({
|
||||
rules: {
|
||||
|
||||
@@ -25,8 +25,6 @@ module(
|
||||
setupApplicationTest(hooks);
|
||||
setupSqlite(hooks);
|
||||
|
||||
let featuresService;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
org: null,
|
||||
@@ -119,8 +117,6 @@ module(
|
||||
urls.usernameKeyPairCredential = `${urls.credentials}/${instances.usernameKeyPairCredential.id}`;
|
||||
urls.jsonCredential = `${urls.credentials}/${instances.jsonCredential.id}`;
|
||||
urls.usernamePasswordDomainCredential = `${urls.credentials}/${instances.usernamePasswordDomainCredential.id}`;
|
||||
|
||||
featuresService = this.owner.lookup('service:features');
|
||||
});
|
||||
|
||||
test('can save changes to existing username & password credential', async function (assert) {
|
||||
@@ -186,7 +182,6 @@ module(
|
||||
});
|
||||
|
||||
test('can save changes to existing JSON credential', async function (assert) {
|
||||
featuresService.enable('json-credentials');
|
||||
assert.notEqual(
|
||||
instances.jsonCredential.name,
|
||||
commonSelectors.FIELD_NAME,
|
||||
|
||||
@@ -32,7 +32,6 @@ module('Acceptance | targets | brokered credential sources', function (hooks) {
|
||||
let credentialSourceCount;
|
||||
let randomlySelectedCredentialLibraries;
|
||||
let randomlySelectedCredentials;
|
||||
let featuresService;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
@@ -64,7 +63,6 @@ module('Acceptance | targets | brokered credential sources', function (hooks) {
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
featuresService = this.owner.lookup('service:features');
|
||||
// Generate resources
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
@@ -205,14 +203,12 @@ module('Acceptance | targets | brokered credential sources', function (hooks) {
|
||||
targetName: 'tcpTarget',
|
||||
link: 'jsonCredential',
|
||||
expectedUrl: 'jsonCredential',
|
||||
enableJsonFeature: true,
|
||||
},
|
||||
'json credential type for RDP target': {
|
||||
route: 'brokeredCredentialSourcesForRDPTarget',
|
||||
targetName: 'rdpTarget',
|
||||
link: 'jsonCredential',
|
||||
expectedUrl: 'jsonCredential',
|
||||
enableJsonFeature: true,
|
||||
},
|
||||
},
|
||||
async function (assert, input) {
|
||||
@@ -225,10 +221,6 @@ module('Acceptance | targets | brokered credential sources', function (hooks) {
|
||||
},
|
||||
});
|
||||
|
||||
// needed only if the test is for json credential
|
||||
if (input.enableJsonFeature) {
|
||||
featuresService.enable('json-credentials');
|
||||
}
|
||||
await visit(urls[input.route]);
|
||||
|
||||
await click(commonSelectors.TABLE_RESOURCE_LINK(urls[input.link]));
|
||||
@@ -237,42 +229,6 @@ module('Acceptance | targets | brokered credential sources', function (hooks) {
|
||||
},
|
||||
);
|
||||
|
||||
test.each(
|
||||
'cannot navigate to a json type credential when feature is disabled',
|
||||
{
|
||||
'for TCP target': {
|
||||
route: 'brokeredCredentialSourcesForTCPTarget',
|
||||
targetName: 'tcpTarget',
|
||||
},
|
||||
'for RDP target': {
|
||||
route: 'brokeredCredentialSourcesForRDPTarget',
|
||||
targetName: 'rdpTarget',
|
||||
},
|
||||
},
|
||||
async function (assert, input) {
|
||||
setRunOptions({
|
||||
rules: {
|
||||
'color-contrast': {
|
||||
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const jsonCredential = instances.credentials[3];
|
||||
instances[input.targetName].update({
|
||||
brokeredCredentialSourceIds: [...randomlySelectedCredentials],
|
||||
});
|
||||
await visit(urls[input.route]);
|
||||
|
||||
assert.false(featuresService.isEnabled('json-credentials'));
|
||||
assert
|
||||
.dom(commonSelectors.TABLE_ROW(4))
|
||||
.includesText(jsonCredential.name);
|
||||
assert.dom(commonSelectors.HREF(urls.jsonCredential)).doesNotExist();
|
||||
},
|
||||
);
|
||||
|
||||
test.each(
|
||||
'visiting add brokered credential sources',
|
||||
{
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user