File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
packages/middleware-signing/src Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -89,4 +89,24 @@ describe(awsAuthMiddleware.name, () => {
89
89
expect ( getUpdatedSystemClockOffset ) . toHaveBeenCalledWith ( dateHeader , mockSystemClockOffset ) ;
90
90
} ) ;
91
91
} ) ;
92
+
93
+ it ( "should update systemClockOffset if error contains ServerTime" , async ( ) => {
94
+ const serverTime = new Date ( ) . toString ( ) ;
95
+ const options = { ...mockOptions } ;
96
+ const signingHandler = awsAuthMiddleware ( options ) ( mockNext , { } ) ;
97
+
98
+ const mockError = Object . assign ( new Error ( "error" ) , { ServerTime : serverTime } ) ;
99
+ mockNext . mockRejectedValue ( mockError ) ;
100
+
101
+ try {
102
+ await signingHandler ( mockSigningHandlerArgs ) ;
103
+ fail ( `should throw ${ mockError } ` ) ;
104
+ } catch ( error ) {
105
+ expect ( error ) . toStrictEqual ( mockError ) ;
106
+ }
107
+
108
+ expect ( options . systemClockOffset ) . toBe ( mockUpdatedSystemClockOffset ) ;
109
+ expect ( getUpdatedSystemClockOffset ) . toHaveBeenCalledTimes ( 1 ) ;
110
+ expect ( getUpdatedSystemClockOffset ) . toHaveBeenCalledWith ( serverTime , mockSystemClockOffset ) ;
111
+ } ) ;
92
112
} ) ;
Original file line number Diff line number Diff line change @@ -28,6 +28,11 @@ export const awsAuthMiddleware =
28
28
signingRegion : context [ "signing_region" ] ,
29
29
signingService : context [ "signing_service" ] ,
30
30
} ) ,
31
+ } ) . catch ( ( error ) => {
32
+ if ( error . ServerTime ) {
33
+ options . systemClockOffset = getUpdatedSystemClockOffset ( error . ServerTime , options . systemClockOffset ) ;
34
+ }
35
+ throw error ;
31
36
} ) ;
32
37
33
38
const { headers } = output . response as any ;
You can’t perform that action at this time.
0 commit comments