Skip to content

Commit

Permalink
Copy headers (shallow) so the original is not modified
Browse files Browse the repository at this point in the history
Fixes #164

Also update mocha to 10.4
  • Loading branch information
mhart committed May 21, 2024
1 parent 3a89b5f commit 8442685
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aws4.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function RequestSigner(request, credentials) {

if (typeof request === 'string') request = url.parse(request)

var headers = request.headers = (request.headers || {}),
var headers = request.headers = Object.assign({}, (request.headers || {})),
hostParts = (!this.service || !this.region) && this.matchHost(request.hostname || request.host || headers.Host || headers.host)

this.request = request
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"integration": "node ./test/slow.js"
},
"devDependencies": {
"mocha": "^10.2.0",
"mocha": "^10.4.0",
"should": "^13.2.3"
}
}
21 changes: 21 additions & 0 deletions test/fast.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,27 @@ describe('aws4', function() {
})
})

describe('#sign() with copies', function() {
it('should modify request/opts in place and return same object', function() {
var opts = {service: 'sqs'}
var newOpts = aws4.sign(opts)
opts.should.equal(newOpts)
})

it('should not modify existing headers', function() {
var headers = {
'Content-Type': 'application/x-amz-json-1.0',
'X-Amz-Target': 'DynamoDB_20120810.ListTables',
}
var opts = aws4.sign({
service: 'dynamodb',
headers: headers,
body: '{}',
})
opts.headers.should.not.equal(headers)
})
})

describe('#sign() with signQuery', function() {
it('should work with standard services', function() {
var opts = aws4.sign({
Expand Down

0 comments on commit 8442685

Please sign in to comment.