@@ -25,7 +25,11 @@ const MockDate = () => new Date('2000-01-01T00:00:00.000Z');
25
25
const signer = new SignatureV4 ( {
26
26
service : 'foo' ,
27
27
region : 'us-bar-1' ,
28
- sha256 : Sha256
28
+ sha256 : Sha256 ,
29
+ credentials : {
30
+ accessKeyId : 'foo' ,
31
+ secretAccessKey : 'bar' ,
32
+ }
29
33
} ) ;
30
34
31
35
const minimalRequest : HttpRequest < any > = {
@@ -52,7 +56,6 @@ describe('SignatureV4', () => {
52
56
it ( 'should sign requests without bodies' , async ( ) => {
53
57
const { query} = await signer . presignRequest ( {
54
58
request : minimalRequest ,
55
- credentials,
56
59
expiration,
57
60
currentDateConstructor : MockDate as any ,
58
61
} ) ;
@@ -72,7 +75,6 @@ describe('SignatureV4', () => {
72
75
...minimalRequest ,
73
76
body : 'It was the best of times, it was the worst of times'
74
77
} ,
75
- credentials,
76
78
expiration,
77
79
currentDateConstructor : MockDate as any ,
78
80
} ) ;
@@ -92,7 +94,6 @@ describe('SignatureV4', () => {
92
94
...minimalRequest ,
93
95
body : new Uint8Array ( [ 0xde , 0xad , 0xbe , 0xef ] )
94
96
} ,
95
- credentials,
96
97
expiration,
97
98
currentDateConstructor : MockDate as any ,
98
99
} ) ;
@@ -112,7 +113,6 @@ describe('SignatureV4', () => {
112
113
...minimalRequest ,
113
114
body : new PassThrough ( )
114
115
} ,
115
- credentials,
116
116
expiration,
117
117
currentDateConstructor : MockDate as any ,
118
118
} ) ;
@@ -129,12 +129,17 @@ describe('SignatureV4', () => {
129
129
it (
130
130
`should set and sign the ${ TOKEN_QUERY_PARAM } query parameter if the credentials have a session token` ,
131
131
async ( ) => {
132
- const { query} = await signer . presignRequest ( {
133
- request : minimalRequest ,
132
+ const signer = new SignatureV4 ( {
133
+ service : 'foo' ,
134
+ region : 'us-bar-1' ,
135
+ sha256 : Sha256 ,
134
136
credentials : {
135
137
...credentials ,
136
138
sessionToken : 'baz' ,
137
- } ,
139
+ }
140
+ } ) ;
141
+ const { query} = await signer . presignRequest ( {
142
+ request : minimalRequest ,
138
143
expiration,
139
144
currentDateConstructor : MockDate as any ,
140
145
} ) ;
@@ -158,15 +163,15 @@ describe('SignatureV4', () => {
158
163
service : 'foo' ,
159
164
region : 'us-bar-1' ,
160
165
sha256 : Sha256 ,
161
- unsignedPayload : true
166
+ unsignedPayload : true ,
167
+ credentials,
162
168
} ) ;
163
169
164
170
const { query} = await signer . presignRequest ( {
165
171
request : {
166
172
...minimalRequest ,
167
173
body : new Uint8Array ( [ 0xde , 0xad , 0xbe , 0xef ] ) ,
168
174
} ,
169
- credentials,
170
175
expiration,
171
176
currentDateConstructor : MockDate as any ,
172
177
} ) ;
@@ -196,7 +201,6 @@ describe('SignatureV4', () => {
196
201
...minimalRequest ,
197
202
headers,
198
203
} ,
199
- credentials,
200
204
expiration,
201
205
hoistHeaders : false ,
202
206
currentDateConstructor : MockDate as any ,
@@ -223,7 +227,6 @@ describe('SignatureV4', () => {
223
227
...minimalRequest ,
224
228
headers,
225
229
} ,
226
- credentials,
227
230
expiration,
228
231
hoistHeaders : false ,
229
232
currentDateConstructor : MockDate as any ,
@@ -243,7 +246,6 @@ describe('SignatureV4', () => {
243
246
[ EXPIRES_QUERY_PARAM ] : '1 week' ,
244
247
}
245
248
} ,
246
- credentials,
247
249
expiration,
248
250
hoistHeaders : false ,
249
251
currentDateConstructor : MockDate as any ,
@@ -258,7 +260,6 @@ describe('SignatureV4', () => {
258
260
return expect (
259
261
signer . presignRequest ( {
260
262
request : minimalRequest ,
261
- credentials,
262
263
expiration : new Date ( ) ,
263
264
currentDateConstructor : MockDate as any ,
264
265
} )
@@ -269,7 +270,6 @@ describe('SignatureV4', () => {
269
270
it ( 'should use the current date if no constructor supplied' , async ( ) => {
270
271
const { query} = await signer . presignRequest ( {
271
272
request : minimalRequest ,
272
- credentials,
273
273
expiration : Math . floor ( ( Date . now ( ) + 60 * 60 * 1000 ) / 1000 ) ,
274
274
} ) ;
275
275
expect ( ( query as any ) [ AMZ_DATE_QUERY_PARAM ] ) . toBe (
@@ -282,7 +282,6 @@ describe('SignatureV4', () => {
282
282
it ( 'should sign requests without bodies' , async ( ) => {
283
283
const { headers} = await signer . signRequest ( {
284
284
request : minimalRequest ,
285
- credentials,
286
285
currentDateConstructor : MockDate as any ,
287
286
} ) ;
288
287
expect ( headers [ AUTH_HEADER ] ) . toBe (
@@ -296,7 +295,6 @@ describe('SignatureV4', () => {
296
295
...minimalRequest ,
297
296
body : 'It was the best of times, it was the worst of times'
298
297
} ,
299
- credentials,
300
298
currentDateConstructor : MockDate as any ,
301
299
} ) ;
302
300
expect ( headers [ AUTH_HEADER ] ) . toBe (
@@ -310,7 +308,6 @@ describe('SignatureV4', () => {
310
308
...minimalRequest ,
311
309
body : new Uint8Array ( [ 0xde , 0xad , 0xbe , 0xef ] ) ,
312
310
} ,
313
- credentials,
314
311
currentDateConstructor : MockDate as any ,
315
312
} ) ;
316
313
expect ( headers [ AUTH_HEADER ] ) . toBe (
@@ -324,7 +321,6 @@ describe('SignatureV4', () => {
324
321
...minimalRequest ,
325
322
body : new PassThrough ( ) ,
326
323
} ,
327
- credentials,
328
324
currentDateConstructor : MockDate as any ,
329
325
} ) ;
330
326
@@ -337,7 +333,6 @@ describe('SignatureV4', () => {
337
333
it ( `should set the ${ AMZ_DATE_HEADER } ` , async ( ) => {
338
334
const { headers} = await signer . signRequest ( {
339
335
request : minimalRequest ,
340
- credentials,
341
336
currentDateConstructor : MockDate as any ,
342
337
} ) ;
343
338
expect ( headers [ AMZ_DATE_HEADER ] ) . toBe ( '20000101T000000Z' ) ;
@@ -346,12 +341,17 @@ describe('SignatureV4', () => {
346
341
it (
347
342
`should set and sign the ${ TOKEN_HEADER } header if the credentials have a session token` ,
348
343
async ( ) => {
349
- const { headers} = await signer . signRequest ( {
350
- request : minimalRequest ,
344
+ const signer = new SignatureV4 ( {
345
+ service : 'foo' ,
346
+ region : 'us-bar-1' ,
347
+ sha256 : Sha256 ,
351
348
credentials : {
352
349
...credentials ,
353
350
sessionToken : 'baz' ,
354
351
} ,
352
+ } ) ;
353
+ const { headers} = await signer . signRequest ( {
354
+ request : minimalRequest ,
355
355
currentDateConstructor : MockDate as any ,
356
356
} ) ;
357
357
expect ( headers [ AUTH_HEADER ] ) . toBe (
@@ -367,15 +367,15 @@ describe('SignatureV4', () => {
367
367
service : 'foo' ,
368
368
region : 'us-bar-1' ,
369
369
sha256 : Sha256 ,
370
- unsignedPayload : true
370
+ unsignedPayload : true ,
371
+ credentials,
371
372
} ) ;
372
373
373
374
const { headers} = await signer . signRequest ( {
374
375
request : {
375
376
...minimalRequest ,
376
377
body : new Uint8Array ( [ 0xde , 0xad , 0xbe , 0xef ] ) ,
377
378
} ,
378
- credentials,
379
379
currentDateConstructor : MockDate as any ,
380
380
} ) ;
381
381
expect ( headers [ AUTH_HEADER ] ) . toBe (
@@ -388,7 +388,6 @@ describe('SignatureV4', () => {
388
388
it ( 'should use the current date if no constructor supplied' , async ( ) => {
389
389
const { headers} = await signer . signRequest ( {
390
390
request : minimalRequest ,
391
- credentials,
392
391
} ) ;
393
392
expect ( headers [ AMZ_DATE_HEADER ] ) . toBe (
394
393
iso8601 ( new Date ( ) ) . replace ( / [ \- : ] / g, '' )
@@ -405,7 +404,6 @@ describe('SignatureV4', () => {
405
404
'user-agent' : 'baz' ,
406
405
} ,
407
406
} ,
408
- credentials,
409
407
currentDateConstructor : MockDate as any ,
410
408
unsignableHeaders : { foo : true }
411
409
} ) ;
0 commit comments