@@ -29,7 +29,7 @@ import {
29
29
SignerExceptionMessages ,
30
30
} from '../src/signer' ;
31
31
import { encodeURI , formatAsUTCISO , qsStringify } from '../src/util' ;
32
- import { ExceptionMessages } from '../src/storage' ;
32
+ import { Storage , ExceptionMessages } from '../src/storage' ;
33
33
import { OutgoingHttpHeaders } from 'http' ;
34
34
35
35
interface SignedUrlArgs {
@@ -56,7 +56,7 @@ describe('signer', () => {
56
56
let bucket : BucketI ;
57
57
let file : FileI ;
58
58
59
- const NOW = new Date ( '2019-03-18T00:00:00Z ' ) ;
59
+ const NOW = new Date ( '2019-03-18T00:00:00.999Z ' ) ;
60
60
let fakeTimers : sinon . SinonFakeTimers ;
61
61
62
62
beforeEach ( ( ) => ( fakeTimers = sinon . useFakeTimers ( NOW ) ) ) ;
@@ -554,7 +554,7 @@ describe('signer', () => {
554
554
signer = new URLSigner ( authClient , bucket , file ) ;
555
555
CONFIG = {
556
556
method : 'GET' ,
557
- expiration : Math . floor ( ( NOW . valueOf ( ) + 2000 ) / 1000 ) ,
557
+ expiration : ( NOW . valueOf ( ) + 2000 ) / 1000 ,
558
558
bucket : bucket . name ,
559
559
} ;
560
560
} ) ;
@@ -573,6 +573,52 @@ describe('signer', () => {
573
573
) ;
574
574
} ) ;
575
575
576
+ it ( 'should not throw with expiration of exactly 7 days' , async ( ) => {
577
+ const file = new Storage ( {
578
+ projectId : 'xxxx' ,
579
+ credentials : {
580
+ type : 'service_account' ,
581
+ private_key : crypto . generateKeyPairSyn c ( 'rsa' , {
582
+ modulusLength : 512 ,
583
+ publicKeyEncoding : {
584
+ type : 'spki' ,
585
+ format : 'pem' ,
586
+ } ,
587
+ privateKeyEncoding : {
588
+ type : 'pkcs8' ,
589
+ format : 'pem' ,
590
+ } ,
591
+ } ) . privateKey ,
592
+ client_email : 'xxxx' ,
593
+ client_id : 'xxx' ,
594
+ } ,
595
+ } )
596
+ . bucket ( BUCKET_NAME )
597
+ . file ( FILE_NAME ) ;
598
+ const ACCESSIBLE_AT = NOW . valueOf ( ) ;
599
+ const SEVEN_DAYS_IN_SECONDS = 7 * 24 * 60 * 60 ;
600
+ const SEVEN_DAYS_IN_MS = SEVEN_DAYS_IN_SECONDS * 1000 ;
601
+ await assert . doesNotReject (
602
+ async ( ) => {
603
+ await file . getSignedUrl ( {
604
+ version : 'v4' ,
605
+ action : 'read' ,
606
+ accessibleAt : ACCESSIBLE_AT ,
607
+ expires : ACCESSIBLE_AT + SEVEN_DAYS_IN_MS ,
608
+ virtualHostedStyle : true ,
609
+ } ) ;
610
+ } ,
611
+ err => {
612
+ assert ( err instanceof Error ) ;
613
+ assert . strictEqual (
614
+ err . message ,
615
+ `Max allowed expiration is seven days (${ SEVEN_DAYS_IN_SECONDS } seconds).`
616
+ ) ;
617
+ return true ;
618
+ }
619
+ ) ;
620
+ } ) ;
621
+
576
622
describe ( 'headers' , ( ) => {
577
623
it ( 'should add path-styled host header' , async ( ) => {
578
624
const getCanonicalHeaders = sandbox
@@ -988,7 +1034,7 @@ describe('signer', () => {
988
1034
989
1035
it ( 'returns expiration date in seconds' , ( ) => {
990
1036
const expires = signer . parseExpires ( NOW ) ;
991
- assert . strictEqual ( expires , Math . round ( NOW . valueOf ( ) / 1000 ) ) ;
1037
+ assert . strictEqual ( expires , Math . floor ( NOW . valueOf ( ) / 1000 ) ) ;
992
1038
} ) ;
993
1039
} ) ;
994
1040
} ) ;
0 commit comments