diff --git a/changelog/11127.txt b/changelog/11127.txt new file mode 100644 index 0000000000..899908099a --- /dev/null +++ b/changelog/11127.txt @@ -0,0 +1,3 @@ +```changelog:bug +ui: Fix bug where database secret engines with custom names cannot delete connections +``` diff --git a/ui/app/adapters/database/connection.js b/ui/app/adapters/database/connection.js index 6c6cb3eb3e..174fd6e3dd 100644 --- a/ui/app/adapters/database/connection.js +++ b/ui/app/adapters/database/connection.js @@ -63,11 +63,12 @@ export default ApplicationAdapter.extend({ deleteRecord(store, type, snapshot) { const id = snapshot.id; - return this.ajax(this.urlFor('database', id), 'DELETE'); + const backend = snapshot.attr('backend'); + return this.ajax(this.urlFor(backend, id), 'DELETE'); }, rotateRootCredentials(backend, id) { - return this.ajax(this.urlFor('database', id, 'ROTATE'), 'POST'); + return this.ajax(this.urlFor(backend, id, 'ROTATE'), 'POST'); }, resetConnection(backend, id) { diff --git a/ui/tests/acceptance/secrets/backend/database/secret-test.js b/ui/tests/acceptance/secrets/backend/database/secret-test.js index 38b9ce3bd6..d1792cbadf 100644 --- a/ui/tests/acceptance/secrets/backend/database/secret-test.js +++ b/ui/tests/acceptance/secrets/backend/database/secret-test.js @@ -71,7 +71,7 @@ module('Acceptance | secrets/database/*', function(hooks) { assert.dom('[data-test-secret-list-tab="Roles"]').exists('Has Roles tab'); }); - test('Connection create and edit form happy path works as expected', async function(assert) { + test('Can create and delete a connection', async function(assert) { const backend = await mount(); const connectionDetails = { plugin: 'mongodb-database-plugin', @@ -127,11 +127,60 @@ module('Acceptance | secrets/database/*', function(hooks) { assert.dom(`[data-test-row-value="${label}"]`).hasText(value); } }); + await connectionPage.delete(); + assert.equal(currentURL(), `/vault/secrets/${backend}/list`, 'Redirects to connection list page'); + assert + .dom('[data-test-empty-state-title') + .hasText('No connections in this backend', 'No connections listed because it was deleted'); + }); + + test('Connection edit form happy path works as expected', async function(assert) { + await mount(); + const connectionDetails = { + plugin: 'mongodb-database-plugin', + id: 'horses-db', + fields: [ + { label: 'Connection Name', name: 'name', value: 'horses-db' }, + { label: 'Connection url', name: 'connection_url', value: 'mongodb://127.0.0.1:235/horses' }, + { label: 'Username', name: 'username', value: 'user', hideOnShow: true }, + { label: 'Password', name: 'password', password: 'so-secure', hideOnShow: true }, + { label: 'Write concern', name: 'write_concern' }, + ], + }; + await connectionPage.createLink(); + await connectionPage.dbPlugin(connectionDetails.plugin); + connectionDetails.fields.forEach(async ({ name, value }) => { + assert + .dom(`[data-test-input="${name}"]`) + .exists(`Field ${name} exists for ${connectionDetails.plugin}`); + if (value) { + await fillIn(`[data-test-input="${name}"]`, value); + } + }); + // uncheck verify for the save step to work + await connectionPage.toggleVerify(); + await connectionPage.save(); + assert + .dom('[data-test-modal-title]') + .hasText('Rotate your root credentials?', 'Modal appears asking to '); + await connectionPage.enable(); + connectionDetails.fields.forEach(({ label, name, value, hideOnShow }) => { + if (hideOnShow) { + assert + .dom(`[data-test-row-value="${label}"]`) + .doesNotExist(`Does not show ${name} value on show page for ${connectionDetails.plugin}`); + } else if (!value) { + assert.dom(`[data-test-row-value="${label}"]`).hasText('Default'); + } else { + assert.dom(`[data-test-row-value="${label}"]`).hasText(value); + } + }); // go back and edit write_concern await connectionPage.edit(); assert.dom(`[data-test-input="name"]`).hasAttribute('readonly'); assert.dom(`[data-test-input="plugin_name"]`).hasAttribute('readonly'); // assert password is hidden + assert.dom('[data-test-input="password"]').doesNotExist('Password field is not shown on edit'); findAll('.CodeMirror')[0].CodeMirror.setValue(JSON.stringify({ wtimeout: 5000 })); // uncheck verify for the save step to work await connectionPage.toggleVerify(); diff --git a/ui/tests/pages/secrets/backend/database/connection.js b/ui/tests/pages/secrets/backend/database/connection.js index 7cbc90ffd0..13ced1664d 100644 --- a/ui/tests/pages/secrets/backend/database/connection.js +++ b/ui/tests/pages/secrets/backend/database/connection.js @@ -14,4 +14,5 @@ export default create({ save: clickable('[data-test-secret-save=""]'), enable: clickable('[data-test-enable-connection=""]'), edit: clickable('[data-test-edit-link="true"]'), + delete: clickable('[data-test-database-connection-delete]'), });