Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: Update KV data when you change the version of a nested secret #25152

Merged
merged 9 commits into from
Feb 1, 2024
3 changes: 3 additions & 0 deletions changelog/25152.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Update the KV secret data when you change the version you're viewing of a nested secret.
```
2 changes: 1 addition & 1 deletion ui/lib/kv/addon/components/kv-data-fields.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{{#if @showJson}}
<JsonEditor
@title="{{if (eq @type 'create') 'Secret' 'Version'}} data"
@value={{this.codeMirrorString}}
@value={{this.stringifiedSecretData}}
@obscure={{@obscureJson}}
@valueUpdated={{this.handleJson}}
@readOnly={{eq @type "details"}}
Expand Down
9 changes: 2 additions & 7 deletions ui/lib/kv/addon/components/kv-data-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ import { stringify } from 'core/helpers/stringify';

export default class KvDataFields extends Component {
@tracked lintingErrors;
@tracked codeMirrorString;

constructor() {
super(...arguments);
this.codeMirrorString = this.args.secret?.secretData
? stringify([this.args.secret.secretData], {})
: '{ "": "" }';
get stringifiedSecretData() {
return this.args.secret?.secretData ? stringify([this.args.secret.secretData], {}) : '{ "": "" }';
}

@action
Expand All @@ -45,6 +41,5 @@ export default class KvDataFields extends Component {
if (!this.lintingErrors) {
this.args.secret.secretData = JSON.parse(value);
}
this.codeMirrorString = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,43 @@ module('Acceptance | kv-v2 workflow | edge cases', function (hooks) {
assert.dom(FORM.toggleJson).isChecked();
assert.false(codemirror().getValue().includes('*'), 'Values are not obscured on edit view');
});

test('viewing advanced secret data versions displays the correct version data', async function (assert) {
assert.expect(2);
const obscuredDataV1 = `{
"foo1": {
"name": "********"
}
}`;
const obscuredDataV2 = `{
"foo2": {
"name": "********"
}
}`;

await visit(`/vault/secrets/${this.backend}/kv/create`);
await fillIn(FORM.inputByAttr('path'), 'complex_version_test');

await click(FORM.toggleJson);
codemirror().setValue('{ "foo1": { "name": "bar1" } }');
await click(FORM.saveBtn);

// Create another version
await click(PAGE.detail.createNewVersion);
codemirror().setValue('{ "foo2": { "name": "bar2" } }');
await click(FORM.saveBtn);

// View the first version and make sure the secret data is correct
await click(PAGE.detail.versionDropdown);
await click(`${PAGE.detail.version(1)} a`);
assert.strictEqual(codemirror().getValue(), obscuredDataV1, 'Version one data is displayed');

// Navigate back the second version and make sure the secret data is correct
await click(PAGE.detail.versionDropdown);
await click(`${PAGE.detail.version(2)} a`);
assert.strictEqual(codemirror().getValue(), obscuredDataV2, 'Version two data is displayed');
});

test('does not register as advanced when value includes {', async function (assert) {
await visit(`/vault/secrets/${this.backend}/kv/create`);
await fillIn(FORM.inputByAttr('path'), 'not-advanced');
Expand Down
Loading