UI: fix delete for SSH engine config (#19448)

* fix delete not working for ssh config

* add test

* add changelog;
This commit is contained in:
claire bontempo 2023-03-08 09:37:53 -08:00 committed by GitHub
parent e29f005db0
commit d16f0ef9d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 76 additions and 18 deletions

3
changelog/19448.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
ui: fixes SSH engine config deletion
```

View File

@ -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 });
}
}

View File

@ -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) {
@ -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);
});
}
},

View File

@ -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">
@ -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
@ -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

View File

@ -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}}

View File

@ -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');
});
});