@@ -54,6 +54,16 @@ describe("SignatureV4", () => {
54
54
signingDate : new Date ( "2000-01-01T00:00:00.000Z" ) ,
55
55
} ;
56
56
57
+ it ( "should throw on invalid credential" , async ( ) => {
58
+ const signer = new SignatureV4 ( { ...signerInit , credentials : { } as any } ) ;
59
+ try {
60
+ await signer . presign ( minimalRequest , presigningOptions ) ;
61
+ fail ( "This test is expected to fail" ) ;
62
+ } catch ( e ) {
63
+ expect ( e . message ) . toBe ( "Resolved credential object is not valid" ) ;
64
+ }
65
+ } ) ;
66
+
57
67
it ( "should sign requests without bodies" , async ( ) => {
58
68
const { query } = await signer . presign ( minimalRequest , presigningOptions ) ;
59
69
expect ( query ) . toEqual ( {
@@ -364,6 +374,16 @@ describe("SignatureV4", () => {
364
374
} ) ;
365
375
366
376
describe ( "#sign (request)" , ( ) => {
377
+ it ( "should throw on invalid credential" , async ( ) => {
378
+ const signer = new SignatureV4 ( { ...signerInit , credentials : { } as any } ) ;
379
+ try {
380
+ await signer . sign ( minimalRequest ) ;
381
+ fail ( "This test is expected to fail" ) ;
382
+ } catch ( e ) {
383
+ expect ( e . message ) . toBe ( "Resolved credential object is not valid" ) ;
384
+ }
385
+ } ) ;
386
+
367
387
it ( "should sign requests without bodies" , async ( ) => {
368
388
const { headers } = await signer . sign ( minimalRequest , {
369
389
signingDate : new Date ( "2000-01-01T00:00:00.000Z" ) ,
@@ -658,6 +678,16 @@ describe("SignatureV4", () => {
658
678
sha256 : Sha256 ,
659
679
} ;
660
680
681
+ it ( "should throw on invalid credential" , async ( ) => {
682
+ const signer = new SignatureV4 ( { ...signerInit , credentials : { } as any } ) ;
683
+ try {
684
+ await signer . sign ( "STRING_TO_SIGN" ) ;
685
+ fail ( "This test is expected to fail" ) ;
686
+ } catch ( e ) {
687
+ expect ( e . message ) . toBe ( "Resolved credential object is not valid" ) ;
688
+ }
689
+ } ) ;
690
+
661
691
it ( "should produce signatures matching known outputs" , async ( ) => {
662
692
// Example copied from https://github.com/aws/aws-sdk-php/blob/3.42.0/tests/S3/PostObjectV4Test.php#L37
663
693
const signer = new SignatureV4 ( signerInit ) ;
@@ -700,6 +730,25 @@ describe("SignatureV4", () => {
700
730
sha256 : Sha256 ,
701
731
} ;
702
732
733
+ it ( "should throw on invalid credential" , async ( ) => {
734
+ const signer = new SignatureV4 ( { ...signerInit , credentials : { } as any } ) ;
735
+ try {
736
+ await signer . sign (
737
+ {
738
+ headers : Uint8Array . from ( [ 5 , 58 , 100 , 97 , 116 , 101 , 8 , 0 , 0 , 1 , 103 , 247 , 125 , 87 , 112 ] ) ,
739
+ payload : "foo" as any ,
740
+ } ,
741
+ {
742
+ signingDate : new Date ( 1369353600000 ) ,
743
+ priorSignature : "" ,
744
+ }
745
+ ) ;
746
+ fail ( "This test is expected to fail" ) ;
747
+ } catch ( e ) {
748
+ expect ( e . message ) . toBe ( "Resolved credential object is not valid" ) ;
749
+ }
750
+ } ) ;
751
+
703
752
it ( "support event signing" , async ( ) => {
704
753
const signer = new SignatureV4 ( signerInit ) ;
705
754
const eventSignature = await signer . sign (
0 commit comments