@@ -63,4 +63,43 @@ describe('[nuxt-security] Rate Limiter', async () => {
6363    expect ( res6 . status ) . toBe ( 200 ) 
6464    expect ( res6 . statusText ) . toBe ( 'OK' ) 
6565  } ) 
66+ 
67+   it  ( 'should return 200 OK after multiple requests for a route with localhost ip whitelisted' ,  async  ( )  =>  { 
68+     const  res1  =  await  fetch ( '/whitelistBase' ) 
69+     await  fetch ( '/whitelistBase' ) 
70+     await  fetch ( '/whitelistBase' ) 
71+     await  fetch ( '/whitelistBase' ) 
72+     const  res5  =  await  fetch ( '/whitelistBase' ) 
73+ 
74+     expect ( res1 ) . toBeDefined ( ) 
75+     expect ( res1 ) . toBeTruthy ( ) 
76+     expect ( res5 . status ) . toBe ( 200 ) 
77+     expect ( res5 . statusText ) . toBe ( 'OK' ) 
78+   } ) 
79+ 
80+   it  ( 'should return 429 when limit reached with an empty whitelist array' ,  async  ( )  =>  { 
81+     const  res1  =  await  fetch ( '/whitelistEmpty' ) 
82+     await  fetch ( '/whitelistEmpty' ) 
83+     await  fetch ( '/whitelistEmpty' ) 
84+     await  fetch ( '/whitelistEmpty' ) 
85+     const  res5  =  await  fetch ( '/whitelistEmpty' ) 
86+ 
87+     expect ( res1 ) . toBeDefined ( ) 
88+     expect ( res1 ) . toBeTruthy ( ) 
89+     expect ( res5 . status ) . toBe ( 429 ) 
90+     expect ( res5 . statusText ) . toBe ( 'Too Many Requests' ) 
91+   } ) 
92+ 
93+   it  ( 'should return 429 when limit reached as localhost ip is not whitelisted' ,  async  ( )  =>  { 
94+     const  res1  =  await  fetch ( '/whitelistNotListed' ) 
95+     await  fetch ( '/whitelistNotListed' ) 
96+     await  fetch ( '/whitelistNotListed' ) 
97+     await  fetch ( '/whitelistNotListed' ) 
98+     const  res5  =  await  fetch ( '/whitelistNotListed' ) 
99+ 
100+     expect ( res1 ) . toBeDefined ( ) 
101+     expect ( res1 ) . toBeTruthy ( ) 
102+     expect ( res5 . status ) . toBe ( 429 ) 
103+     expect ( res5 . statusText ) . toBe ( 'Too Many Requests' ) 
104+   } ) 
66105} ) 
0 commit comments