-
Notifications
You must be signed in to change notification settings - Fork 4.6k
UI: Add KV view for wrap tool #29677
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d9d2cb5
add kv view for wrap tool
lane-wetmore 8d4c220
Merge branch 'main' into ui/VAULT-33463-add-kv-view-in-wrap
lane-wetmore 2148968
add changelog entry
lane-wetmore 7a6320a
update toggle and tests
lane-wetmore 54a97b9
update changelog, style updates, fix linting error bug
lane-wetmore cb93b73
update tests
lane-wetmore cca8f0d
update test to include multiline input
lane-wetmore 55c44fb
clean up
lane-wetmore d748f28
test improvements and clean up
lane-wetmore 2caf385
shift away from disabling button on error
lane-wetmore 6ac5d00
update test for json lint warning
lane-wetmore f1d7d1d
add check after back
lane-wetmore fe1ef8f
move assertions to a better test for them
lane-wetmore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ```release-note:improvement | ||
| ui: adds key value pair string inputs as optional form for wrap tool | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,8 +37,13 @@ module('Integration | Component | tools/wrap', function (hooks) { | |
| await this.renderComponent(); | ||
|
|
||
| assert.dom('h1').hasText('Wrap Data', 'Title renders'); | ||
| assert.dom('label').hasText('Data to wrap (json-formatted)'); | ||
| assert.strictEqual(codemirror().getValue(' '), '{ }', 'json editor initializes with empty object'); | ||
| assert.dom('[data-test-toggle-label="json"]').hasText('JSON'); | ||
| assert.dom('[data-test-component="json-editor-title"]').hasText('Data to wrap (json-formatted)'); | ||
| assert.strictEqual( | ||
| codemirror().getValue(' '), | ||
| `{ \"\": \"\" }`, // eslint-disable-line no-useless-escape | ||
| 'json editor initializes with empty object that includes whitespace' | ||
| ); | ||
| assert.dom(TTL.toggleByLabel('Wrap TTL')).isNotChecked('Wrap TTL defaults to unchecked'); | ||
| assert.dom(TS.submit).isEnabled(); | ||
| assert.dom(TS.toolsInput('wrapping-token')).doesNotExist(); | ||
|
|
@@ -104,6 +109,67 @@ module('Integration | Component | tools/wrap', function (hooks) { | |
| await click(TS.submit); | ||
| }); | ||
|
|
||
| test('it toggles between views and preserves input data', async function (assert) { | ||
lane-wetmore marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert.expect(6); | ||
| await this.renderComponent(); | ||
| await codemirror().setValue(this.wrapData); | ||
| assert.dom('[data-test-component="json-editor-title"]').hasText('Data to wrap (json-formatted)'); | ||
| await click('[data-test-toggle-input="json"]'); | ||
| assert.dom('[data-test-component="json-editor-title"]').doesNotExist(); | ||
lane-wetmore marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert.dom('[data-test-kv-key="0"]').hasValue('foo'); | ||
| assert.dom('[data-test-kv-value="0"]').hasValue('bar'); | ||
| await click('[data-test-toggle-input="json"]'); | ||
| assert.dom('[data-test-component="json-editor-title"]').exists(); | ||
| assert.strictEqual( | ||
| codemirror().getValue(' '), | ||
| `{ \"foo": \"bar" }`, // eslint-disable-line no-useless-escape | ||
| 'json editor has original data' | ||
| ); | ||
| }); | ||
|
|
||
| test('it submits from kv view', async function (assert) { | ||
| assert.expect(6); | ||
|
|
||
| const multilineData = `this is a multi-line secret | ||
lane-wetmore marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| that contains | ||
| some seriously important config`; | ||
| const flashSpy = sinon.spy(this.owner.lookup('service:flash-messages'), 'success'); | ||
| const updatedWrapData = JSON.stringify({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to stringify? We can just compare the two objects below, right? (Instead of need to call |
||
| ...JSON.parse(this.wrapData), | ||
| foo: 'bar', | ||
| foo2: multilineData, | ||
| }); | ||
|
|
||
| this.server.post('sys/wrapping/wrap', (schema, { requestBody, requestHeaders }) => { | ||
| const payload = JSON.parse(requestBody); | ||
| assert.propEqual(payload, JSON.parse(updatedWrapData), `payload contains data: ${requestBody}`); | ||
| assert.strictEqual(requestHeaders['X-Vault-Wrap-TTL'], '30m', 'request header has default wrap ttl'); | ||
| return { | ||
| wrap_info: { | ||
| token: this.token, | ||
| accessor: '5yjKx6Om9NmBx1mjiN1aIrnm', | ||
| ttl: 1800, | ||
| creation_time: '2024-06-07T12:02:22.096254-07:00', | ||
| creation_path: 'sys/wrapping/wrap', | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| await this.renderComponent(); | ||
| await click('[data-test-toggle-input="json"]'); | ||
hellobontempo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| await fillIn('[data-test-kv-key="0"]', 'foo'); | ||
| await fillIn('[data-test-kv-value="0"]', 'bar'); | ||
| await click('[data-test-kv-add-row="0"]'); | ||
| await fillIn('[data-test-kv-key="1"]', 'foo2'); | ||
| await fillIn('[data-test-kv-value="1"]', multilineData); | ||
| await click(TS.submit); | ||
| await waitUntil(() => find(TS.toolsInput('wrapping-token'))); | ||
| assert.true(flashSpy.calledWith('Wrap was successful.'), 'it renders success flash'); | ||
| assert.dom(TS.toolsInput('wrapping-token')).hasText(this.token); | ||
| assert.dom('label').hasText('Wrapped token'); | ||
| assert.dom('.CodeMirror').doesNotExist(); | ||
| }); | ||
|
|
||
| test('it resets on done', async function (assert) { | ||
| await this.renderComponent(); | ||
| await codemirror().setValue(this.wrapData); | ||
|
|
@@ -113,7 +179,11 @@ module('Integration | Component | tools/wrap', function (hooks) { | |
|
|
||
| await waitUntil(() => find(TS.button('Done'))); | ||
| await click(TS.button('Done')); | ||
| assert.strictEqual(codemirror().getValue(' '), '{ }', 'json editor resets to empty object'); | ||
| assert.strictEqual( | ||
| codemirror().getValue(' '), | ||
| `{ \"\": \"\" }`, // eslint-disable-line no-useless-escape | ||
| 'json editor initializes with empty object that includes whitespace' | ||
| ); | ||
| assert.dom(TTL.toggleByLabel('Wrap TTL')).isNotChecked('Wrap TTL resets to unchecked'); | ||
| await click(TTL.toggleByLabel('Wrap TTL')); | ||
| assert.dom(TTL.valueInputByLabel('Wrap TTL')).hasValue('30', 'ttl resets to default when toggled'); | ||
|
|
@@ -126,16 +196,51 @@ module('Integration | Component | tools/wrap', function (hooks) { | |
|
|
||
| await waitUntil(() => find(TS.button('Back'))); | ||
| await click(TS.button('Back')); | ||
| assert.strictEqual(codemirror().getValue(' '), `{"foo": "bar"}`, 'json editor has original data'); | ||
| assert.strictEqual( | ||
| codemirror().getValue(' '), | ||
| `{ \"foo": \"bar" }`, // eslint-disable-line no-useless-escape | ||
| 'json editor has original data' | ||
| ); | ||
| assert.dom(TTL.toggleByLabel('Wrap TTL')).isNotChecked('Wrap TTL defaults to unchecked'); | ||
| }); | ||
|
|
||
| test('it disables/enables submit based on json linting', async function (assert) { | ||
| test('it renders/hides warning based on json linting', async function (assert) { | ||
| await this.renderComponent(); | ||
| await codemirror().setValue(`{bad json}`); | ||
| assert.dom(TS.submit).isDisabled('submit disables if json editor has linting errors'); | ||
|
|
||
| assert | ||
| .dom('[data-test-inline-alert]') | ||
| .hasText( | ||
| 'JSON is unparsable. Fix linting errors to avoid data discrepancies.', | ||
| 'Linting error message is shown for json view' | ||
| ); | ||
| await codemirror().setValue(this.wrapData); | ||
| assert.dom(TS.submit).isEnabled('submit reenables if json editor has no linting errors'); | ||
| assert.dom('[data-test-inline-alert]').doesNotExist(); | ||
| }); | ||
|
|
||
| test('it hides json warning on back and on done', async function (assert) { | ||
| await this.renderComponent(); | ||
| await codemirror().setValue(`{bad json}`); | ||
| assert | ||
| .dom('[data-test-inline-alert]') | ||
| .hasText( | ||
| 'JSON is unparsable. Fix linting errors to avoid data discrepancies.', | ||
| 'Linting error message is shown for json view' | ||
| ); | ||
| await click(TS.submit); | ||
| await waitUntil(() => find(TS.button('Done'))); | ||
| await click(TS.button('Done')); | ||
| assert.dom('[data-test-inline-alert]').doesNotExist(); | ||
|
|
||
| await codemirror().setValue(`{bad json}`); | ||
| assert | ||
| .dom('[data-test-inline-alert]') | ||
| .hasText( | ||
| 'JSON is unparsable. Fix linting errors to avoid data discrepancies.', | ||
| 'Linting error message is shown for json view' | ||
| ); | ||
| await click(TS.submit); | ||
| await waitUntil(() => find(TS.button('Back'))); | ||
| await click(TS.button('Back')); | ||
| assert.dom('[data-test-inline-alert]').doesNotExist(); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.