UI: fix DB Postgres test (#28227)

This commit is contained in:
Chelsea Shaw
2024-08-29 16:26:16 -05:00
committed by GitHub
parent b6015de314
commit 4de1c697a2
3 changed files with 52 additions and 32 deletions

View File

@@ -8,6 +8,7 @@ import { service } from '@ember/service';
import { tracked } from '@glimmer/tracking'; import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object'; import { action } from '@ember/object';
import { waitFor } from '@ember/test-waiters'; import { waitFor } from '@ember/test-waiters';
import { task } from 'ember-concurrency';
const LIST_ROOT_ROUTE = 'vault.cluster.secrets.backend.list-root'; const LIST_ROOT_ROUTE = 'vault.cluster.secrets.backend.list-root';
const SHOW_ROUTE = 'vault.cluster.secrets.backend.show'; const SHOW_ROUTE = 'vault.cluster.secrets.backend.show';
@@ -56,42 +57,43 @@ export default class DatabaseConnectionEdit extends Component {
this.args.model[attr] = value; this.args.model[attr] = value;
} }
@action handleCreateConnection = task(
async handleCreateConnection(evt) { waitFor(async (evt) => {
evt.preventDefault(); evt.preventDefault();
const secret = this.args.model; try {
secret const secret = this.args.model;
.save() await secret.save();
.then(() => {
this.showSaveModal = true; this.showSaveModal = true;
}) } catch (e) {
.catch((e) => {
const errorMessage = getErrorMessage(e.errors); const errorMessage = getErrorMessage(e.errors);
this.flashMessages.danger(errorMessage); this.flashMessages.danger(errorMessage);
}); }
} })
);
@action @action
continueWithoutRotate() { continueWithoutRotate() {
if (this.continueWithRotate.isRunning) return;
this.showSaveModal = false; this.showSaveModal = false;
const { name } = this.args.model; const { name } = this.args.model;
this.transitionToRoute(SHOW_ROUTE, name); this.transitionToRoute(SHOW_ROUTE, name);
} }
@action continueWithRotate = task(
@waitFor waitFor(async () => {
async continueWithRotate() { const { backend, name } = this.args.model;
this.showSaveModal = false; try {
const { backend, name } = this.args.model; await this.rotateCredentials(backend, name);
try { this.flashMessages.success(`Successfully rotated root credentials for connection "${name}"`);
await this.rotateCredentials(backend, name); this.transitionToRoute(SHOW_ROUTE, name);
this.flashMessages.success(`Successfully rotated root credentials for connection "${name}"`); } catch (e) {
this.transitionToRoute(SHOW_ROUTE, name); this.flashMessages.danger(`Error rotating root credentials: ${e.errors}`);
} catch (e) { this.transitionToRoute(SHOW_ROUTE, name);
this.flashMessages.danger(`Error rotating root credentials: ${e.errors}`); } finally {
this.transitionToRoute(SHOW_ROUTE, name); this.showSaveModal = false;
} }
} })
);
@action @action
handleUpdateConnection(evt) { handleUpdateConnection(evt) {

View File

@@ -102,7 +102,7 @@
</Hds::Alert> </Hds::Alert>
{{/if}} {{/if}}
<form {{on "submit" this.handleCreateConnection}} aria-label="create connection form"> <form {{on "submit" (perform this.handleCreateConnection)}} aria-label="create connection form">
{{#each @model.fieldAttrs as |attr|}} {{#each @model.fieldAttrs as |attr|}}
{{#if (not-eq attr.options.readOnly true)}} {{#if (not-eq attr.options.readOnly true)}}
<FormField data-test-field={{true}} @attr={{attr}} @model={{@model}} /> <FormField data-test-field={{true}} @attr={{attr}} @model={{@model}} />
@@ -177,7 +177,12 @@
<div class="field is-grouped is-grouped-split is-fullwidth box is-bottomless"> <div class="field is-grouped is-grouped-split is-fullwidth box is-bottomless">
<div class="field is-grouped"> <div class="field is-grouped">
<Hds::ButtonSet> <Hds::ButtonSet>
<Hds::Button @text="Create database" type="submit" data-test-secret-save /> <Hds::Button
@icon={{if this.handleCreateConnection.isRunning "loading"}}
@text="Create database"
type="submit"
data-test-secret-save
/>
<Hds::Button <Hds::Button
@text="Cancel" @text="Cancel"
@color="secondary" @color="secondary"
@@ -370,7 +375,12 @@
</M.Body> </M.Body>
<M.Footer> <M.Footer>
<Hds::ButtonSet> <Hds::ButtonSet>
<Hds::Button @text="Rotate and enable" {{on "click" this.continueWithRotate}} data-test-enable-rotate-connection /> <Hds::Button
@icon={{if this.continueWithRotate.isRunning "loading"}}
@text="Rotate and enable"
{{on "click" (perform this.continueWithRotate)}}
data-test-enable-rotate-connection
/>
<Hds::Button <Hds::Button
@text="Enable without rotating" @text="Enable without rotating"
@color="secondary" @color="secondary"

View File

@@ -48,8 +48,8 @@ const connectionTests = [
{ {
name: 'elasticsearch-connection', name: 'elasticsearch-connection',
plugin: 'elasticsearch-database-plugin', plugin: 'elasticsearch-database-plugin',
elasticUser: 'username', username: 'username',
elasticPassword: 'password', password: 'password',
url: 'http://127.0.0.1:9200', url: 'http://127.0.0.1:9200',
assertCount: 9, assertCount: 9,
requiredFields: async (assert, name) => { requiredFields: async (assert, name) => {
@@ -199,6 +199,8 @@ const connectionTests = [
name: 'postgresql-connection', name: 'postgresql-connection',
plugin: 'postgresql-database-plugin', plugin: 'postgresql-database-plugin',
url: `postgresql://{{username}}:{{password}}@localhost:5432/postgres?sslmode=disable`, url: `postgresql://{{username}}:{{password}}@localhost:5432/postgres?sslmode=disable`,
username: 'username',
password: 'password',
assertCount: 7, assertCount: 7,
requiredFields: async (assert, name) => { requiredFields: async (assert, name) => {
assert.dom('[data-test-input="username"]').exists(`Username field exists for ${name}`); assert.dom('[data-test-input="username"]').exists(`Username field exists for ${name}`);
@@ -269,13 +271,19 @@ module('Acceptance | secrets/database/*', function (hooks) {
await connectionPage.dbPlugin(testCase.plugin); await connectionPage.dbPlugin(testCase.plugin);
assert.dom('[data-test-empty-state]').doesNotExist('Empty state goes away after plugin selected'); assert.dom('[data-test-empty-state]').doesNotExist('Empty state goes away after plugin selected');
await connectionPage.name(testCase.name); await connectionPage.name(testCase.name);
// elasticsearch has a special url field
if (testCase.plugin === 'elasticsearch-database-plugin') { if (testCase.plugin === 'elasticsearch-database-plugin') {
await connectionPage.url(testCase.url); await connectionPage.url(testCase.url);
await connectionPage.username(testCase.elasticUser);
await connectionPage.password(testCase.elasticPassword);
} else { } else {
await connectionPage.connectionUrl(testCase.url); await connectionPage.connectionUrl(testCase.url);
} }
// elasticsearch and postgres require username and password set in order to save
if (testCase.username) {
await connectionPage.username(testCase.username);
await connectionPage.password(testCase.password);
}
testCase.requiredFields(assert, testCase.plugin); testCase.requiredFields(assert, testCase.plugin);
assert.dom('[data-test-input="verify_connection"]').isChecked('verify is checked'); assert.dom('[data-test-input="verify_connection"]').isChecked('verify is checked');
await connectionPage.toggleVerify(); await connectionPage.toggleVerify();