@@ -70,66 +70,73 @@ describe('updateRateLimits()', () => {
7070 test ( 'should update the `all` category based on `retry-after` header ' , ( ) => {
7171 const rateLimits : RateLimits = { } ;
7272 const headers = {
73+ 'x-sentry-rate-limits' : null ,
7374 'retry-after' : '42' ,
7475 } ;
75- const updatedRateLimits = updateRateLimits ( rateLimits , headers , 0 ) ;
76+ const updatedRateLimits = updateRateLimits ( rateLimits , { headers } , 0 ) ;
7677 expect ( updatedRateLimits . all ) . toEqual ( 42 * 1000 ) ;
7778 } ) ;
7879
7980 test ( 'should update a single category based on `x-sentry-rate-limits` header' , ( ) => {
8081 const rateLimits : RateLimits = { } ;
8182 const headers = {
83+ 'retry-after' : null ,
8284 'x-sentry-rate-limits' : '13:error' ,
8385 } ;
84- const updatedRateLimits = updateRateLimits ( rateLimits , headers , 0 ) ;
86+ const updatedRateLimits = updateRateLimits ( rateLimits , { headers } , 0 ) ;
8587 expect ( updatedRateLimits . error ) . toEqual ( 13 * 1000 ) ;
8688 } ) ;
8789
8890 test ( 'should update multiple categories based on `x-sentry-rate-limits` header' , ( ) => {
8991 const rateLimits : RateLimits = { } ;
9092 const headers = {
93+ 'retry-after' : null ,
9194 'x-sentry-rate-limits' : '13:error;transaction' ,
9295 } ;
93- const updatedRateLimits = updateRateLimits ( rateLimits , headers , 0 ) ;
96+ const updatedRateLimits = updateRateLimits ( rateLimits , { headers } , 0 ) ;
9497 expect ( updatedRateLimits . error ) . toEqual ( 13 * 1000 ) ;
9598 expect ( updatedRateLimits . transaction ) . toEqual ( 13 * 1000 ) ;
9699 } ) ;
97100
98101 test ( 'should update multiple categories with different values based on multi `x-sentry-rate-limits` header' , ( ) => {
99102 const rateLimits : RateLimits = { } ;
100103 const headers = {
104+ 'retry-after' : null ,
101105 'x-sentry-rate-limits' : '13:error,15:transaction' ,
102106 } ;
103- const updatedRateLimits = updateRateLimits ( rateLimits , headers , 0 ) ;
107+ const updatedRateLimits = updateRateLimits ( rateLimits , { headers } , 0 ) ;
104108 expect ( updatedRateLimits . error ) . toEqual ( 13 * 1000 ) ;
105109 expect ( updatedRateLimits . transaction ) . toEqual ( 15 * 1000 ) ;
106110 } ) ;
107111
108112 test ( 'should use last entry from multi `x-sentry-rate-limits` header for a given category' , ( ) => {
109113 const rateLimits : RateLimits = { } ;
110114 const headers = {
115+ 'retry-after' : null ,
111116 'x-sentry-rate-limits' : '13:error,15:transaction;error' ,
112117 } ;
113- const updatedRateLimits = updateRateLimits ( rateLimits , headers , 0 ) ;
118+ const updatedRateLimits = updateRateLimits ( rateLimits , { headers } , 0 ) ;
114119 expect ( updatedRateLimits . error ) . toEqual ( 15 * 1000 ) ;
115120 expect ( updatedRateLimits . transaction ) . toEqual ( 15 * 1000 ) ;
116121 } ) ;
117122
118123 test ( 'should fallback to `all` if `x-sentry-rate-limits` header is missing a category' , ( ) => {
119124 const rateLimits : RateLimits = { } ;
120125 const headers = {
126+ 'retry-after' : null ,
121127 'x-sentry-rate-limits' : '13' ,
122128 } ;
123- const updatedRateLimits = updateRateLimits ( rateLimits , headers , 0 ) ;
129+ const updatedRateLimits = updateRateLimits ( rateLimits , { headers } , 0 ) ;
124130 expect ( updatedRateLimits . all ) . toEqual ( 13 * 1000 ) ;
125131 } ) ;
126132
127133 test ( 'should use 60s default if delay in `x-sentry-rate-limits` header is malformed' , ( ) => {
128134 const rateLimits : RateLimits = { } ;
129135 const headers = {
136+ 'retry-after' : null ,
130137 'x-sentry-rate-limits' : 'x' ,
131138 } ;
132- const updatedRateLimits = updateRateLimits ( rateLimits , headers , 0 ) ;
139+ const updatedRateLimits = updateRateLimits ( rateLimits , { headers } , 0 ) ;
133140 expect ( updatedRateLimits . all ) . toEqual ( 60 * 1000 ) ;
134141 } ) ;
135142
@@ -138,9 +145,10 @@ describe('updateRateLimits()', () => {
138145 error : 1337 ,
139146 } ;
140147 const headers = {
148+ 'retry-after' : null ,
141149 'x-sentry-rate-limits' : '13:transaction' ,
142150 } ;
143- const updatedRateLimits = updateRateLimits ( rateLimits , headers , 0 ) ;
151+ const updatedRateLimits = updateRateLimits ( rateLimits , { headers } , 0 ) ;
144152 expect ( updatedRateLimits . error ) . toEqual ( 1337 ) ;
145153 expect ( updatedRateLimits . transaction ) . toEqual ( 13 * 1000 ) ;
146154 } ) ;
@@ -151,8 +159,31 @@ describe('updateRateLimits()', () => {
151159 'retry-after' : '42' ,
152160 'x-sentry-rate-limits' : '13:error' ,
153161 } ;
154- const updatedRateLimits = updateRateLimits ( rateLimits , headers , 0 ) ;
162+ const updatedRateLimits = updateRateLimits ( rateLimits , { headers } , 0 ) ;
155163 expect ( updatedRateLimits . error ) . toEqual ( 13 * 1000 ) ;
156164 expect ( updatedRateLimits . all ) . toBeUndefined ( ) ;
157165 } ) ;
166+
167+ test ( 'should apply a global rate limit of 60s when no headers are provided on a 429 status code' , ( ) => {
168+ const rateLimits : RateLimits = { } ;
169+ const updatedRateLimits = updateRateLimits ( rateLimits , { statusCode : 429 } , 0 ) ;
170+ expect ( updatedRateLimits . all ) . toBe ( 60_000 ) ;
171+ } ) ;
172+
173+ test ( 'should not apply a global rate limit specific headers are provided on a 429 status code' , ( ) => {
174+ const rateLimits : RateLimits = { } ;
175+ const headers = {
176+ 'retry-after' : null ,
177+ 'x-sentry-rate-limits' : '13:error' ,
178+ } ;
179+ const updatedRateLimits = updateRateLimits ( rateLimits , { statusCode : 429 , headers } , 0 ) ;
180+ expect ( updatedRateLimits . error ) . toEqual ( 13 * 1000 ) ;
181+ expect ( updatedRateLimits . all ) . toBeUndefined ( ) ;
182+ } ) ;
183+
184+ test ( 'should not apply a default rate limit on a non-429 status code' , ( ) => {
185+ const rateLimits : RateLimits = { } ;
186+ const updatedRateLimits = updateRateLimits ( rateLimits , { statusCode : 200 } , 0 ) ;
187+ expect ( updatedRateLimits ) . toEqual ( rateLimits ) ;
188+ } ) ;
158189} ) ;
0 commit comments