@@ -187,6 +187,120 @@ describe('parseRateLimitConfig', () => {
187187 } ) ;
188188 } ) ;
189189
190+ describe ( 'tokenBucketBufferSize validation' , ( ) => {
191+ it ( 'should use default tokenBucketBufferSize when not specified' , ( ) => {
192+ const config = {
193+ serviceUserArn : 'arn:aws:iam::123456789012:user/rate-limit-service' ,
194+ } ;
195+
196+ const result = parseRateLimitConfig ( config , 1 ) ;
197+ assert . strictEqual ( result . tokenBucketBufferSize , 50 ) ;
198+ } ) ;
199+
200+ it ( 'should accept custom tokenBucketBufferSize' , ( ) => {
201+ const config = {
202+ serviceUserArn : 'arn:aws:iam::123456789012:user/rate-limit-service' ,
203+ tokenBucketBufferSize : 100 ,
204+ } ;
205+
206+ const result = parseRateLimitConfig ( config , 1 ) ;
207+ assert . strictEqual ( result . tokenBucketBufferSize , 100 ) ;
208+ } ) ;
209+
210+ it ( 'should throw if tokenBucketBufferSize is not a positive integer' , ( ) => {
211+ const config = {
212+ serviceUserArn : 'arn:aws:iam::123456789012:user/rate-limit-service' ,
213+ tokenBucketBufferSize : - 10 ,
214+ } ;
215+
216+ assert . throws (
217+ ( ) => parseRateLimitConfig ( config , 1 ) ,
218+ / r a t e L i m i t i n g .t o k e n B u c k e t B u f f e r S i z e m u s t b e a p o s i t i v e i n t e g e r /
219+ ) ;
220+ } ) ;
221+
222+ it ( 'should throw if tokenBucketBufferSize is zero' , ( ) => {
223+ const config = {
224+ serviceUserArn : 'arn:aws:iam::123456789012:user/rate-limit-service' ,
225+ tokenBucketBufferSize : 0 ,
226+ } ;
227+
228+ assert . throws (
229+ ( ) => parseRateLimitConfig ( config , 1 ) ,
230+ / r a t e L i m i t i n g .t o k e n B u c k e t B u f f e r S i z e m u s t b e a p o s i t i v e i n t e g e r /
231+ ) ;
232+ } ) ;
233+
234+ it ( 'should throw if tokenBucketBufferSize is not an integer' , ( ) => {
235+ const config = {
236+ serviceUserArn : 'arn:aws:iam::123456789012:user/rate-limit-service' ,
237+ tokenBucketBufferSize : 50.5 ,
238+ } ;
239+
240+ assert . throws (
241+ ( ) => parseRateLimitConfig ( config , 1 ) ,
242+ / r a t e L i m i t i n g .t o k e n B u c k e t B u f f e r S i z e m u s t b e a p o s i t i v e i n t e g e r /
243+ ) ;
244+ } ) ;
245+ } ) ;
246+
247+ describe ( 'tokenBucketRefillThreshold validation' , ( ) => {
248+ it ( 'should use default tokenBucketRefillThreshold when not specified' , ( ) => {
249+ const config = {
250+ serviceUserArn : 'arn:aws:iam::123456789012:user/rate-limit-service' ,
251+ } ;
252+
253+ const result = parseRateLimitConfig ( config , 1 ) ;
254+ assert . strictEqual ( result . tokenBucketRefillThreshold , 20 ) ;
255+ } ) ;
256+
257+ it ( 'should accept custom tokenBucketRefillThreshold' , ( ) => {
258+ const config = {
259+ serviceUserArn : 'arn:aws:iam::123456789012:user/rate-limit-service' ,
260+ tokenBucketRefillThreshold : 30 ,
261+ } ;
262+
263+ const result = parseRateLimitConfig ( config , 1 ) ;
264+ assert . strictEqual ( result . tokenBucketRefillThreshold , 30 ) ;
265+ } ) ;
266+
267+ it ( 'should throw if tokenBucketRefillThreshold is not a positive integer' , ( ) => {
268+ const config = {
269+ serviceUserArn : 'arn:aws:iam::123456789012:user/rate-limit-service' ,
270+ tokenBucketRefillThreshold : - 5 ,
271+ } ;
272+
273+ assert . throws (
274+ ( ) => parseRateLimitConfig ( config , 1 ) ,
275+ / r a t e L i m i t i n g .t o k e n B u c k e t R e f i l l T h r e s h o l d m u s t b e a p o s i t i v e i n t e g e r /
276+ ) ;
277+ } ) ;
278+
279+ it ( 'should throw if tokenBucketRefillThreshold is zero' , ( ) => {
280+ const config = {
281+ serviceUserArn : 'arn:aws:iam::123456789012:user/rate-limit-service' ,
282+ tokenBucketRefillThreshold : 0 ,
283+ } ;
284+
285+ assert . throws (
286+ ( ) => parseRateLimitConfig ( config , 1 ) ,
287+ / r a t e L i m i t i n g .t o k e n B u c k e t R e f i l l T h r e s h o l d m u s t b e a p o s i t i v e i n t e g e r /
288+ ) ;
289+ } ) ;
290+
291+ it ( 'should throw if tokenBucketRefillThreshold is not an integer' , ( ) => {
292+ const config = {
293+ serviceUserArn : 'arn:aws:iam::123456789012:user/rate-limit-service' ,
294+ tokenBucketRefillThreshold : 20.5 ,
295+ } ;
296+
297+ assert . throws (
298+ ( ) => parseRateLimitConfig ( config , 1 ) ,
299+ / r a t e L i m i t i n g .t o k e n B u c k e t R e f i l l T h r e s h o l d m u s t b e a p o s i t i v e i n t e g e r /
300+ ) ;
301+ } ) ;
302+ } ) ;
303+
190304 describe ( 'bucket validation' , ( ) => {
191305 it ( 'should throw if bucket is not an object' , ( ) => {
192306 const config = {
0 commit comments