Skip to content

Widen region option in SignatureV4 ctor to accept a region provider and move credentials to be a ctor argument #44

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

Merged
merged 1 commit into from
Aug 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
50 changes: 24 additions & 26 deletions packages/signature-v4/__tests__/SignatureV4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ const MockDate = () => new Date('2000-01-01T00:00:00.000Z');
const signer = new SignatureV4({
service: 'foo',
region: 'us-bar-1',
sha256: Sha256
sha256: Sha256,
credentials: {
accessKeyId: 'foo',
secretAccessKey: 'bar',
}
});

const minimalRequest: HttpRequest<any> = {
Expand All @@ -52,7 +56,6 @@ describe('SignatureV4', () => {
it('should sign requests without bodies', async () => {
const {query} = await signer.presignRequest({
request: minimalRequest,
credentials,
expiration,
currentDateConstructor: MockDate as any,
});
Expand All @@ -72,7 +75,6 @@ describe('SignatureV4', () => {
...minimalRequest,
body: 'It was the best of times, it was the worst of times'
},
credentials,
expiration,
currentDateConstructor: MockDate as any,
});
Expand All @@ -92,7 +94,6 @@ describe('SignatureV4', () => {
...minimalRequest,
body: new Uint8Array([0xde, 0xad, 0xbe, 0xef])
},
credentials,
expiration,
currentDateConstructor: MockDate as any,
});
Expand All @@ -112,7 +113,6 @@ describe('SignatureV4', () => {
...minimalRequest,
body: new PassThrough()
},
credentials,
expiration,
currentDateConstructor: MockDate as any,
});
Expand All @@ -129,12 +129,17 @@ describe('SignatureV4', () => {
it(
`should set and sign the ${TOKEN_QUERY_PARAM} query parameter if the credentials have a session token`,
async () => {
const {query} = await signer.presignRequest({
request: minimalRequest,
const signer = new SignatureV4({
service: 'foo',
region: 'us-bar-1',
sha256: Sha256,
credentials: {
...credentials,
sessionToken: 'baz',
},
}
});
const {query} = await signer.presignRequest({
request: minimalRequest,
expiration,
currentDateConstructor: MockDate as any,
});
Expand All @@ -158,15 +163,15 @@ describe('SignatureV4', () => {
service: 'foo',
region: 'us-bar-1',
sha256: Sha256,
unsignedPayload: true
unsignedPayload: true,
credentials,
});

const {query} = await signer.presignRequest({
request: {
...minimalRequest,
body: new Uint8Array([0xde, 0xad, 0xbe, 0xef]),
},
credentials,
expiration,
currentDateConstructor: MockDate as any,
});
Expand Down Expand Up @@ -196,7 +201,6 @@ describe('SignatureV4', () => {
...minimalRequest,
headers,
},
credentials,
expiration,
hoistHeaders: false,
currentDateConstructor: MockDate as any,
Expand All @@ -223,7 +227,6 @@ describe('SignatureV4', () => {
...minimalRequest,
headers,
},
credentials,
expiration,
hoistHeaders: false,
currentDateConstructor: MockDate as any,
Expand All @@ -243,7 +246,6 @@ describe('SignatureV4', () => {
[EXPIRES_QUERY_PARAM]: '1 week',
}
},
credentials,
expiration,
hoistHeaders: false,
currentDateConstructor: MockDate as any,
Expand All @@ -258,7 +260,6 @@ describe('SignatureV4', () => {
return expect(
signer.presignRequest({
request: minimalRequest,
credentials,
expiration: new Date(),
currentDateConstructor: MockDate as any,
})
Expand All @@ -269,7 +270,6 @@ describe('SignatureV4', () => {
it('should use the current date if no constructor supplied', async () => {
const {query} = await signer.presignRequest({
request: minimalRequest,
credentials,
expiration: Math.floor((Date.now() + 60 * 60 * 1000) / 1000),
});
expect((query as any)[AMZ_DATE_QUERY_PARAM]).toBe(
Expand All @@ -282,7 +282,6 @@ describe('SignatureV4', () => {
it('should sign requests without bodies', async () => {
const {headers} = await signer.signRequest({
request: minimalRequest,
credentials,
currentDateConstructor: MockDate as any,
});
expect(headers[AUTH_HEADER]).toBe(
Expand All @@ -296,7 +295,6 @@ describe('SignatureV4', () => {
...minimalRequest,
body: 'It was the best of times, it was the worst of times'
},
credentials,
currentDateConstructor: MockDate as any,
});
expect(headers[AUTH_HEADER]).toBe(
Expand All @@ -310,7 +308,6 @@ describe('SignatureV4', () => {
...minimalRequest,
body: new Uint8Array([0xde, 0xad, 0xbe, 0xef]),
},
credentials,
currentDateConstructor: MockDate as any,
});
expect(headers[AUTH_HEADER]).toBe(
Expand All @@ -324,7 +321,6 @@ describe('SignatureV4', () => {
...minimalRequest,
body: new PassThrough(),
},
credentials,
currentDateConstructor: MockDate as any,
});

Expand All @@ -337,7 +333,6 @@ describe('SignatureV4', () => {
it(`should set the ${AMZ_DATE_HEADER}`, async () => {
const {headers} = await signer.signRequest({
request: minimalRequest,
credentials,
currentDateConstructor: MockDate as any,
});
expect(headers[AMZ_DATE_HEADER]).toBe('20000101T000000Z');
Expand All @@ -346,12 +341,17 @@ describe('SignatureV4', () => {
it(
`should set and sign the ${TOKEN_HEADER} header if the credentials have a session token`,
async () => {
const {headers} = await signer.signRequest({
request: minimalRequest,
const signer = new SignatureV4({
service: 'foo',
region: 'us-bar-1',
sha256: Sha256,
credentials: {
...credentials,
sessionToken: 'baz',
},
});
const {headers} = await signer.signRequest({
request: minimalRequest,
currentDateConstructor: MockDate as any,
});
expect(headers[AUTH_HEADER]).toBe(
Expand All @@ -367,15 +367,15 @@ describe('SignatureV4', () => {
service: 'foo',
region: 'us-bar-1',
sha256: Sha256,
unsignedPayload: true
unsignedPayload: true,
credentials,
});

const {headers} = await signer.signRequest({
request: {
...minimalRequest,
body: new Uint8Array([0xde, 0xad, 0xbe, 0xef]),
},
credentials,
currentDateConstructor: MockDate as any,
});
expect(headers[AUTH_HEADER]).toBe(
Expand All @@ -388,7 +388,6 @@ describe('SignatureV4', () => {
it('should use the current date if no constructor supplied', async () => {
const {headers} = await signer.signRequest({
request: minimalRequest,
credentials,
});
expect(headers[AMZ_DATE_HEADER]).toBe(
iso8601(new Date()).replace(/[\-:]/g, '')
Expand All @@ -405,7 +404,6 @@ describe('SignatureV4', () => {
'user-agent': 'baz',
},
},
credentials,
currentDateConstructor: MockDate as any,
unsignableHeaders: {foo: true}
});
Expand Down
Loading