Icu 12567 add new field credential mapping overrides (#2156)
* chore: 🤖 add credential type select list
This commit is contained in:
1 parent
956f6fd04d
commit
93c8d481fd
14 files changed
+517
-36
No files matched your search
@@ -95,15 +95,27 @@ module('Acceptance | credential-libraries | create', function (hooks) {
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await select('[name="credential_type"]', 'ssh_private_key');
|
||||
|
||||
await select(
|
||||
'[name="credential_mapping_overrides"] tbody td:nth-of-type(1) select',
|
||||
'private_key_attribute',
|
||||
);
|
||||
await fillIn(
|
||||
'[name="credential_mapping_overrides"] tbody td:nth-of-type(2) input',
|
||||
'key',
|
||||
);
|
||||
await click('[name="credential_mapping_overrides"] button');
|
||||
|
||||
await click('[type="submit"]');
|
||||
assert.strictEqual(getCredentialLibraryCount(), count + 1);
|
||||
|
||||
const credentialLibrary = this.server.schema.credentialLibraries.findBy({
|
||||
name: 'random string',
|
||||
});
|
||||
|
||||
assert.strictEqual(credentialLibrary.name, 'random string');
|
||||
assert.strictEqual(credentialLibrary.credentialType, 'ssh_private_key');
|
||||
assert.deepEqual(credentialLibrary.credentialMappingOverrides, {
|
||||
private_key_attribute: 'key',
|
||||
});
|
||||
});
|
||||
|
||||
test('can create a new credential library of type vault ssh cert', async function (assert) {
|
||||
|
||||
@@ -22,6 +22,17 @@ module('Acceptance | credential-libraries | update', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
const BUTTON_SELECTOR = '.rose-form-actions [type="button"]';
|
||||
const SAVE_BTN_SELECTOR = '.rose-form-actions [type="submit"]';
|
||||
const NAME_INPUT_SELECTOR = '[name="name"]';
|
||||
const FIELD_ERROR_TEXT_SELECTOR = '.hds-form-error__message';
|
||||
const DESC_INPUT_SELECTOR = '[name="description"]';
|
||||
const VAULT_PATH_SELECTOR = '[name="vault_path"]';
|
||||
const CRED_TYPE_SELECTOR = '[name="credential_type"]';
|
||||
const CRED_MAPPING_OVERRIDES_SELECT =
|
||||
'[name="credential_mapping_overrides"] tbody td:nth-of-type(1) select';
|
||||
const CRED_MAPPING_OVERRIDES_INPUT =
|
||||
'[name="credential_mapping_overrides"] tbody td:nth-of-type(2) input';
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
@@ -73,43 +84,60 @@ module('Acceptance | credential-libraries | update', function (hooks) {
|
||||
authenticateSession({});
|
||||
});
|
||||
|
||||
test('can update resource and save changes', async function (assert) {
|
||||
assert.notEqual(instances.credentialLibrary.name, 'random string');
|
||||
await visit(urls.credentialLibrary);
|
||||
await click('form [type="button"]', 'Activate edit mode');
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await click('.rose-form-actions [type="submit"]');
|
||||
assert.strictEqual(currentURL(), urls.credentialLibrary);
|
||||
assert.strictEqual(
|
||||
this.server.schema.credentialLibraries.all().models[0].name,
|
||||
'random string',
|
||||
);
|
||||
});
|
||||
|
||||
test('cannot update resource without proper authorization', async function (assert) {
|
||||
instances.credentialLibrary.authorized_actions =
|
||||
instances.credentialLibrary.authorized_actions.filter(
|
||||
(item) => item !== 'update',
|
||||
);
|
||||
await visit(urls.credentialLibrary);
|
||||
assert.notOk(find('form [type="button"]'));
|
||||
assert.notOk(find(BUTTON_SELECTOR));
|
||||
});
|
||||
|
||||
test('can update a credential library and cancel changes', async function (assert) {
|
||||
await visit(urls.credentialLibrary);
|
||||
await click('form [type="button"]', 'Activate edit mode');
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await click('.rose-form-actions [type="button"]');
|
||||
await click(BUTTON_SELECTOR, 'Activate edit mode');
|
||||
await fillIn(NAME_INPUT_SELECTOR, 'random string');
|
||||
await click(BUTTON_SELECTOR);
|
||||
assert.notEqual(
|
||||
this.server.schema.credentialLibraries.all().models[0].name,
|
||||
'random string',
|
||||
);
|
||||
assert.strictEqual(
|
||||
find('[name="name"]').value,
|
||||
find(NAME_INPUT_SELECTOR).value,
|
||||
instances.credentialLibrary.name,
|
||||
);
|
||||
});
|
||||
|
||||
test('can update a vault generic credential library and save changes', async function (assert) {
|
||||
await visit(
|
||||
`${urls.credentialLibraries}/${instances.credentialLibrary.id}`,
|
||||
);
|
||||
|
||||
await click(BUTTON_SELECTOR);
|
||||
|
||||
await fillIn(NAME_INPUT_SELECTOR, 'random string');
|
||||
await fillIn(DESC_INPUT_SELECTOR, 'description');
|
||||
await fillIn(VAULT_PATH_SELECTOR, 'path');
|
||||
|
||||
await select(CRED_MAPPING_OVERRIDES_SELECT, 'private_key_attribute');
|
||||
await fillIn(CRED_MAPPING_OVERRIDES_INPUT, 'key');
|
||||
|
||||
await click('[name="credential_mapping_overrides"] button');
|
||||
|
||||
await click(SAVE_BTN_SELECTOR);
|
||||
const credentialLibrary = this.server.schema.credentialLibraries.findBy({
|
||||
name: 'random string',
|
||||
});
|
||||
assert.strictEqual(credentialLibrary.name, 'random string');
|
||||
assert.strictEqual(credentialLibrary.description, 'description');
|
||||
assert.strictEqual(credentialLibrary.attributes.path, 'path');
|
||||
assert.deepEqual(credentialLibrary.credentialMappingOverrides, {
|
||||
private_key_attribute: 'key',
|
||||
private_key_passphrase_attribute: null,
|
||||
username_attribute: null,
|
||||
});
|
||||
});
|
||||
|
||||
test('saving an existing credential library with invalid fields displays error messages', async function (assert) {
|
||||
this.server.patch('/credential-libraries/:id', () => {
|
||||
return new Response(
|
||||
@@ -131,15 +159,15 @@ module('Acceptance | credential-libraries | update', function (hooks) {
|
||||
);
|
||||
});
|
||||
await visit(urls.credentialLibrary);
|
||||
await click('form [type="button"]', 'Activate edit mode');
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await click('[type="submit"]');
|
||||
await click(BUTTON_SELECTOR, 'Activate edit mode');
|
||||
await fillIn(NAME_INPUT_SELECTOR, 'random string');
|
||||
await click(SAVE_BTN_SELECTOR);
|
||||
assert.ok(
|
||||
find('[role="alert"]').textContent.trim(),
|
||||
'The request was invalid.',
|
||||
);
|
||||
assert.ok(
|
||||
find('.hds-form-error__message').textContent.trim(),
|
||||
find(FIELD_ERROR_TEXT_SELECTOR).textContent.trim(),
|
||||
'Name is required.',
|
||||
);
|
||||
});
|
||||
@@ -151,8 +179,8 @@ module('Acceptance | credential-libraries | update', function (hooks) {
|
||||
assert.notEqual(instances.credentialLibrary.name, 'random string');
|
||||
|
||||
await visit(urls.credentialLibrary);
|
||||
await click('form [type="button"]', 'Activate edit mode');
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await click(BUTTON_SELECTOR, 'Activate edit mode');
|
||||
await fillIn(NAME_INPUT_SELECTOR, 'random string');
|
||||
assert.strictEqual(currentURL(), urls.credentialLibrary);
|
||||
|
||||
try {
|
||||
@@ -174,8 +202,8 @@ module('Acceptance | credential-libraries | update', function (hooks) {
|
||||
confirmService.enabled = true;
|
||||
assert.notEqual(instances.credentialLibrary.name, 'random string');
|
||||
await visit(urls.credentialLibrary);
|
||||
await click('form [type="button"]', 'Activate edit mode');
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await click(BUTTON_SELECTOR, 'Activate edit mode');
|
||||
await fillIn(NAME_INPUT_SELECTOR, 'random string');
|
||||
assert.strictEqual(currentURL(), urls.credentialLibrary);
|
||||
|
||||
try {
|
||||
@@ -193,8 +221,8 @@ module('Acceptance | credential-libraries | update', function (hooks) {
|
||||
|
||||
test('cannot update credential type in a vault generic credential library', async function (assert) {
|
||||
await visit(urls.credentialLibrary);
|
||||
await click('form [type="button"]', 'Activate edit mode');
|
||||
assert.dom('[name=credential_type]').isDisabled();
|
||||
await click(BUTTON_SELECTOR, 'Activate edit mode');
|
||||
assert.dom(CRED_TYPE_SELECTOR).isDisabled();
|
||||
});
|
||||
|
||||
test('can update a vault ssh cert credential library and save changes', async function (assert) {
|
||||
@@ -206,10 +234,10 @@ module('Acceptance | credential-libraries | update', function (hooks) {
|
||||
await visit(
|
||||
`${urls.credentialLibraries}/${instances.credentialLibrary.id}`,
|
||||
);
|
||||
await click('form [type="button"]:not(:disabled)', 'Activate edit mode');
|
||||
await fillIn('[name="name"]', 'name');
|
||||
await fillIn('[name="description"]', 'description');
|
||||
await fillIn('[name="vault_path"]', 'path');
|
||||
await click(BUTTON_SELECTOR, 'Activate edit mode');
|
||||
await fillIn(NAME_INPUT_SELECTOR, 'name');
|
||||
await fillIn(DESC_INPUT_SELECTOR, 'description');
|
||||
await fillIn(VAULT_PATH_SELECTOR, 'path');
|
||||
await fillIn('[name="username"]', 'username');
|
||||
await select('[name="key_type"]', 'rsa');
|
||||
await fillIn('[name="key_bits"]', 100);
|
||||
@@ -234,7 +262,8 @@ module('Acceptance | credential-libraries | update', function (hooks) {
|
||||
);
|
||||
|
||||
await click('[name="extensions"] button');
|
||||
await click('[type="submit"]');
|
||||
|
||||
await click(SAVE_BTN_SELECTOR);
|
||||
const credentialLibrary = this.server.schema.credentialLibraries.findBy({
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
});
|
||||
|
||||
@@ -163,4 +163,65 @@ module('Integration | Component | list-wrapper', function (hooks) {
|
||||
await click('.list-wrapper-field [data-test-remove-option-button=option1]');
|
||||
assert.dom('tbody tr').exists({ count: 3 });
|
||||
});
|
||||
|
||||
test('it renders multiple options with select and text input as key value pair', async function (assert) {
|
||||
this.options = {
|
||||
username_attribute: 'user',
|
||||
password_attribute: 'pass',
|
||||
};
|
||||
|
||||
this.selectOptions = {
|
||||
username_attribute: 'User Key',
|
||||
password_attribute: 'Pass Key',
|
||||
};
|
||||
await render(hbs`
|
||||
<Form::Field::ListWrapper>
|
||||
<:field as |F|>
|
||||
<F.SelectText @name="credential_mapping_overrides" @options={{this.options}} @removeDuplicates='true' @selectOptions={{this.selectOptions}}></F.SelectText>
|
||||
</:field>
|
||||
</Form::Field::ListWrapper>
|
||||
`);
|
||||
|
||||
assert.dom('tbody tr').exists({ count: 2 });
|
||||
assert
|
||||
.dom('.list-wrapper-field tbody tr:last-child input')
|
||||
.hasValue('pass');
|
||||
assert
|
||||
.dom('.list-wrapper-field tbody tr:last-child select')
|
||||
.hasValue('password_attribute');
|
||||
});
|
||||
|
||||
test('it does not render new rows when the select option limit is reached by passing in @removeDuplicates', async function (assert) {
|
||||
this.options = { username_attribute: 'user', password_attribute: 'pass' };
|
||||
this.selectOptions = {
|
||||
username_attribute: 'User Key',
|
||||
password_attribute: 'Pass Key',
|
||||
};
|
||||
await render(hbs`
|
||||
<Form::Field::ListWrapper>
|
||||
<:field as |F|>
|
||||
<F.SelectText @name="credential_mapping_overrides" @options={{this.options}} @selectOptions={{this.selectOptions}} @removeDuplicates='true'></F.SelectText>
|
||||
</:field>
|
||||
</Form::Field::ListWrapper>
|
||||
`);
|
||||
|
||||
assert.dom('tbody tr').exists({ count: 2 });
|
||||
});
|
||||
|
||||
test('it does render unlimited new rows when @removeDuplicates is not passed', async function (assert) {
|
||||
this.options = { username_attribute: 'user', password_attribute: 'pass' };
|
||||
this.selectOptions = {
|
||||
username_attribute: 'User Key',
|
||||
password_attribute: 'Pass Key',
|
||||
};
|
||||
await render(hbs`
|
||||
<Form::Field::ListWrapper>
|
||||
<:field as |F|>
|
||||
<F.SelectText @name="credential_mapping_overrides" @options={{this.options}} @selectOptions={{this.selectOptions}}></F.SelectText>
|
||||
</:field>
|
||||
</Form::Field::ListWrapper>
|
||||
`);
|
||||
|
||||
assert.dom('tbody tr').exists({ count: 3 });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user