From 42b329eb251318cb9451c0289490f7616b879ba9 Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Tue, 22 May 2018 16:49:29 -0500 Subject: [PATCH] fix issue where unwrapping a response with an auth block wouldn't work (#4611) --- ui/app/components/tool-actions-form.js | 7 ++-- ui/tests/acceptance/tools-test.js | 45 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) 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(); + }); +});