fix: 🐛 Update vault-ldap cred library (#3000)
* fix: 🐛 remove UPD cred type from vault-ldap * fix: 🐛 failing tests * fix: 🐛 remove log
This commit is contained in:
1 parent
396bf0a43f
commit
b4f3741979
9 files changed
+27
-149
No files matched your search
@@ -76,13 +76,13 @@ export default class GeneratedCredentialLibraryModel extends BaseModel {
|
||||
path;
|
||||
|
||||
@attr('string', {
|
||||
for: ['vault-generic', 'vault-ldap'],
|
||||
for: 'vault-generic',
|
||||
description: 'It indicates the type of credential the library returns.',
|
||||
})
|
||||
credential_type;
|
||||
|
||||
@attr('object-as-array', {
|
||||
for: ['vault-generic', 'vault-ldap'],
|
||||
for: 'vault-generic',
|
||||
description: 'It indicates the credential mapping overrides.',
|
||||
})
|
||||
credential_mapping_overrides;
|
||||
|
||||
@@ -7,7 +7,6 @@ import ApplicationSerializer from './application';
|
||||
import {
|
||||
TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
|
||||
TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
|
||||
options,
|
||||
} from '../models/credential-library';
|
||||
|
||||
@@ -30,8 +29,6 @@ export default class CredentialLibrarySerializer extends ApplicationSerializer {
|
||||
return this.serializeVaultGeneric(...arguments);
|
||||
case TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE:
|
||||
return this.serializeVaultSshCertificate(...arguments);
|
||||
case TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP:
|
||||
return this.serializeVaultLdap(...arguments);
|
||||
default:
|
||||
return super.serialize(...arguments);
|
||||
}
|
||||
@@ -64,15 +61,6 @@ export default class CredentialLibrarySerializer extends ApplicationSerializer {
|
||||
}
|
||||
}
|
||||
|
||||
serializeVaultLdap(snapshot) {
|
||||
const { isNew } = snapshot;
|
||||
const serialized = super.serialize(...arguments);
|
||||
if (serialized.attributes) {
|
||||
this.handleCredentialMappingOverrides(serialized, isNew);
|
||||
return serialized;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle credential mapping overrides for serialization.
|
||||
* @param {Object} serialized - The serialized object.
|
||||
|
||||
@@ -23,9 +23,6 @@ export default factory.extend({
|
||||
if (this.type === TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC) {
|
||||
return options.credential_types[i % options.credential_types.length];
|
||||
}
|
||||
if (this.type === TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP) {
|
||||
return options.credential_types[2]; // Only supports username, password & domain credential type
|
||||
}
|
||||
},
|
||||
authorized_actions: () =>
|
||||
permissions.authorizedActionsFor('credential-library') || [
|
||||
|
||||
@@ -291,11 +291,6 @@ module('Unit | Serializer | credential library', function (hooks) {
|
||||
description: 'Description',
|
||||
path: '/vault/path',
|
||||
version: 1,
|
||||
credential_type: 'username_password_domain',
|
||||
credential_mapping_overrides: [
|
||||
{ key: 'username_attribute', value: 'user' },
|
||||
{ key: 'domain_attribute', value: 'domain' },
|
||||
],
|
||||
});
|
||||
const snapshot = record._createSnapshot();
|
||||
const serializedRecord = serializer.serialize(snapshot);
|
||||
@@ -306,11 +301,6 @@ module('Unit | Serializer | credential library', function (hooks) {
|
||||
name: 'Name',
|
||||
description: 'Description',
|
||||
version: 1,
|
||||
credential_type: 'username_password_domain',
|
||||
credential_mapping_overrides: {
|
||||
username_attribute: 'user',
|
||||
domain_attribute: 'domain',
|
||||
},
|
||||
attributes: {
|
||||
path: '/vault/path',
|
||||
},
|
||||
@@ -326,15 +316,10 @@ module('Unit | Serializer | credential library', function (hooks) {
|
||||
type: 'credential-library',
|
||||
attributes: {
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
|
||||
name: 'Name',
|
||||
name: 'Test',
|
||||
description: 'Description',
|
||||
path: '/vault/path',
|
||||
version: 1,
|
||||
credential_type: 'username_password_domain',
|
||||
credential_mapping_overrides: [
|
||||
{ key: 'username_attribute', value: 'user' },
|
||||
{ key: 'domain_attribute', value: 'domain' },
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -345,15 +330,9 @@ module('Unit | Serializer | credential library', function (hooks) {
|
||||
assert.deepEqual(serializedRecord, {
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
|
||||
credential_store_id: null,
|
||||
name: 'Name',
|
||||
name: 'Test',
|
||||
description: 'Description',
|
||||
version: 1,
|
||||
credential_type: 'username_password_domain',
|
||||
credential_mapping_overrides: {
|
||||
username_attribute: 'user',
|
||||
domain_attribute: 'domain',
|
||||
password_attribute: null,
|
||||
},
|
||||
attributes: {
|
||||
path: '/vault/path',
|
||||
},
|
||||
|
||||
@@ -96,25 +96,6 @@
|
||||
{{/if}}
|
||||
</Hds::Form::TextInput::Field>
|
||||
|
||||
<InfoField
|
||||
@value={{t
|
||||
(concat 'resources.credential-library.titles.' @model.credential_type)
|
||||
}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t
|
||||
'resources.credential-library.form.credential_type.label'
|
||||
}}</F.Label>
|
||||
<F.HelperText>
|
||||
{{t 'resources.credential-library.form.credential_type.description'}}
|
||||
</F.HelperText>
|
||||
</InfoField>
|
||||
|
||||
<Form::CredentialLibrary::MappingOverrides
|
||||
@model={{@model}}
|
||||
@disabled={{form.disabled}}
|
||||
/>
|
||||
|
||||
{{#if (can 'save model' @model)}}
|
||||
<form.actions
|
||||
@enableEditText={{t 'actions.edit-form'}}
|
||||
|
||||
+1
-10
@@ -7,10 +7,8 @@ import Route from '@ember/routing/route';
|
||||
import { service } from '@ember/service';
|
||||
import {
|
||||
TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
|
||||
TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
|
||||
TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
} from 'api/models/credential-library';
|
||||
import { TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN } from 'api/models/credential';
|
||||
|
||||
export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesNewRoute extends Route {
|
||||
// =services
|
||||
@@ -57,7 +55,7 @@ export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrari
|
||||
'scopes.scope.credential-stores.credential-store',
|
||||
);
|
||||
|
||||
let name, description, credential_type;
|
||||
let name, description;
|
||||
if (this.currentModel?.isNew) {
|
||||
({ name, description } = this.currentModel);
|
||||
this.currentModel.rollbackAttributes();
|
||||
@@ -73,18 +71,11 @@ export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrari
|
||||
resolvedType = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
|
||||
}
|
||||
|
||||
// Set the credential type to username_password_domain if the type is vault ldap
|
||||
if (resolvedType === TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP) {
|
||||
credential_type = TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN;
|
||||
}
|
||||
|
||||
return this.store.createRecord('credential-library', {
|
||||
type: resolvedType,
|
||||
credential_store_id,
|
||||
name,
|
||||
description,
|
||||
// credential_type is only set for vault ldap type
|
||||
credential_type,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -479,10 +479,6 @@ module('Acceptance | credential-libraries | create', function (hooks) {
|
||||
credentialLibrary.attributes.path,
|
||||
selectors.FIELD_VAULT_PATH_VALUE,
|
||||
);
|
||||
assert.strictEqual(
|
||||
credentialLibrary.credentialType,
|
||||
selectors.FIELD_CRED_TYPE_UPD_VALUE,
|
||||
);
|
||||
});
|
||||
|
||||
test('cannot select vault ldap when feature is disabled', async function (assert) {
|
||||
@@ -501,60 +497,6 @@ module('Acceptance | credential-libraries | create', function (hooks) {
|
||||
assert.dom(selectors.TYPE_VAULT_LDAP).doesNotExist();
|
||||
});
|
||||
|
||||
test('can create a new credential library with username, password and domain type for vault ldap', async function (assert) {
|
||||
setRunOptions({
|
||||
rules: {
|
||||
'color-contrast': {
|
||||
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-26
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
featuresService.enable('vault-ldap-credential');
|
||||
|
||||
const credentialLibraryCount = getCredentialLibraryCount();
|
||||
const usernamePasswordDomainCredentialLibraryCount =
|
||||
getUsernamePasswordDomainCredentialLibraryCount();
|
||||
await visit(urls.newCredentialLibrary);
|
||||
|
||||
await click(selectors.TYPE_VAULT_LDAP);
|
||||
|
||||
await fillIn(selectors.FIELD_VAULT_PATH, selectors.FIELD_VAULT_PATH_VALUE);
|
||||
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
|
||||
|
||||
await select(
|
||||
selectors.FIELD_CRED_MAP_OVERRIDES_SELECT,
|
||||
selectors.FIELD_CRED_MAP_OVERRIDES_SELECT_DOMAIN_VALUE,
|
||||
);
|
||||
await fillIn(selectors.FIELD_CRED_MAP_OVERRIDES_INPUT, 'domain');
|
||||
|
||||
await click(selectors.FIELD_CRED_MAP_OVERRIDES_BTN);
|
||||
await click(commonSelectors.SAVE_BTN);
|
||||
|
||||
assert.strictEqual(getCredentialLibraryCount(), credentialLibraryCount + 1);
|
||||
assert.strictEqual(
|
||||
getUsernamePasswordDomainCredentialLibraryCount(),
|
||||
usernamePasswordDomainCredentialLibraryCount + 1,
|
||||
);
|
||||
|
||||
const credentialLibrary = this.server.schema.credentialLibraries.findBy({
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
|
||||
});
|
||||
|
||||
assert.strictEqual(
|
||||
credentialLibrary.name,
|
||||
commonSelectors.FIELD_NAME_VALUE,
|
||||
);
|
||||
assert.strictEqual(
|
||||
credentialLibrary.credentialType,
|
||||
selectors.FIELD_CRED_TYPE_UPD_VALUE,
|
||||
);
|
||||
assert.deepEqual(credentialLibrary.credentialMappingOverrides, {
|
||||
domain_attribute: 'domain',
|
||||
});
|
||||
});
|
||||
|
||||
test('default `vault-generic` credential library is selected when `ssh-target` feature is not enabled and user manually sets `type` in the query params', async function (assert) {
|
||||
setRunOptions({
|
||||
rules: {
|
||||
|
||||
@@ -489,14 +489,6 @@ module('Acceptance | credential-libraries | update', function (hooks) {
|
||||
|
||||
await fillIn(selectors.FIELD_VAULT_PATH, selectors.FIELD_VAULT_PATH_VALUE);
|
||||
|
||||
await select(
|
||||
selectors.FIELD_CRED_MAP_OVERRIDES_SELECT,
|
||||
selectors.FIELD_CRED_MAP_OVERRIDES_SELECT_DOMAIN_VALUE,
|
||||
);
|
||||
|
||||
await fillIn(selectors.FIELD_CRED_MAP_OVERRIDES_INPUT, 'domain');
|
||||
await click(selectors.FIELD_CRED_MAP_OVERRIDES_BTN);
|
||||
|
||||
await click(commonSelectors.SAVE_BTN);
|
||||
|
||||
const credentialLibrary = this.server.schema.credentialLibraries.findBy({
|
||||
@@ -515,8 +507,5 @@ module('Acceptance | credential-libraries | update', function (hooks) {
|
||||
credentialLibrary.attributes.path,
|
||||
selectors.FIELD_VAULT_PATH_VALUE,
|
||||
);
|
||||
assert.deepEqual(credentialLibrary.credentialMappingOverrides, {
|
||||
domain_attribute: 'domain',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -132,8 +132,12 @@ module(
|
||||
|
||||
filteredCredentialLibraries = selectItems(
|
||||
this.server.schema.credentialLibraries,
|
||||
(cred) =>
|
||||
cred.credential_type !== TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
(cred) => {
|
||||
return (
|
||||
cred.credential_type !== TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN &&
|
||||
cred.type !== TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
// credentials for RDP
|
||||
@@ -143,7 +147,8 @@ module(
|
||||
[
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD,
|
||||
].includes(cred.credential_type),
|
||||
].includes(cred.credential_type) ||
|
||||
cred.type === TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
|
||||
);
|
||||
filteredCredentialsForRDP = selectItems(
|
||||
this.server.schema.credentials,
|
||||
@@ -188,9 +193,13 @@ module(
|
||||
|
||||
// SSH specific credential sources
|
||||
getCredentialLibraryCount = () =>
|
||||
this.server.schema.credentialLibraries.where(
|
||||
(c) => c.credential_type !== TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
).models.length;
|
||||
this.server.schema.credentialLibraries.where((c) => {
|
||||
return (
|
||||
c.credential_type !== TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN &&
|
||||
c.type !== TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP
|
||||
);
|
||||
}).models.length;
|
||||
|
||||
getCredentialCount = () =>
|
||||
this.server.schema.credentials.where(
|
||||
(cred) =>
|
||||
@@ -209,11 +218,13 @@ module(
|
||||
].includes(cred.type),
|
||||
).models.length;
|
||||
getCredentialLibraryForRDPCount = () =>
|
||||
this.server.schema.credentialLibraries.where((cred) =>
|
||||
[
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD,
|
||||
].includes(cred.credential_type),
|
||||
this.server.schema.credentialLibraries.where(
|
||||
(cred) =>
|
||||
[
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD,
|
||||
].includes(cred.credential_type) ||
|
||||
cred.type === TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
|
||||
).models.length;
|
||||
|
||||
credentialSourceCount =
|
||||
|
||||
Reference in new issue
Block a user