diff --git a/ui/app/components/tool-actions-form.js b/ui/app/components/tool-actions-form.js index c89cc41917d9..0f09e9dda430 100644 --- a/ui/app/components/tool-actions-form.js +++ b/ui/app/components/tool-actions-form.js @@ -71,10 +71,11 @@ export default Ember.Component.extend(DEFAULTS, { handleSuccess(resp, action) { let props = {}; - if (resp && resp.data && action === 'unwrap') { - props = Ember.assign({}, props, { unwrap_data: resp.data }); + let secret = resp && resp.data || resp.auth; + if (secret && action === 'unwrap') { + props = Ember.assign({}, props, { unwrap_data: secret }); } - props = Ember.assign({}, props, resp.data); + props = Ember.assign({}, props, secret); if (resp && resp.wrap_info) { const keyName = action === 'rewrap' ? 'rewrap_token' : 'token'; diff --git a/ui/tests/acceptance/tools-test.js b/ui/tests/acceptance/tools-test.js index 7db50fbba2e6..7a108eb3e2c2 100644 --- a/ui/tests/acceptance/tools-test.js +++ b/ui/tests/acceptance/tools-test.js @@ -1,3 +1,4 @@ +import Pretender from 'pretender'; import { test } from 'qunit'; import moduleForAcceptance from 'vault/tests/helpers/module-for-acceptance'; import { toolsActions } from 'vault/helpers/tools-actions'; @@ -133,3 +134,47 @@ test('tools functionality', function(assert) { ); }); }); + +const AUTH_RESPONSE = { + "request_id": "39802bc4-235c-2f0b-87f3-ccf38503ac3e", + "lease_id": "", + "renewable": false, + "lease_duration": 0, + "data": null, + "wrap_info": null, + "warnings": null, + "auth": { + "client_token": "ecfc2758-588e-981d-50f4-a25883bbf03c", + "accessor": "6299780b-f2b2-1a3f-7b83-9d3d67629249", + "policies": [ + "root" + ], + "metadata": null, + "lease_duration": 0, + "renewable": false, + "entity_id": "" + } +}; + +test('ensure unwrap with auth block works properly', function(assert) { + this.server = new Pretender(function() { + this.post('/v1/sys/wrapping/unwrap', response => { + return [response, { 'Content-Type': 'application/json' }, JSON.stringify(AUTH_RESPONSE)]; + }); + }); + visit('/vault/tools'); + //unwrap + click('[data-test-tools-action-link="unwrap"]'); + andThen(() => { + fillIn('[data-test-tools-input="wrapping-token"]', 'sometoken'); + }); + click('[data-test-tools-submit]'); + andThen(() => { + assert.deepEqual( + JSON.parse(find('.CodeMirror').get(0).CodeMirror.getValue()), + AUTH_RESPONSE.auth, + 'unwrapped data equals input data' + ); + this.server.shutdown(); + }); +});