@@ -106,6 +106,24 @@ describe('free mode country access', () => {
106106 expect ( access . ipPrivacy ?. signals ) . toEqual ( [ 'vpn' ] )
107107 } )
108108
109+ test ( 'blocks allowlisted countries when IPinfo reports a residential proxy' , async ( ) => {
110+ const access = await getFreeModeCountryAccess (
111+ makeReq ( {
112+ 'cf-ipcountry' : 'US' ,
113+ 'x-forwarded-for' : '203.0.113.10' ,
114+ } ) ,
115+ {
116+ ipinfoToken : 'test-token' ,
117+ lookupIpPrivacy : async ( ) => ( {
118+ signals : [ 'res_proxy' ] ,
119+ } ) ,
120+ } ,
121+ )
122+ expect ( access . allowed ) . toBe ( false )
123+ expect ( access . blockReason ) . toBe ( 'anonymous_network' )
124+ expect ( access . ipPrivacy ?. signals ) . toEqual ( [ 'res_proxy' ] )
125+ } )
126+
109127 test ( 'allows allowlisted countries when privacy lookup finds no anonymous signals' , async ( ) => {
110128 const access = await getFreeModeCountryAccess (
111129 makeReq ( {
@@ -141,25 +159,49 @@ describe('free mode country access', () => {
141159 expect ( access . ipPrivacy ) . toBe ( null )
142160 } )
143161
144- test ( 'parses IPinfo privacy signals' , async ( ) => {
162+ test ( 'parses IPinfo Max anonymous signals' , async ( ) => {
163+ let requestedUrl = ''
164+ const fetch = async ( url : string | URL | Request ) => {
165+ requestedUrl = String ( url )
166+ return Response . json ( {
167+ anonymous : {
168+ is_proxy : false ,
169+ is_relay : true ,
170+ is_tor : true ,
171+ is_vpn : false ,
172+ is_res_proxy : true ,
173+ } ,
174+ is_anonymous : true ,
175+ is_hosting : true ,
176+ } )
177+ }
178+
179+ const privacy = await lookupIpinfoPrivacy ( {
180+ ip : IPINFO_PRIVACY_TEST_IP ,
181+ token : 'test-token' ,
182+ fetch : fetch as unknown as typeof globalThis . fetch ,
183+ } )
184+
185+ expect ( requestedUrl ) . toContain ( 'https://api.ipinfo.io/lookup/' )
186+ expect ( privacy ) . toEqual ( {
187+ signals : [ 'tor' , 'relay' , 'res_proxy' , 'hosting' ] ,
188+ } )
189+ } )
190+
191+ test ( 'blocks generic IPinfo anonymous results without a specific signal' , async ( ) => {
145192 const fetch = async ( ) =>
146193 Response . json ( {
147- vpn : true ,
148- proxy : false ,
149- tor : true ,
150- relay : false ,
151- hosting : true ,
152- service : 'Example VPN' ,
194+ is_anonymous : true ,
153195 } )
154196
155197 const privacy = await lookupIpinfoPrivacy ( {
156- ip : IPINFO_PRIVACY_TEST_IP ,
198+ ip : '198.51.100.43' ,
157199 token : 'test-token' ,
158200 fetch : fetch as unknown as typeof globalThis . fetch ,
159201 } )
160202
161203 expect ( privacy ) . toEqual ( {
162- signals : [ 'vpn' , 'tor' , 'hosting' , 'service '] ,
204+ signals : [ 'anonymous ' ] ,
163205 } )
164206 } )
165207} )
0 commit comments