Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
added tests to reproduce issue grafana#96
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrygorovych committed Mar 27, 2024
1 parent a09683f commit 1d461d9
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/internal/signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ export function signatureV4TestSuite() {
)
})

describe('#sign should sign requests to target endpoint different from host (proxy use case)', () => {
const { headers } = signer.sign(
{
method: 'POST',
endpoint: new Endpoint('https://target-foo.us-bar-1.amazonaws.com'),
path: '/',
headers: {
host: 'foo.us-bar-1.amazonaws.com',
},
},
{
signingDate: new Date('2000-01-01T00:00:00Z'),
}
)

expect(headers[AUTHORIZATION_HEADER]).to.equal(
'AWS4-HMAC-SHA256 Credential=foo/20000101/us-bar-1/foo/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=1e3b24fcfd7655c0c245d99ba7b6b5ca6174eab903ebfbda09ce457af062ad30'
)
})

describe('#sign should support overriding region and service in the signer instance', () => {
const signer = new SignatureV4({
credentials: credentials,
Expand Down Expand Up @@ -409,6 +429,30 @@ export function signatureV4TestSuite() {
})
})

describe('should presign requests to target endpoint different from host (proxy use case)', () => {
const { query } = signer.presign(
{
method: 'POST',
endpoint: new Endpoint('https://target-foo.us-bar-1.amazonaws.com'),
path: '/',
headers: {
host: 'foo.us-bar-1.amazonaws.com',
},
},
presigningOptions
)

expect(query).to.deep.equal({
[AMZ_ALGORITHM_QUERY_PARAM]: SIGNING_ALGORITHM_IDENTIFIER,
[AMZ_CREDENTIAL_QUERY_PARAM]: 'foo/20000101/us-bar-1/foo/aws4_request',
[AMZ_DATE_QUERY_PARAM]: '20000101T000000Z',
[AMZ_EXPIRES_QUERY_PARAM]: presigningOptions.expiresIn.toString(),
[AMZ_SIGNED_HEADERS_QUERY_PARAM]: HOST_HEADER,
[AMZ_SIGNATURE_QUERY_PARAM]:
'46f0091f3e84cbd4552a184f43830a4f8b42fd18ceaefcdc2c225be1efd9e00e',
})
})

describe('should sign request without hoisting some headers', () => {
const options = JSON.parse(JSON.stringify(presigningOptions))
options.unhoistableHeaders = new Set(['x-amz-not-hoisted'])
Expand Down

0 comments on commit 1d461d9

Please sign in to comment.