Skip to content

Commit

Permalink
UI: fix delete for SSH engine config (hashicorp#19448)
Browse files Browse the repository at this point in the history
* fix delete not working for ssh config

* add test

* add changelog;
  • Loading branch information
hellobontempo authored Mar 8, 2023
1 parent 62f3118 commit 75efaf0
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 18 deletions.
3 changes: 3 additions & 0 deletions changelog/19448.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: fixes SSH engine config deletion
```
22 changes: 15 additions & 7 deletions ui/app/components/configure-ssh-secret.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,28 @@ import { action } from '@ember/object';
*
* @example
* ```js
* <ConfigureSshSecret
@model={{model}}
@configured={{configured}}
@saveConfig={{action "saveConfig"}} />
* <ConfigureSshSecret
* @model={{this.model}}
* @configured={{this.configured}}
* @saveConfig={{action "saveConfig"}}
* @loading={{this.loading}}
* />
* ```
*
* @param {string} model - ssh secret engine model
* @param {Function} saveConfig - parent action which updates the configuration
*
* @param {boolean} loading - property in parent that updates depending on status of parent's action
*
*/
export default class ConfigureSshSecretComponent extends Component {
@action
saveConfig(data, event) {
delete() {
this.args.saveConfig({ delete: true });
}

@action
saveConfig(event) {
event.preventDefault();
this.args.saveConfig(data);
this.args.saveConfig({ delete: false });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default Controller.extend(CONFIG_ATTRS, {
this.model
.saveCA({ isDelete })
.then(() => {
this.set('loading', false);
this.send('refreshRoute');
this.set('configured', !isDelete);
if (isDelete) {
Expand All @@ -43,6 +42,9 @@ export default Controller.extend(CONFIG_ATTRS, {
.catch((error) => {
const errorMessage = error.errors ? error.errors.join('. ') : error;
this.flashMessages.danger(errorMessage);
})
.finally(() => {
this.set('loading', false);
});
}
},
Expand Down
18 changes: 9 additions & 9 deletions ui/app/templates/components/configure-ssh-secret.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
<ConfirmAction
@buttonClasses="button"
@confirmMessage="This will remove the CA certificate information."
@onConfirmAction={{action "saveConfig" (hash delete=true)}}
@onConfirmAction={{this.delete}}
>
Delete
</ConfirmAction>
</div>
</div>
{{else}}
<form onsubmit={{action "saveConfig" (hash delete=false)}} data-test-ssh-configure-form="true">
<form {{on "submit" this.saveConfig}} data-test-ssh-configure-form="true">
<div class="box is-fullwidth is-sideless is-marginless">
<NamespaceReminder @mode="save" @noun="configuration" />
<div class="field">
Expand All @@ -58,13 +58,13 @@
</div>
</div>
<div class="b-checkbox">
<input
type="checkbox"
<Input
@type="checkbox"
id="generateSigningKey"
class="styled"
checked={{@model.generateSigningKey}}
onchange={{action (mut @model.generateSigningKey) value="target.checked"}}
data-test-ssh-input={{this.generateSigningKey}}
@checked={{@model.generateSigningKey}}
{{on "change" (fn (mut @model.generateSigningKey) (not @model.generateSigningKey))}}
data-test-ssh-input="generate-signing-key-checkbox"
/>
<label for="generateSigningKey" class="is-label">
Generate signing key
Expand All @@ -78,8 +78,8 @@
<div class="control">
<button
type="submit"
class="button is-primary {{if this.loading 'is-loading'}}"
disabled={{this.loading}}
class="button is-primary {{if @loading 'is-loading'}}"
disabled={{@loading}}
data-test-ssh-input="configure-submit"
>
Save
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@
{{else if (eq this.model.type "pki")}}
<Pki::ConfigurePkiSecret />
{{else if (eq this.model.type "ssh")}}
<ConfigureSshSecret @model={{this.model}} @configured={{this.configured}} @saveConfig={{action "saveConfig"}} />
<ConfigureSshSecret
@model={{this.model}}
@configured={{this.configured}}
@saveConfig={{action "saveConfig"}}
@loading={{this.loading}}
/>
{{/if}}

{{outlet}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { click, settled } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import page from 'vault/tests/pages/settings/configure-secret-backends/pki/index';
import authPage from 'vault/tests/pages/auth';
import enablePage from 'vault/tests/pages/settings/mount-secret-backend';
import { create } from 'ember-cli-page-object';
import fm from 'vault/tests/pages/components/flash-message';
const flashMessage = create(fm);
const SELECTORS = {
generateSigningKey: '[data-test-ssh-input="generate-signing-key-checkbox"]',
saveConfig: '[data-test-ssh-input="configure-submit"]',
publicKey: '[data-test-ssh-input="public-key"]',
};
module('Acceptance | settings/configure/secrets/ssh', function (hooks) {
setupApplicationTest(hooks);

hooks.beforeEach(function () {
return authPage.login();
});

test('it configures ssh ca', async function (assert) {
const path = `ssh-${new Date().getTime()}`;
await enablePage.enable('ssh', path);
await settled();
await page.visit({ backend: path });
await settled();
assert.dom(SELECTORS.generateSigningKey).isChecked('generate_signing_key defaults to true');
await click(SELECTORS.generateSigningKey);
await click(SELECTORS.saveConfig);
assert.strictEqual(
flashMessage.latestMessage,
'missing public_key',
'renders warning flash message for failed save'
);
await click(SELECTORS.generateSigningKey);
await click(SELECTORS.saveConfig);
assert.dom(SELECTORS.publicKey).exists('renders public key after saving config');
});
});

0 comments on commit 75efaf0

Please sign in to comment.