@@ -54,6 +54,16 @@ describe("SignatureV4", () => {
5454 signingDate : new Date ( "2000-01-01T00:00:00.000Z" ) ,
5555 } ;
5656
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+
5767 it ( "should sign requests without bodies" , async ( ) => {
5868 const { query } = await signer . presign ( minimalRequest , presigningOptions ) ;
5969 expect ( query ) . toEqual ( {
@@ -364,6 +374,16 @@ describe("SignatureV4", () => {
364374 } ) ;
365375
366376 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+
367387 it ( "should sign requests without bodies" , async ( ) => {
368388 const { headers } = await signer . sign ( minimalRequest , {
369389 signingDate : new Date ( "2000-01-01T00:00:00.000Z" ) ,
@@ -658,6 +678,16 @@ describe("SignatureV4", () => {
658678 sha256 : Sha256 ,
659679 } ;
660680
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+
661691 it ( "should produce signatures matching known outputs" , async ( ) => {
662692 // Example copied from https://github.com/aws/aws-sdk-php/blob/3.42.0/tests/S3/PostObjectV4Test.php#L37
663693 const signer = new SignatureV4 ( signerInit ) ;
@@ -700,6 +730,25 @@ describe("SignatureV4", () => {
700730 sha256 : Sha256 ,
701731 } ;
702732
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+
703752 it ( "support event signing" , async ( ) => {
704753 const signer = new SignatureV4 ( signerInit ) ;
705754 const eventSignature = await signer . sign (
0 commit comments