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

fix issue where unwrapping a response with an auth block wouldn't work #4611

Merged
merged 2 commits into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});