Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a81a27d
added check for updating static roles, appending full payload data
drivera258 Feb 4, 2025
3b468a1
pulling specific properties into payload obj to fix popups
drivera258 Feb 4, 2025
2b3ce76
Merge branch 'main' into ui/VAULT-33437/update-static-roles
drivera258 Feb 4, 2025
3cac617
Merge branch 'main' into ui/VAULT-33437/update-static-roles
drivera258 Feb 4, 2025
c704c9c
adding changelog
drivera258 Feb 4, 2025
4ad7c6a
Merge branch 'main' into ui/VAULT-33437/update-static-roles
drivera258 Feb 4, 2025
102827f
add else to keep previous imp for dynamic roles
drivera258 Feb 4, 2025
2da43af
Merge branch 'main' into ui/VAULT-33437/update-static-roles
drivera258 Feb 4, 2025
fca1704
removing separate request, utilizing snapshot
drivera258 Feb 5, 2025
4c32caa
renamed serialized data var, added comment for required username line
drivera258 Feb 5, 2025
4960475
Merge branch 'main' into ui/VAULT-33437/update-static-roles
drivera258 Feb 5, 2025
7a005ae
adding test for editing static role
drivera258 Feb 5, 2025
a0aaf1b
Merge branch 'main' into ui/VAULT-33437/update-static-roles
drivera258 Feb 5, 2025
7ed26a3
updated test for edit payload
drivera258 Feb 6, 2025
802809a
Merge branch 'main' into ui/VAULT-33437/update-static-roles
drivera258 Feb 6, 2025
7f03788
Merge branch 'main' into ui/VAULT-33437/update-static-roles
drivera258 Feb 7, 2025
dcf1480
Merge branch 'main' into ui/VAULT-33437/update-static-roles
drivera258 Feb 7, 2025
29760aa
Merge branch 'main' into ui/VAULT-33437/update-static-roles
drivera258 Feb 10, 2025
dd86c18
Update changelog/29498.txt
drivera258 Feb 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/29498.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui/database: Fixes 'cannot update static username' error when updating static role's rotation period
```
11 changes: 10 additions & 1 deletion ui/app/adapters/database/role.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,19 @@ export default ApplicationAdapter.extend({

async updateRecord(store, type, snapshot) {
const serializer = store.serializerFor(type.modelName);
const data = serializer.serialize(snapshot);
const serializedData = serializer.serialize(snapshot);
const roleType = snapshot.attr('type');
const backend = snapshot.attr('backend');
const id = snapshot.attr('name');
let data = {};
if (roleType === 'static') {
data = {
...serializedData,
username: snapshot.attr('username'), // username is required for updating a static role
};
} else {
data = serializedData;
}

return this.ajax(this.urlFor(backend, id, roleType), 'POST', { data }).then(() => data);
},
Expand Down
22 changes: 22 additions & 0 deletions ui/tests/integration/components/database-role-edit-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { capabilitiesStub } from 'vault/tests/helpers/stubs';
import { click, fillIn } from '@ember/test-helpers';

module('Integration | Component | database-role-edit', function (hooks) {
setupRenderingTest(hooks);
Expand All @@ -20,6 +21,7 @@ module('Integration | Component | database-role-edit', function (hooks) {
modelName: 'database/role',
database: ['my-mongodb-database'],
backend: 'database',
username: 'staticTestUser',
type: 'static',
name: 'my-static-role',
id: 'my-static-role',
Expand All @@ -36,6 +38,26 @@ module('Integration | Component | database-role-edit', function (hooks) {
this.modelDynamic = this.store.peekRecord('database/role', 'my-dynamic-role');
});

test('it should let user edit a static role when given update capability', async function (assert) {
this.server.post('/sys/capabilities-self', capabilitiesStub('database/static-creds/my-role', ['update']));

this.server.post(`/database/static-roles/my-static-role`, (schema, req) => {
assert.true(true, 'request made to update static role');
assert.propEqual(
JSON.parse(req.requestBody),
{
username: 'staticTestUser',
rotation_period: '1728000s', // 20 days in seconds
},
'it updates static role with correct payload'
);
});

await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="edit"/>`);
await fillIn('[data-test-ttl-value="Rotation period"]', '20');
await click('[data-test-secret-save]');
});

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`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="show"/>`);
Expand Down
Loading