feat: 🎸 vault ldap CRUDL support

This commit is contained in:
Priya Patel authored and Dharini committed 2025-09-03 16:59:20 -07:00
1 parent 3b7873302b
commit c91771e152
18 files changed
+564 -165

No files matched your search

@@ -10,7 +10,10 @@ import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { setupSqlite } from 'api/test-support/helpers/sqlite';
import { authenticateSession } from 'ember-simple-auth/test-support';
import { Response } from 'miragejs';
import { TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE } from 'api/models/credential-library';
import {
TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
} from 'api/models/credential-library';
import * as selectors from './selectors';
import * as commonSelectors from 'admin/tests/helpers/selectors';
import { setRunOptions } from 'ember-a11y-testing/test-support';
@@ -427,4 +430,89 @@ module('Acceptance | credential-libraries | create', function (hooks) {
);
assert.strictEqual(currentURL(), urls.credentialLibraries);
});
test('can create a new credential library of type vault ldap', async function (assert) {
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 click(commonSelectors.SAVE_BTN);
assert.strictEqual(
this.server.schema.credentialLibraries.where({
type: TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
}).length,
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.attributes.path,
selectors.FIELD_VAULT_PATH_VALUE,
);
assert.strictEqual(
credentialLibrary.credentialType,
selectors.FIELD_CRED_TYPE_UPD_VALUE,
);
});
test('can create a new credential library with username, password and domain type for vault ldap', async function (assert) {
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) {
await visit(`${urls.newCredentialLibrary}?type=vault-ssh-certificate`);
assert.dom(selectors.TYPE_VAULT_SSH_CERT).isNotVisible();
assert.dom(selectors.TYPE_VAULT_LDAP).isNotChecked();
assert.dom(selectors.TYPE_VAULT_GENERIC).isChecked();
});
});
@@ -15,7 +15,10 @@ import sinon from 'sinon';
import * as selectors from './selectors';
import * as commonSelectors from 'admin/tests/helpers/selectors';
import { setRunOptions } from 'ember-a11y-testing/test-support';
import { TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC } from 'api/models/credential-library';
import {
TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
} from 'api/models/credential-library';
import { TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN } from 'api/models/credential';
module('Acceptance | credential-libraries | delete', function (hooks) {
@@ -25,6 +28,7 @@ module('Acceptance | credential-libraries | delete', function (hooks) {
let getCredentialLibraryCount;
let getUsernamePasswordDomainCredentialLibraryCount;
let getVaultLDAPCredentialLibraryCount;
const instances = {
scopes: {
@@ -42,6 +46,7 @@ module('Acceptance | credential-libraries | delete', function (hooks) {
newCredentialLibrary: null,
unknownCredentialLibrary: null,
usernamePasswordDomainCredentialLibrary: null,
vaultLDAPCredentialLibrary: null,
};
hooks.beforeEach(async function () {
@@ -71,6 +76,14 @@ module('Acceptance | credential-libraries | delete', function (hooks) {
credential_type: TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
},
);
instances.vaultLDAPCredentialLibrary = this.server.create(
'credential-library',
{
scope: instances.scopes.project,
credentialStore: instances.credentialStore,
type: TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
},
);
// Generate route URLs for resources
urls.credentialStores = `/scopes/${instances.scopes.project.id}/credential-stores`;
urls.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`;
@@ -79,6 +92,7 @@ module('Acceptance | credential-libraries | delete', function (hooks) {
urls.newCredentialLibrary = `${urls.credentialLibraries}/new`;
urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`;
urls.usernamePasswordDomainCredentialLibrary = `${urls.credentialLibraries}/${instances.usernamePasswordDomainCredentialLibrary.id}`;
urls.vaultLDAPCredentialLibrary = `${urls.credentialLibraries}/${instances.vaultLDAPCredentialLibrary.id}`;
// Generate resource counter
getCredentialLibraryCount = () =>
this.server.schema.credentialLibraries.all().models.length;
@@ -87,6 +101,11 @@ module('Acceptance | credential-libraries | delete', function (hooks) {
credential_type: TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
}).length;
};
getVaultLDAPCredentialLibraryCount = () => {
return this.server.schema.credentialLibraries.where({
type: TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
}).length;
};
await authenticateSession({});
});
@@ -208,4 +227,18 @@ module('Acceptance | credential-libraries | delete', function (hooks) {
usernamePasswordDomainCredentialLibraryCount - 1,
);
});
test('can delete vault ldap credential library type', async function (assert) {
const vaultLDAPCredentialLibraryCount =
getVaultLDAPCredentialLibraryCount();
await visit(urls.vaultLDAPCredentialLibrary);
await click(selectors.MANAGE_DROPDOWN_CRED_LIB);
await click(selectors.MANAGE_DROPDOWN_CRED_LIB_DELETE);
assert.strictEqual(
getVaultLDAPCredentialLibraryCount(),
vaultLDAPCredentialLibraryCount - 1,
);
});
});
@@ -10,6 +10,7 @@ import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { setupSqlite } from 'api/test-support/helpers/sqlite';
import { authenticateSession } from 'ember-simple-auth/test-support';
import * as commonSelectors from 'admin/tests/helpers/selectors';
import { TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP } from 'api/models/credential-library';
module('Acceptance | credential-libraries | list', function (hooks) {
setupApplicationTest(hooks);
@@ -48,10 +49,19 @@ module('Acceptance | credential-libraries | list', function (hooks) {
scope: instances.scopes.project,
credentialStore: instances.credentialStore,
});
instances.vaultLDAPCredentialLibrary = this.server.create(
'credential-library',
{
scope: instances.scopes.project,
credentialStore: instances.credentialStore,
type: TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
},
);
// Generate route URLs for resources
urls.credentialStores = `/scopes/${instances.scopes.project.id}/credential-stores`;
urls.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`;
urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`;
urls.vaultLDAPCredentialLibrary = `${urls.credentialLibraries}/${instances.vaultLDAPCredentialLibrary.id}`;
await authenticateSession({});
});
@@ -90,4 +100,12 @@ module('Acceptance | credential-libraries | list', function (hooks) {
assert.dom(commonSelectors.HREF(urls.credentialLibraries)).isVisible();
});
test('User can navigate to vault ldap credential library details', async function (assert) {
await visit(urls.credentialLibraries);
assert
.dom(commonSelectors.TABLE_RESOURCE_LINK(urls.vaultLDAPCredentialLibrary))
.isVisible();
});
});
@@ -12,6 +12,7 @@ import { authenticateSession } from 'ember-simple-auth/test-support';
import {
TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
} from 'api/models/credential-library';
import * as commonSelectors from 'admin/tests/helpers/selectors';
import { setRunOptions } from 'ember-a11y-testing/test-support';
@@ -190,4 +191,24 @@ module('Acceptance | credential-libraries | read', function (hooks) {
assert.strictEqual(currentURL(), url);
});
test('visiting vault ldap credential library', async function (assert) {
const vaultLDAPCredentialLibrary = this.server.create(
'credential-library',
{
scope: instances.scopes.project,
credentialStore: instances.credentialStore,
type: TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
},
);
await visit(urls.credentialLibraries);
const url = `${urls.credentialLibraries}/${vaultLDAPCredentialLibrary.id}`;
await visit(url);
await a11yAudit();
assert.strictEqual(currentURL(), url);
});
});
@@ -37,6 +37,8 @@ export const FIELD_CRED_MAP_OVERRIDES_BTN =
'[name="credential_mapping_overrides"] button';
export const TYPE_VAULT_SSH_CERT = '[value="vault-ssh-certificate"]';
export const TYPE_VAULT_LDAP = '[value="vault-ldap"]';
export const TYPE_VAULT_GENERIC = '[value="vault-generic"]';
export const FIELD_CRIT_OPTS_KEY =
'[name="critical_options"] tbody td:nth-of-type(1) input';
@@ -13,6 +13,7 @@ import { Response } from 'miragejs';
import {
TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
} from 'api/models/credential-library';
import * as selectors from './selectors';
import * as commonSelectors from 'admin/tests/helpers/selectors';
@@ -72,6 +73,14 @@ module('Acceptance | credential-libraries | update', function (hooks) {
credential_type: TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
},
);
instances.vaultLDAPCredentialLibrary = this.server.create(
'credential-library',
{
scope: instances.scopes.project,
credentialStore: instances.credentialStore,
type: TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
},
);
// Generate route URLs for resources
urls.globalScope = `/scopes/global/scopes`;
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
@@ -83,6 +92,7 @@ module('Acceptance | credential-libraries | update', function (hooks) {
urls.newCredentialLibrary = `${urls.credentialLibraries}/new`;
urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`;
urls.usernamePasswordDomainCredentialLibrary = `${urls.credentialLibraries}/${instances.usernamePasswordDomainCredentialLibrary.id}`;
urls.vaultLDAPCredentialLibrary = `${urls.credentialLibraries}/${instances.vaultLDAPCredentialLibrary.id}`;
await authenticateSession({});
});
@@ -108,6 +118,7 @@ module('Acceptance | credential-libraries | update', function (hooks) {
});
await visit(urls.credentialLibrary);
await click(commonSelectors.EDIT_BTN, 'Activate edit mode');
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
await click(commonSelectors.CANCEL_BTN);
@@ -237,6 +248,7 @@ module('Acceptance | credential-libraries | update', function (hooks) {
);
});
await visit(urls.credentialLibrary);
await click(commonSelectors.EDIT_BTN, 'Activate edit mode');
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
await click(commonSelectors.SAVE_BTN);
@@ -269,6 +281,7 @@ module('Acceptance | credential-libraries | update', function (hooks) {
);
await visit(urls.credentialLibrary);
await click(commonSelectors.EDIT_BTN, 'Activate edit mode');
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
@@ -309,6 +322,7 @@ module('Acceptance | credential-libraries | update', function (hooks) {
);
await visit(urls.credentialLibrary);
await click(commonSelectors.EDIT_BTN, 'Activate edit mode');
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
@@ -340,6 +354,7 @@ module('Acceptance | credential-libraries | update', function (hooks) {
});
await visit(urls.credentialLibrary);
await click(commonSelectors.EDIT_BTN, 'Activate edit mode');
assert.dom(selectors.FIELD_CRED_TYPE).doesNotExist();
@@ -363,6 +378,7 @@ module('Acceptance | credential-libraries | update', function (hooks) {
await visit(
`${urls.credentialLibraries}/${instances.credentialLibrary.id}`,
);
await click(commonSelectors.EDIT_BTN, 'Activate edit mode');
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
await fillIn(
@@ -425,4 +441,55 @@ module('Acceptance | credential-libraries | update', function (hooks) {
ext_key: 'ext_value',
});
});
test('cannot update credential type in a vault ldap credential library', async function (assert) {
await visit(urls.vaultLDAPCredentialLibrary);
await click(commonSelectors.EDIT_BTN, 'Activate edit mode');
assert.dom(selectors.FIELD_CRED_TYPE).doesNotExist();
});
test('can update a vault ldap credential library and save changes', async function (assert) {
await visit(urls.vaultLDAPCredentialLibrary);
await click(commonSelectors.EDIT_BTN, 'Activate edit mode');
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
await fillIn(
commonSelectors.FIELD_DESCRIPTION,
commonSelectors.FIELD_DESCRIPTION_VALUE,
);
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({
type: TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
});
assert.strictEqual(
credentialLibrary.name,
commonSelectors.FIELD_NAME_VALUE,
);
assert.strictEqual(
credentialLibrary.description,
commonSelectors.FIELD_DESCRIPTION_VALUE,
);
assert.strictEqual(
credentialLibrary.attributes.path,
selectors.FIELD_VAULT_PATH_VALUE,
);
assert.deepEqual(credentialLibrary.credentialMappingOverrides, {
domain_attribute: 'domain',
});
});
});
@@ -18,8 +18,11 @@ import {
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
TYPE_CREDENTIAL_JSON,
} from 'api/models/credential';
import { TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC } from 'api/models/credential-library';
import { setRunOptions } from 'ember-a11y-testing/test-support';
import {
TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
} from 'api/models/credential-library';
module(
'Acceptance | targets | injected application credential sources',
@@ -96,14 +99,18 @@ module(
scope: instances.scopes.project,
credentialStore: instances.staticCredentialStore,
});
instances.credentialLibraries = this.server.createList(
'credential-library',
6,
{
instances.credentialLibraries = [
...this.server.createList('credential-library', 3, {
scope: instances.scopes.project,
credentialStore: instances.vaultCredentialStore,
},
);
type: TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
}),
...this.server.createList('credential-library', 3, {
scope: instances.scopes.project,
credentialStore: instances.vaultCredentialStore,
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
}),
];
instances.credentialLibrary = instances.credentialLibraries[0];
instances.credential = instances.credentials[0];