Skip to content

Commit

Permalink
ui: Any per request headers should overwrite any 'global' headers...
Browse files Browse the repository at this point in the history
...not the other way around

Also, 'made sure' data isn't added to the URL for GET requests

Also, added a test that catches and errors before this change happened
With this change the test passes
  • Loading branch information
John Cowen committed Aug 23, 2019
1 parent d942a69 commit 4245db6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
19 changes: 13 additions & 6 deletions ui-v2/app/services/client/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ export default Service.extend({
...{
'Content-Type': 'application/json; charset=utf-8',
},
...createHeaders(temp),
...get(client, 'settings').findHeaders(),
...createHeaders(temp),
};
return new Promise(function(resolve, reject) {
const options = {
Expand Down Expand Up @@ -160,11 +160,18 @@ export default Service.extend({
},
};
if (typeof body !== 'undefined') {
if (method !== 'GET' && headers['Content-Type'].indexOf('json') !== -1) {
options.data = JSON.stringify(body);
} else {
// TODO: Does this need urlencoding? Assuming jQuery does this
options.data = body;
// Only read add HTTP body if we aren't GET
// Right now we do this to avoid having to put data in the templates
// for write-like actions
// potentially we should change things so you _have_ to do that
// as doing it this way is a little magical
if (method !== 'GET') {
if (headers['Content-Type'].indexOf('json') !== -1) {
options.data = JSON.stringify(body);
} else {
// TODO: Does this need urlencoding? Assuming jQuery does this
options.data = body;
}
}
}
options.beforeSend = function(xhr) {
Expand Down
20 changes: 20 additions & 0 deletions ui-v2/tests/acceptance/dc/acls/tokens/login.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@setupApplicationTest
Feature: dc / acls / tokens / login
Scenario: Logging into the ACLs login page
Given 1 datacenter model with the value "dc-1"
And the url "/v1/acl/tokens" responds with a 403 status
When I visit the tokens page for yaml
---
dc: dc-1
---
Then the url should be /dc-1/acls/tokens
And I fill in with yaml
---
secret: something
---
And I submit
Then a GET request is made to "/v1/acl/token/self?dc=dc-1" from yaml
---
headers:
X-Consul-Token: something
---
10 changes: 10 additions & 0 deletions ui-v2/tests/acceptance/steps/dc/acls/tokens/login-steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import steps from '../../../steps';

// step definitions that are shared between features should be moved to the
// tests/acceptance/steps/steps.js file

export default function(assert) {
return steps(assert).then('I should find a file', function() {
assert.ok(true, this.step);
});
}

0 comments on commit 4245db6

Please sign in to comment.