From dd8a0d57a8ef4a0ecda3f3d80b39aed488e519fd Mon Sep 17 00:00:00 2001 From: Dan Rivera Date: Wed, 19 Feb 2025 18:49:46 -0500 Subject: [PATCH] UI: adding skip import rotation field when creating static roles (#29633) * adding skip import rotation field to ui * changing labels and subtext * removing readonly, user input on edit would not affect value * changelog * fix test * fix test2 --- changelog/29633.txt | 3 +++ ui/app/models/database/role.js | 7 +++++ .../utils/model-helpers/database-helpers.js | 2 +- .../components/database-role-edit-test.js | 26 +++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 changelog/29633.txt diff --git a/changelog/29633.txt b/changelog/29633.txt new file mode 100644 index 0000000000..9df7a4b970 --- /dev/null +++ b/changelog/29633.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui/database: Added input field for setting 'skip_import_rotation' when creating a static role +``` diff --git a/ui/app/models/database/role.js b/ui/app/models/database/role.js index 79f6fbd727..4c75e99601 100644 --- a/ui/app/models/database/role.js +++ b/ui/app/models/database/role.js @@ -54,6 +54,12 @@ export default Model.extend({ 'Specifies the amount of time Vault should wait before rotating the password. The minimum is 5 seconds. Default is 24 hours.', helperTextEnabled: 'Vault will rotate password after', }), + skip_import_rotation: attr({ + label: 'Skip initial rotation', + editType: 'boolean', + defaultValue: false, + subText: 'When unchecked, Vault automatically rotates the password upon creation', + }), creation_statements: attr('array', { editType: 'stringArray', }), @@ -110,6 +116,7 @@ export default Model.extend({ 'max_ttl', 'username', 'rotation_period', + 'skip_import_rotation', 'creation_statements', 'creation_statement', // for editType: JSON 'revocation_statements', diff --git a/ui/app/utils/model-helpers/database-helpers.js b/ui/app/utils/model-helpers/database-helpers.js index d669e36178..085fc8626b 100644 --- a/ui/app/utils/model-helpers/database-helpers.js +++ b/ui/app/utils/model-helpers/database-helpers.js @@ -188,7 +188,7 @@ export const AVAILABLE_PLUGIN_TYPES = [ ]; export const ROLE_FIELDS = { - static: ['username', 'rotation_period'], + static: ['username', 'rotation_period', 'skip_import_rotation'], dynamic: ['default_ttl', 'max_ttl'], }; diff --git a/ui/tests/integration/components/database-role-edit-test.js b/ui/tests/integration/components/database-role-edit-test.js index 113bd818bc..a9ce5aa926 100644 --- a/ui/tests/integration/components/database-role-edit-test.js +++ b/ui/tests/integration/components/database-role-edit-test.js @@ -22,6 +22,7 @@ module('Integration | Component | database-role-edit', function (hooks) { database: ['my-mongodb-database'], backend: 'database', username: 'staticTestUser', + skip_import_rotation: false, type: 'static', name: 'my-static-role', id: 'my-static-role', @@ -58,6 +59,31 @@ module('Integration | Component | database-role-edit', function (hooks) { await click('[data-test-secret-save]'); }); + test('it should successfully create user with skip import rotation', async function (assert) { + this.server.post('/sys/capabilities-self', capabilitiesStub('database/static-creds/my-role', ['create'])); + this.server.post(`/database/static-roles/my-static-role`, (schema, req) => { + assert.true(true, 'request made to create static role'); + assert.propEqual( + JSON.parse(req.requestBody), + { + path: 'static-roles', + username: 'staticTestUser', + rotation_period: '172800s', // 2 days in seconds + skip_import_rotation: true, + }, + 'it creates a static role with correct payload' + ); + }); + + await render(hbs``); + await fillIn('[data-test-ttl-value="Rotation period"]', '2'); + await click('[data-test-input="skip_import_rotation"]'); + await click('[data-test-secret-save]'); + + await render(hbs``); + assert.dom('[data-test-value-div="Skip initial rotation"]').containsText('Yes'); + }); + test('it should show Get credentials button when a user has the correct policy', async function (assert) { this.server.post('/sys/capabilities-self', capabilitiesStub('database/static-creds/my-role', ['read'])); await render(hbs``);