mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-23 07:31:09 +02:00
* [UI] Ember Data Migration - Secrets Engine Resource (#30791) * adds base factory for resources and secrets engine resource * updates dashboard and secret-engine list route to fetch mounts from api service * updates secret backends routes to use api service * updates secrets engine config routes to use api service * updates secrets backend route to use internal mounts endpoint and fixes error handling * updates property casing in config details card component * fixes dashboard tests * fixes issues with engine configuration * updates api service to only set token header if value is defined in auth service * fixes more tests * Update ui/app/routes/vault/cluster/secrets/backend/configuration/index.js Co-authored-by: Angel Garbarino <Monkeychip@users.noreply.github.com> * removes alwaysRender from publicKey field in secret engine configuration details component * removes unused hideToggle arg from secret engine mount config template * updates kv config route to load secret-engine model * fixes kv config route --------- Co-authored-by: Angel Garbarino <Monkeychip@users.noreply.github.com> * [UI] Ember Data Migration - Secrets Engine Forms (#30951) * adds secrets engine form class * updates mount-secret-backend route and form component to use secrets engine form class and api service * updates to form class proxy for nested form data properties * adds form classes for configurable secrets engines * updates secrets engine config edit route and components to use form classes and api service * adds missing copyright header * fixes tests * fixes type error * updates configure-ssh component to use form class and api service * updates configure-ssh tests * updates configuration-wif component tests * fixes mount secret backend and form tests * adds method to normalize request key casing to api service * addresses pr review feedback * removes unused secrets engine config models, adapters and serializers (#30980) * fixes azure config tests * fixes more ent tests --------- Co-authored-by: Angel Garbarino <Monkeychip@users.noreply.github.com>
155 lines
5.2 KiB
JavaScript
155 lines
5.2 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupRenderingTest } from 'vault/tests/helpers';
|
|
import { render, click, fillIn } from '@ember/test-helpers';
|
|
import { hbs } from 'ember-cli-htmlbars';
|
|
import { GENERAL } from 'vault/tests/helpers/general-selectors';
|
|
import { SECRET_ENGINE_SELECTORS as SES } from 'vault/tests/helpers/secret-engine/secret-engine-selectors';
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
|
import sinon from 'sinon';
|
|
import SshConfigForm from 'vault/forms/secrets/ssh-config';
|
|
|
|
module('Integration | Component | SecretEngine/configure-ssh', function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
setupMirage(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
const router = this.owner.lookup('service:router');
|
|
this.id = 'ssh-test';
|
|
this.form = new SshConfigForm({ generateSigningKey: true }, { isNew: true });
|
|
this.transitionStub = sinon.stub(router, 'transitionTo');
|
|
this.refreshStub = sinon.stub(router, 'refresh');
|
|
});
|
|
|
|
test('it shows create fields if not configured', async function (assert) {
|
|
await render(hbs`
|
|
<SecretEngine::ConfigureSsh
|
|
@configForm={{this.form}}
|
|
@id={{this.id}}
|
|
/>
|
|
`);
|
|
assert.dom(GENERAL.inputByAttr('privateKey')).hasNoText('Private key is empty and reset');
|
|
assert.dom(GENERAL.inputByAttr('publicKey')).hasNoText('Public key is empty and reset');
|
|
assert
|
|
.dom(GENERAL.inputByAttr('generateSigningKey'))
|
|
.isChecked('Generate signing key is checked by default');
|
|
});
|
|
|
|
test('it should go back to parent route on cancel', async function (assert) {
|
|
await render(hbs`
|
|
<SecretEngine::ConfigureSsh
|
|
@configForm={{this.form}}
|
|
@id={{this.id}}
|
|
/>
|
|
`);
|
|
|
|
await click(GENERAL.cancelButton);
|
|
|
|
assert.true(
|
|
this.transitionStub.calledWith('vault.cluster.secrets.backend.configuration', 'ssh-test'),
|
|
'On cancel the router transitions to the parent configuration index route.'
|
|
);
|
|
});
|
|
|
|
test('it should validate form fields', async function (assert) {
|
|
await render(hbs`
|
|
<SecretEngine::ConfigureSsh
|
|
@configForm={{this.form}}
|
|
@id={{this.id}}
|
|
/>
|
|
`);
|
|
await fillIn(GENERAL.inputByAttr('publicKey'), 'hello');
|
|
await click(GENERAL.submitButton);
|
|
assert
|
|
.dom(GENERAL.inlineError)
|
|
.hasText(
|
|
'You must provide a Public and Private keys or leave both unset.',
|
|
'Public key validation error renders.'
|
|
);
|
|
|
|
await click(GENERAL.inputByAttr('generateSigningKey'));
|
|
await click(GENERAL.submitButton);
|
|
assert
|
|
.dom(GENERAL.inlineError)
|
|
.hasText(
|
|
'You must provide a Public and Private keys or leave both unset.',
|
|
'Generate signing key validation message shows.'
|
|
);
|
|
});
|
|
|
|
test('it should generate signing key', async function (assert) {
|
|
assert.expect(2);
|
|
this.server.post('/ssh-test/config/ca', (schema, req) => {
|
|
const data = JSON.parse(req.requestBody);
|
|
const expected = {
|
|
generate_signing_key: true,
|
|
};
|
|
assert.deepEqual(expected, data, 'POST request made to save ca-config with correct properties');
|
|
});
|
|
await render(hbs`
|
|
<SecretEngine::ConfigureSsh
|
|
@configForm={{this.form}}
|
|
@id={{this.id}}
|
|
/>
|
|
`);
|
|
|
|
await click(GENERAL.submitButton);
|
|
assert.true(
|
|
this.transitionStub.calledWith('vault.cluster.secrets.backend.configuration', this.id),
|
|
'Transitions to details route on save success.'
|
|
);
|
|
});
|
|
|
|
module('editing', function (hooks) {
|
|
hooks.beforeEach(function () {
|
|
this.editId = 'ssh-edit-me';
|
|
this.publicKey = 'public-key';
|
|
this.form = new SshConfigForm({
|
|
publicKey: this.publicKey,
|
|
generateSigningKey: true,
|
|
});
|
|
});
|
|
test('it populates fields when editing', async function (assert) {
|
|
await render(hbs`
|
|
<SecretEngine::ConfigureSsh
|
|
@configForm={{this.form}}
|
|
@id={{this.editId}}
|
|
/>
|
|
`);
|
|
assert
|
|
.dom(SES.ssh.editConfigSection)
|
|
.exists('renders the edit configuration section of the form and not the create part');
|
|
assert.dom(GENERAL.inputByAttr('public-key')).hasText('***********', 'public key is masked');
|
|
await click(GENERAL.button('toggle-masked'));
|
|
assert
|
|
.dom(GENERAL.inputByAttr('public-key'))
|
|
.hasText(this.publicKey, 'public key is unmasked and shows the actual value');
|
|
});
|
|
|
|
test('it allows you to delete a public key', async function (assert) {
|
|
assert.expect(3);
|
|
this.server.delete('/ssh-edit-me/config/ca', () => {
|
|
assert.true(true, 'DELETE request made to ca-config with correct properties');
|
|
});
|
|
await render(hbs`
|
|
<SecretEngine::ConfigureSsh
|
|
@configForm={{this.form}}
|
|
@id={{this.editId}}
|
|
/>
|
|
`);
|
|
// delete Public key
|
|
await click(GENERAL.button('delete-public-key'));
|
|
assert.dom(GENERAL.confirmMessage).hasText('Confirming will remove the CA certificate information.');
|
|
await click(GENERAL.confirmButton);
|
|
assert.true(
|
|
this.transitionStub.calledWith('vault.cluster.secrets.backend.configuration.edit', 'ssh-edit-me'),
|
|
'On delete the router transitions to the current route.'
|
|
);
|
|
});
|
|
});
|
|
});
|