@@ -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
} ) ;
@@ -73,7 +76,6 @@ describe("SignatureV4", () => {
73
76
...minimalRequest ,
74
77
body : "It was the best of times, it was the worst of times"
75
78
} ,
76
- credentials,
77
79
expiration,
78
80
currentDateConstructor : MockDate as any
79
81
} ) ;
@@ -94,7 +96,6 @@ describe("SignatureV4", () => {
94
96
...minimalRequest ,
95
97
body : new Uint8Array ( [ 0xde , 0xad , 0xbe , 0xef ] )
96
98
} ,
97
- credentials,
98
99
expiration,
99
100
currentDateConstructor : MockDate as any
100
101
} ) ;
@@ -115,7 +116,6 @@ describe("SignatureV4", () => {
115
116
...minimalRequest ,
116
117
body : new PassThrough ( )
117
118
} ,
118
- credentials,
119
119
expiration,
120
120
currentDateConstructor : MockDate as any
121
121
} ) ;
@@ -131,12 +131,17 @@ describe("SignatureV4", () => {
131
131
} ) ;
132
132
133
133
it ( `should set and sign the ${ TOKEN_QUERY_PARAM } query parameter if the credentials have a session token` , async ( ) => {
134
- const { query } = await signer . presignRequest ( {
135
- request : minimalRequest ,
134
+ const signer = new SignatureV4 ( {
135
+ service : "foo" ,
136
+ region : "us-bar-1" ,
137
+ sha256 : Sha256 ,
136
138
credentials : {
137
139
...credentials ,
138
140
sessionToken : "baz"
139
- } ,
141
+ }
142
+ } ) ;
143
+ const { query } = await signer . presignRequest ( {
144
+ request : minimalRequest ,
140
145
expiration,
141
146
currentDateConstructor : MockDate as any
142
147
} ) ;
@@ -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
@@ -225,7 +229,6 @@ describe("SignatureV4", () => {
225
229
...minimalRequest ,
226
230
headers
227
231
} ,
228
- credentials,
229
232
expiration,
230
233
hoistHeaders : false ,
231
234
currentDateConstructor : MockDate as any ,
@@ -245,7 +248,6 @@ describe("SignatureV4", () => {
245
248
[ EXPIRES_QUERY_PARAM ] : "1 week"
246
249
}
247
250
} ,
248
- credentials,
249
251
expiration,
250
252
hoistHeaders : false ,
251
253
currentDateConstructor : MockDate as any
@@ -257,7 +259,6 @@ describe("SignatureV4", () => {
257
259
return expect (
258
260
signer . presignRequest ( {
259
261
request : minimalRequest ,
260
- credentials,
261
262
expiration : new Date ( ) ,
262
263
currentDateConstructor : MockDate as any
263
264
} )
@@ -267,7 +268,6 @@ describe("SignatureV4", () => {
267
268
it ( "should use the current date if no constructor supplied" , async ( ) => {
268
269
const { query } = await signer . presignRequest ( {
269
270
request : minimalRequest ,
270
- credentials,
271
271
expiration : Math . floor ( ( Date . now ( ) + 60 * 60 * 1000 ) / 1000 )
272
272
} ) ;
273
273
expect ( ( query as any ) [ AMZ_DATE_QUERY_PARAM ] ) . toBe (
@@ -280,7 +280,6 @@ describe("SignatureV4", () => {
280
280
it ( "should sign requests without bodies" , async ( ) => {
281
281
const { headers } = await signer . signRequest ( {
282
282
request : minimalRequest ,
283
- credentials,
284
283
currentDateConstructor : MockDate as any
285
284
} ) ;
286
285
expect ( headers [ AUTH_HEADER ] ) . toBe (
@@ -294,7 +293,6 @@ describe("SignatureV4", () => {
294
293
...minimalRequest ,
295
294
body : "It was the best of times, it was the worst of times"
296
295
} ,
297
- credentials,
298
296
currentDateConstructor : MockDate as any
299
297
} ) ;
300
298
expect ( headers [ AUTH_HEADER ] ) . toBe (
@@ -308,7 +306,6 @@ describe("SignatureV4", () => {
308
306
...minimalRequest ,
309
307
body : new Uint8Array ( [ 0xde , 0xad , 0xbe , 0xef ] )
310
308
} ,
311
- credentials,
312
309
currentDateConstructor : MockDate as any
313
310
} ) ;
314
311
expect ( headers [ AUTH_HEADER ] ) . toBe (
@@ -322,7 +319,6 @@ describe("SignatureV4", () => {
322
319
...minimalRequest ,
323
320
body : new PassThrough ( )
324
321
} ,
325
- credentials,
326
322
currentDateConstructor : MockDate as any
327
323
} ) ;
328
324
@@ -335,19 +331,23 @@ describe("SignatureV4", () => {
335
331
it ( `should set the ${ AMZ_DATE_HEADER } ` , async ( ) => {
336
332
const { headers } = await signer . signRequest ( {
337
333
request : minimalRequest ,
338
- credentials,
339
334
currentDateConstructor : MockDate as any
340
335
} ) ;
341
336
expect ( headers [ AMZ_DATE_HEADER ] ) . toBe ( "20000101T000000Z" ) ;
342
337
} ) ;
343
338
344
339
it ( `should set and sign the ${ TOKEN_HEADER } header if the credentials have a session token` , async ( ) => {
345
- const { headers } = await signer . signRequest ( {
346
- request : minimalRequest ,
340
+ const signer = new SignatureV4 ( {
341
+ service : "foo" ,
342
+ region : "us-bar-1" ,
343
+ sha256 : Sha256 ,
347
344
credentials : {
348
345
...credentials ,
349
346
sessionToken : "baz"
350
- } ,
347
+ }
348
+ } ) ;
349
+ const { headers } = await signer . signRequest ( {
350
+ request : minimalRequest ,
351
351
currentDateConstructor : MockDate as any
352
352
} ) ;
353
353
expect ( headers [ AUTH_HEADER ] ) . toBe (
@@ -360,15 +360,15 @@ describe("SignatureV4", () => {
360
360
service : "foo" ,
361
361
region : "us-bar-1" ,
362
362
sha256 : Sha256 ,
363
- unsignedPayload : true
363
+ unsignedPayload : true ,
364
+ credentials
364
365
} ) ;
365
366
366
367
const { headers } = await signer . signRequest ( {
367
368
request : {
368
369
...minimalRequest ,
369
370
body : new Uint8Array ( [ 0xde , 0xad , 0xbe , 0xef ] )
370
371
} ,
371
- credentials,
372
372
currentDateConstructor : MockDate as any
373
373
} ) ;
374
374
expect ( headers [ AUTH_HEADER ] ) . toBe (
@@ -379,8 +379,7 @@ describe("SignatureV4", () => {
379
379
380
380
it ( "should use the current date if no constructor supplied" , async ( ) => {
381
381
const { headers } = await signer . signRequest ( {
382
- request : minimalRequest ,
383
- credentials
382
+ request : minimalRequest
384
383
} ) ;
385
384
expect ( headers [ AMZ_DATE_HEADER ] ) . toBe (
386
385
iso8601 ( new Date ( ) ) . replace ( / [ \- : ] / g, "" )
@@ -397,7 +396,6 @@ describe("SignatureV4", () => {
397
396
"user-agent" : "baz"
398
397
}
399
398
} ,
400
- credentials,
401
399
currentDateConstructor : MockDate as any ,
402
400
unsignableHeaders : { foo : true }
403
401
} ) ;
0 commit comments