Skip to content

Commit b5aca27

Browse files
authored
FIX LEB-4935 | Fix header getter in hasValidFetchResponse (#17)
1 parent f06f1a1 commit b5aca27

File tree

10 files changed

+28
-14
lines changed

10 files changed

+28
-14
lines changed

demo/ajax.app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/get.app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/post.app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/es5/hmac.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ var AcquiaHttpHmac = /*#__PURE__*/function () {
579579
}, {
580580
key: "hasValidFetchResponse",
581581
value: function hasValidFetchResponse(responseText, headers, nonce, timestamp) {
582-
return _classPrivateFieldLooseBase(this, _hasValidResponse)[_hasValidResponse](responseText, headers['X-Server-Authorization-HMAC-SHA256'], nonce, timestamp);
582+
return _classPrivateFieldLooseBase(this, _hasValidResponse)[_hasValidResponse](responseText, headers.get('X-Server-Authorization-HMAC-SHA256'), nonce, timestamp);
583583
}
584584
}], [{
585585
key: "isXMLHttpRequest",

lib/es5/hmac.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/es6/hmac.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ class AcquiaHttpHmac {
589589
* TRUE if the request is valid; FALSE otherwise.
590590
*/
591591
hasValidFetchResponse(responseText, headers, nonce, timestamp) {
592-
return _classPrivateFieldLooseBase(this, _hasValidResponse)[_hasValidResponse](responseText, headers['X-Server-Authorization-HMAC-SHA256'], nonce, timestamp);
592+
return _classPrivateFieldLooseBase(this, _hasValidResponse)[_hasValidResponse](responseText, headers.get('X-Server-Authorization-HMAC-SHA256'), nonce, timestamp);
593593
}
594594

595595
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "http-hmac-javascript",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"description": "HTTP HMAC JavaScript Library",
55
"main": "./lib/es5/hmac.js",
66
"dependencies": {

qunit/hmac.tests.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ Math.random = function () {
2121
return 0.123456789;
2222
};
2323

24+
class Headers {
25+
constructor() {
26+
this.headers = {};
27+
}
28+
29+
set(name, value) {
30+
this.headers[name] = value;
31+
}
32+
33+
get(name) {
34+
return this.headers[name];
35+
}
36+
}
37+
2438
QUnit.module('HTTP HMAC JavaScript Library tests', {
2539
setup: function() {
2640
request = new MockHttpRequest();
@@ -439,13 +453,13 @@ QUnit.test('Test hasValidFetchResponse(), asserts pass.', function(assert) {
439453
expect(1);
440454
// A smoke test to confirm it's correctly hooked up. Logic is covered in tests of `hasValidResponse`.
441455
const responseText = 'correct response text';
442-
const headers = {
443-
'X-Server-Authorization-HMAC-SHA256': 'CU0ma6cbZ6wZAsjjKli8ukH8Nxx6kShpTQqxvw08Yns=',
444-
};
445456
const nonce = '480b7e99-d558-4a59-e49a-228ae489561b';
446457
const timestamp = 1000000000;
458+
const headers = new Headers();
459+
460+
headers.set('X-Server-Authorization-HMAC-SHA256', 'CU0ma6cbZ6wZAsjjKli8ukH8Nxx6kShpTQqxvw08Yns=');
447461

448-
var hasValidFetchResponse = HMAC.hasValidFetchResponse(responseText, headers, nonce, timestamp);
462+
const hasValidFetchResponse = HMAC.hasValidFetchResponse(responseText, headers, nonce, timestamp);
449463
assert.ok(hasValidFetchResponse, 'hasValidFetchResponse() asserts pass.');
450464
});
451465

src/hmac.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ class AcquiaHttpHmac {
539539
console.log('signature ', signature);
540540
console.log('server_signature', sha256Header);
541541

542-
return signature === sha256Header;
542+
return signature === sha256Header;
543543
}
544544

545545
/**
@@ -576,7 +576,7 @@ class AcquiaHttpHmac {
576576
hasValidFetchResponse (responseText, headers, nonce, timestamp) {
577577
return this.#hasValidResponse(
578578
responseText,
579-
headers['X-Server-Authorization-HMAC-SHA256'],
579+
headers.get('X-Server-Authorization-HMAC-SHA256'),
580580
nonce,
581581
timestamp,
582582
);

0 commit comments

Comments
 (0)