@@ -20,8 +20,6 @@ import {Credentials, HttpRequest} from "@aws/types";
20
20
import { iso8601 } from "@aws/protocol-timestamp" ;
21
21
import { PassThrough } from 'stream' ;
22
22
23
- const MockDate = ( ) => new Date ( '2000-01-01T00:00:00.000Z' ) ;
24
-
25
23
const signer = new SignatureV4 ( {
26
24
service : 'foo' ,
27
25
region : 'us-bar-1' ,
@@ -50,14 +48,14 @@ const credentials: Credentials = {
50
48
describe ( 'SignatureV4' , ( ) => {
51
49
describe ( '#presignRequest' , ( ) => {
52
50
const expiration = Math . floor (
53
- ( MockDate ( ) . valueOf ( ) + 60 * 60 * 1000 ) / 1000
51
+ ( ( new Date ( '2000-01-01T00:00:00.000Z' ) ) . valueOf ( ) + 60 * 60 * 1000 ) / 1000
54
52
) ;
55
53
56
54
it ( 'should sign requests without bodies' , async ( ) => {
57
55
const { query} = await signer . presignRequest ( {
58
56
request : minimalRequest ,
59
57
expiration,
60
- currentDateConstructor : MockDate as any ,
58
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
61
59
} ) ;
62
60
expect ( query ) . toEqual ( {
63
61
[ ALGORITHM_QUERY_PARAM ] : ALGORITHM_IDENTIFIER ,
@@ -76,7 +74,7 @@ describe('SignatureV4', () => {
76
74
body : 'It was the best of times, it was the worst of times'
77
75
} ,
78
76
expiration,
79
- currentDateConstructor : MockDate as any ,
77
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
80
78
} ) ;
81
79
expect ( query ) . toEqual ( {
82
80
[ ALGORITHM_QUERY_PARAM ] : ALGORITHM_IDENTIFIER ,
@@ -95,7 +93,7 @@ describe('SignatureV4', () => {
95
93
body : new Uint8Array ( [ 0xde , 0xad , 0xbe , 0xef ] )
96
94
} ,
97
95
expiration,
98
- currentDateConstructor : MockDate as any ,
96
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
99
97
} ) ;
100
98
expect ( query ) . toEqual ( {
101
99
[ ALGORITHM_QUERY_PARAM ] : ALGORITHM_IDENTIFIER ,
@@ -114,7 +112,7 @@ describe('SignatureV4', () => {
114
112
body : new PassThrough ( )
115
113
} ,
116
114
expiration,
117
- currentDateConstructor : MockDate as any ,
115
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
118
116
} ) ;
119
117
expect ( query ) . toEqual ( {
120
118
[ ALGORITHM_QUERY_PARAM ] : ALGORITHM_IDENTIFIER ,
@@ -141,7 +139,7 @@ describe('SignatureV4', () => {
141
139
const { query} = await signer . presignRequest ( {
142
140
request : minimalRequest ,
143
141
expiration,
144
- currentDateConstructor : MockDate as any ,
142
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
145
143
} ) ;
146
144
147
145
expect ( query ) . toEqual ( {
@@ -173,7 +171,7 @@ describe('SignatureV4', () => {
173
171
body : new Uint8Array ( [ 0xde , 0xad , 0xbe , 0xef ] ) ,
174
172
} ,
175
173
expiration,
176
- currentDateConstructor : MockDate as any ,
174
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
177
175
} ) ;
178
176
179
177
expect ( query ) . toEqual ( {
@@ -203,7 +201,7 @@ describe('SignatureV4', () => {
203
201
} ,
204
202
expiration,
205
203
hoistHeaders : false ,
206
- currentDateConstructor : MockDate as any ,
204
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
207
205
} ) ;
208
206
expect ( query ) . toEqual ( {
209
207
[ ALGORITHM_QUERY_PARAM ] : ALGORITHM_IDENTIFIER ,
@@ -229,7 +227,7 @@ describe('SignatureV4', () => {
229
227
} ,
230
228
expiration,
231
229
hoistHeaders : false ,
232
- currentDateConstructor : MockDate as any ,
230
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
233
231
unsignableHeaders : { foo : true }
234
232
} ) ;
235
233
expect ( ( query as any ) [ SIGNED_HEADERS_QUERY_PARAM ] ) . toBe ( 'host;user-agent' ) ;
@@ -248,7 +246,7 @@ describe('SignatureV4', () => {
248
246
} ,
249
247
expiration,
250
248
hoistHeaders : false ,
251
- currentDateConstructor : MockDate as any ,
249
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
252
250
} ) ;
253
251
expect ( query [ EXPIRES_QUERY_PARAM ] ) . toBe ( '3600' ) ;
254
252
}
@@ -261,7 +259,7 @@ describe('SignatureV4', () => {
261
259
signer . presignRequest ( {
262
260
request : minimalRequest ,
263
261
expiration : new Date ( ) ,
264
- currentDateConstructor : MockDate as any ,
262
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
265
263
} )
266
264
) . rejects . toMatch ( / l e s s t h a n o n e w e e k i n t h e f u t u r e / ) ;
267
265
}
@@ -282,7 +280,7 @@ describe('SignatureV4', () => {
282
280
it ( 'should sign requests without bodies' , async ( ) => {
283
281
const { headers} = await signer . signRequest ( {
284
282
request : minimalRequest ,
285
- currentDateConstructor : MockDate as any ,
283
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
286
284
} ) ;
287
285
expect ( headers [ AUTH_HEADER ] ) . toBe (
288
286
'AWS4-HMAC-SHA256 Credential=foo/20000101/us-bar-1/foo/aws4_request, SignedHeaders=host;x-amz-date, Signature=9fd83bc86a8d79b30697566790e40f832f280c9d7cbb343b213d1544a0273ebb'
@@ -295,7 +293,7 @@ describe('SignatureV4', () => {
295
293
...minimalRequest ,
296
294
body : 'It was the best of times, it was the worst of times'
297
295
} ,
298
- currentDateConstructor : MockDate as any ,
296
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
299
297
} ) ;
300
298
expect ( headers [ AUTH_HEADER ] ) . toBe (
301
299
'AWS4-HMAC-SHA256 Credential=foo/20000101/us-bar-1/foo/aws4_request, SignedHeaders=host;x-amz-date, Signature=b281e6664227db05f6f161b1d9725e030f9c2cddb91b42f8b93d7cbffa7eb796'
@@ -308,7 +306,7 @@ describe('SignatureV4', () => {
308
306
...minimalRequest ,
309
307
body : new Uint8Array ( [ 0xde , 0xad , 0xbe , 0xef ] ) ,
310
308
} ,
311
- currentDateConstructor : MockDate as any ,
309
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
312
310
} ) ;
313
311
expect ( headers [ AUTH_HEADER ] ) . toBe (
314
312
'AWS4-HMAC-SHA256 Credential=foo/20000101/us-bar-1/foo/aws4_request, SignedHeaders=host;x-amz-date, Signature=a8def96b8c754e523927d6a49392c02ff803ee49dc56549e244daf3f62b4abdd'
@@ -321,7 +319,7 @@ describe('SignatureV4', () => {
321
319
...minimalRequest ,
322
320
body : new PassThrough ( ) ,
323
321
} ,
324
- currentDateConstructor : MockDate as any ,
322
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
325
323
} ) ;
326
324
327
325
expect ( headers [ AUTH_HEADER ] ) . toBe (
@@ -333,7 +331,7 @@ describe('SignatureV4', () => {
333
331
it ( `should set the ${ AMZ_DATE_HEADER } ` , async ( ) => {
334
332
const { headers} = await signer . signRequest ( {
335
333
request : minimalRequest ,
336
- currentDateConstructor : MockDate as any ,
334
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
337
335
} ) ;
338
336
expect ( headers [ AMZ_DATE_HEADER ] ) . toBe ( '20000101T000000Z' ) ;
339
337
} ) ;
@@ -352,7 +350,7 @@ describe('SignatureV4', () => {
352
350
} ) ;
353
351
const { headers} = await signer . signRequest ( {
354
352
request : minimalRequest ,
355
- currentDateConstructor : MockDate as any ,
353
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
356
354
} ) ;
357
355
expect ( headers [ AUTH_HEADER ] ) . toBe (
358
356
'AWS4-HMAC-SHA256 Credential=foo/20000101/us-bar-1/foo/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token, Signature=772bb343901420732ab811c947f90e1fafbc3b88697bad072b436a4e895b4bfc'
@@ -376,7 +374,7 @@ describe('SignatureV4', () => {
376
374
...minimalRequest ,
377
375
body : new Uint8Array ( [ 0xde , 0xad , 0xbe , 0xef ] ) ,
378
376
} ,
379
- currentDateConstructor : MockDate as any ,
377
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
380
378
} ) ;
381
379
expect ( headers [ AUTH_HEADER ] ) . toBe (
382
380
'AWS4-HMAC-SHA256 Credential=foo/20000101/us-bar-1/foo/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=2d17bf1aa1624819549626389790503937599b27a998286e0e190b897b1467dd'
@@ -385,7 +383,7 @@ describe('SignatureV4', () => {
385
383
}
386
384
) ;
387
385
388
- it ( 'should use the current date if no constructor supplied' , async ( ) => {
386
+ it ( 'should use the current date if no signing date supplied' , async ( ) => {
389
387
const { headers} = await signer . signRequest ( {
390
388
request : minimalRequest ,
391
389
} ) ;
@@ -404,7 +402,7 @@ describe('SignatureV4', () => {
404
402
'user-agent' : 'baz' ,
405
403
} ,
406
404
} ,
407
- currentDateConstructor : MockDate as any ,
405
+ signingDate : new Date ( '2000-01-01T00:00:00.000Z' ) ,
408
406
unsignableHeaders : { foo : true }
409
407
} ) ;
410
408
expect ( headers [ AUTH_HEADER ] ) . toMatch (
0 commit comments