mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 02:57:59 +00:00
UI: Fix updating static roles via role edit page on UI (#29498)
* added check for updating static roles, appending full payload data * pulling specific properties into payload obj to fix popups * adding changelog * add else to keep previous imp for dynamic roles * removing separate request, utilizing snapshot * renamed serialized data var, added comment for required username line * adding test for editing static role * updated test for edit payload * Update changelog/29498.txt Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com> --------- Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>
This commit is contained in:
3
changelog/29498.txt
Normal file
3
changelog/29498.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:bug
|
||||||
|
ui/database: Fixes 'cannot update static username' error when updating static role's rotation period
|
||||||
|
```
|
||||||
@@ -195,10 +195,19 @@ export default ApplicationAdapter.extend({
|
|||||||
|
|
||||||
async updateRecord(store, type, snapshot) {
|
async updateRecord(store, type, snapshot) {
|
||||||
const serializer = store.serializerFor(type.modelName);
|
const serializer = store.serializerFor(type.modelName);
|
||||||
const data = serializer.serialize(snapshot);
|
const serializedData = serializer.serialize(snapshot);
|
||||||
const roleType = snapshot.attr('type');
|
const roleType = snapshot.attr('type');
|
||||||
const backend = snapshot.attr('backend');
|
const backend = snapshot.attr('backend');
|
||||||
const id = snapshot.attr('name');
|
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);
|
return this.ajax(this.urlFor(backend, id, roleType), 'POST', { data }).then(() => data);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { render } from '@ember/test-helpers';
|
|||||||
import { hbs } from 'ember-cli-htmlbars';
|
import { hbs } from 'ember-cli-htmlbars';
|
||||||
import { setupMirage } from 'ember-cli-mirage/test-support';
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
||||||
import { capabilitiesStub } from 'vault/tests/helpers/stubs';
|
import { capabilitiesStub } from 'vault/tests/helpers/stubs';
|
||||||
|
import { click, fillIn } from '@ember/test-helpers';
|
||||||
|
|
||||||
module('Integration | Component | database-role-edit', function (hooks) {
|
module('Integration | Component | database-role-edit', function (hooks) {
|
||||||
setupRenderingTest(hooks);
|
setupRenderingTest(hooks);
|
||||||
@@ -20,6 +21,7 @@ module('Integration | Component | database-role-edit', function (hooks) {
|
|||||||
modelName: 'database/role',
|
modelName: 'database/role',
|
||||||
database: ['my-mongodb-database'],
|
database: ['my-mongodb-database'],
|
||||||
backend: 'database',
|
backend: 'database',
|
||||||
|
username: 'staticTestUser',
|
||||||
type: 'static',
|
type: 'static',
|
||||||
name: 'my-static-role',
|
name: 'my-static-role',
|
||||||
id: 'my-static-role',
|
id: 'my-static-role',
|
||||||
@@ -36,6 +38,26 @@ module('Integration | Component | database-role-edit', function (hooks) {
|
|||||||
this.modelDynamic = this.store.peekRecord('database/role', 'my-dynamic-role');
|
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) {
|
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']));
|
this.server.post('/sys/capabilities-self', capabilitiesStub('database/static-creds/my-role', ['read']));
|
||||||
await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="show"/>`);
|
await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="show"/>`);
|
||||||
|
|||||||
Reference in New Issue
Block a user