Skip to content

Commit

Permalink
fix issue where unwrapping a response with an auth block wouldn't work (
Browse files Browse the repository at this point in the history
  • Loading branch information
meirish authored May 22, 2018
1 parent 1fb28cf commit 42b329e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ui/app/components/tool-actions-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
45 changes: 45 additions & 0 deletions ui/tests/acceptance/tools-test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();
});
});

0 comments on commit 42b329e

Please sign in to comment.