@@ -249,6 +249,51 @@ test("`findIp`", async (t) => {
249249 } ,
250250 ) ;
251251
252+ await t . test ( "should support an IP string in a proxy" , function ( ) {
253+ assert . equal (
254+ findIp (
255+ { headers : { "x-forwarded-for" : "1.1.1.1, 2.2.2.2, 3.3.3.3" } } ,
256+ { proxies : [ "3.3.3.3" ] } ,
257+ ) ,
258+ "2.2.2.2" ,
259+ ) ;
260+ } ) ;
261+
262+ await t . test ( "should support an CIDR string in a proxy" , function ( ) {
263+ assert . equal (
264+ findIp (
265+ { headers : { "x-forwarded-for" : "1.1.1.1, 2.2.2.2, 3.3.3.3" } } ,
266+ { proxies : [ "3.3.3.3/32" ] } ,
267+ ) ,
268+ "2.2.2.2" ,
269+ ) ;
270+ } ) ;
271+
272+ await t . test ( "should support an CIDR object in a proxy" , function ( ) {
273+ assert . equal (
274+ findIp (
275+ { headers : { "x-forwarded-for" : "1.1.1.1, 2.2.2.2, 3.3.3.3" } } ,
276+ { proxies : [ parseProxy ( "3.3.3.3/32" ) ] } ,
277+ ) ,
278+ "2.2.2.2" ,
279+ ) ;
280+ } ) ;
281+
282+ await t . test ( "should filter an invalid value in a proxy" , function ( ) {
283+ assert . equal (
284+ findIp (
285+ { headers : { "x-forwarded-for" : "1.1.1.1, 2.2.2.2, 3.3.3.3" } } ,
286+ {
287+ proxies : [
288+ // @ts -expect-error: Testing type annotation violations
289+ 123456789 ,
290+ ] ,
291+ } ,
292+ ) ,
293+ "3.3.3.3" ,
294+ ) ;
295+ } ) ;
296+
252297 await t . test ( "request: `ip`" , async ( t ) => {
253298 for ( const [ message , input , expected , proxies ] of cases ) {
254299 await t . test ( message , ( ) => {
0 commit comments