vpndetection-fastapi 2.1.28__tar.gz → 2.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/CHANGELOG.md +13 -0
- {vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/PKG-INFO +19 -4
- {vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/README.md +17 -2
- {vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/pyproject.toml +1 -1
- {vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/src/vpndetection_fastapi/__init__.py +10 -2
- {vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/testdata/testdata.json +323 -20
- {vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/tests/test_middleware.py +129 -0
- {vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/.github/workflows/ci.yml +0 -0
- {vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/.github/workflows/release.yml +0 -0
- {vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/.gitignore +0 -0
- {vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/LICENSE +0 -0
- {vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/SECURITY.md +0 -0
- {vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/src/vpndetection_fastapi/py.typed +0 -0
- {vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/testdata/bogons.json +0 -0
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
What each release changed for you, newest first. Each line is a commit's summary, linked to its full description and diff. Releases before 2.0.5 are described by their release commits.
|
|
4
4
|
|
|
5
|
+
## 2.2.0 - 2026-11-23
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- Require vpndetection 5.21.0: a user agent with a lookup, and allow_bots in the middleware core ([`a7e8d80`](https://github.com/vpndetection-io/sdk-python-fastapi/commit/a7e8d80b886c987c7358a028499ff2697fe8c58c))
|
|
10
|
+
- Let a verified crawler through with allow_bots ([`c7dd247`](https://github.com/vpndetection-io/sdk-python-fastapi/commit/c7dd247cb47bd55acd35cadca44b5d6e4c131265))
|
|
11
|
+
|
|
12
|
+
## 2.1.29 - 2026-11-22
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- Require vpndetection 5.20.0: is_bot and bot, and the AS's country and RPKI status required ([`6448579`](https://github.com/vpndetection-io/sdk-python-fastapi/commit/64485792c122bfe1c5a8684a9ec5ed9fd3896056))
|
|
17
|
+
|
|
5
18
|
## 2.1.28 - 2026-11-20
|
|
6
19
|
|
|
7
20
|
### Features
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: vpndetection-fastapi
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: Official FastAPI and Starlette middleware for the VPNDetection API. Detect VPNs, proxies, Tor, hosting and CDN visitors on every request.
|
|
5
5
|
Project-URL: Homepage, https://vpndetection.io
|
|
6
6
|
Project-URL: Source, https://github.com/vpndetection-io/sdk-python-fastapi
|
|
@@ -20,7 +20,7 @@ Classifier: Topic :: Security
|
|
|
20
20
|
Classifier: Typing :: Typed
|
|
21
21
|
Requires-Python: >=3.11
|
|
22
22
|
Requires-Dist: starlette>=0.37
|
|
23
|
-
Requires-Dist: vpndetection<6,>=5.
|
|
23
|
+
Requires-Dist: vpndetection<6,>=5.21.0
|
|
24
24
|
Provides-Extra: dev
|
|
25
25
|
Requires-Dist: fastapi>=0.115; extra == 'dev'
|
|
26
26
|
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
@@ -89,10 +89,25 @@ A condition is written in the shape of a result, keyed by the same names the API
|
|
|
89
89
|
[{"is_tor": True}, {"is_resproxy": True}] # a list is OR
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
Values are matched by equality, strings without regard to case. A list means any-of. A dict of `gte`/`gt`/`lte`/`lt` compares numbers, and every bound you give must hold, so two of them are a range. Members set to `False` or `None` are ignored, so a condition states the signals you act on; one that constrains nothing would match every request, and is refused when the middleware is built rather than silently blocking all your traffic.
|
|
92
|
+
Values are matched by equality, strings without regard to case. A list means any-of. A dict of `gte`/`gt`/`lte`/`lt` compares numbers, and every bound you give must hold, so two of them are a range. A member the answer holds as a list (`web`, `pubproxy.protocols`, `bittorrent.clients`, `bot.agents`, `bot.categories`) is never matched, so block on its flag alone. Members set to `False` or `None` are ignored, so a condition states the signals you act on; one that constrains nothing would match every request, and is refused when the middleware is built rather than silently blocking all your traffic.
|
|
93
93
|
|
|
94
94
|
Replace the refusal with `on_blocked`.
|
|
95
95
|
|
|
96
|
+
### Letting verified crawlers through
|
|
97
|
+
|
|
98
|
+
`allow_bots=True` sends each request's own `User-Agent` header with its lookup, and a request whose answer verifies that crawler, `lookup(request).result.user_agent.verdict == "verified"`, is never refused, by `block_condition` or by `block_if`; the answer is still attached. A request with no `User-Agent` sends none. It is off by default, which keeps one cached answer per address rather than one per agent.
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
app.add_middleware(
|
|
102
|
+
VPNDetectionMiddleware,
|
|
103
|
+
api_key=os.environ["VPNDETECTION_API_KEY"],
|
|
104
|
+
block_condition={"is_hosting": True},
|
|
105
|
+
allow_bots=True,
|
|
106
|
+
)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
With it on, a condition can name the verdict, refusing a forged crawler and a script: `{"user_agent": {"verdict": ["spoofed", "not_bot"]}}`. Only a paid plan's answer carries `user_agent`: a keyless client, or a free key past its trial, never gets a verdict and lets no crawler through, and the middleware warns once when that happens.
|
|
110
|
+
|
|
96
111
|
### Blocking one endpoint
|
|
97
112
|
|
|
98
113
|
`block_condition` applies to every endpoint. In FastAPI, refuse a visitor on some endpoints only with the `block_if` dependency, on a path operation, a router or the app:
|
|
@@ -146,7 +161,7 @@ Beyond a few million distinct visitors a day, stop calling the API per request:
|
|
|
146
161
|
|
|
147
162
|
## Absent is not false
|
|
148
163
|
|
|
149
|
-
Unlimited, with a key or without one, leaves out `is_hosting`, `is_cdn`, the four proxy flags, the carrier, satellite and service flags, `company` and `abuse`, and of the detail behind each flag it answers only Tor's and relay's. A field your plan does not include is `None`, which means "not in your plan" rather than "checked, and no".
|
|
164
|
+
Unlimited, with a key or without one, leaves out `is_hosting`, `is_cdn`, the four proxy flags, the carrier, satellite and service flags, `bot`, `company` and `abuse`, and of the detail behind each flag it answers only Tor's and relay's. A field your plan does not include is `None`, which means "not in your plan" rather than "checked, and no".
|
|
150
165
|
|
|
151
166
|
```python
|
|
152
167
|
lookup(request).result.is_hosting # None when your plan does not include it
|
|
@@ -59,10 +59,25 @@ A condition is written in the shape of a result, keyed by the same names the API
|
|
|
59
59
|
[{"is_tor": True}, {"is_resproxy": True}] # a list is OR
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
Values are matched by equality, strings without regard to case. A list means any-of. A dict of `gte`/`gt`/`lte`/`lt` compares numbers, and every bound you give must hold, so two of them are a range. Members set to `False` or `None` are ignored, so a condition states the signals you act on; one that constrains nothing would match every request, and is refused when the middleware is built rather than silently blocking all your traffic.
|
|
62
|
+
Values are matched by equality, strings without regard to case. A list means any-of. A dict of `gte`/`gt`/`lte`/`lt` compares numbers, and every bound you give must hold, so two of them are a range. A member the answer holds as a list (`web`, `pubproxy.protocols`, `bittorrent.clients`, `bot.agents`, `bot.categories`) is never matched, so block on its flag alone. Members set to `False` or `None` are ignored, so a condition states the signals you act on; one that constrains nothing would match every request, and is refused when the middleware is built rather than silently blocking all your traffic.
|
|
63
63
|
|
|
64
64
|
Replace the refusal with `on_blocked`.
|
|
65
65
|
|
|
66
|
+
### Letting verified crawlers through
|
|
67
|
+
|
|
68
|
+
`allow_bots=True` sends each request's own `User-Agent` header with its lookup, and a request whose answer verifies that crawler, `lookup(request).result.user_agent.verdict == "verified"`, is never refused, by `block_condition` or by `block_if`; the answer is still attached. A request with no `User-Agent` sends none. It is off by default, which keeps one cached answer per address rather than one per agent.
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
app.add_middleware(
|
|
72
|
+
VPNDetectionMiddleware,
|
|
73
|
+
api_key=os.environ["VPNDETECTION_API_KEY"],
|
|
74
|
+
block_condition={"is_hosting": True},
|
|
75
|
+
allow_bots=True,
|
|
76
|
+
)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
With it on, a condition can name the verdict, refusing a forged crawler and a script: `{"user_agent": {"verdict": ["spoofed", "not_bot"]}}`. Only a paid plan's answer carries `user_agent`: a keyless client, or a free key past its trial, never gets a verdict and lets no crawler through, and the middleware warns once when that happens.
|
|
80
|
+
|
|
66
81
|
### Blocking one endpoint
|
|
67
82
|
|
|
68
83
|
`block_condition` applies to every endpoint. In FastAPI, refuse a visitor on some endpoints only with the `block_if` dependency, on a path operation, a router or the app:
|
|
@@ -116,7 +131,7 @@ Beyond a few million distinct visitors a day, stop calling the API per request:
|
|
|
116
131
|
|
|
117
132
|
## Absent is not false
|
|
118
133
|
|
|
119
|
-
Unlimited, with a key or without one, leaves out `is_hosting`, `is_cdn`, the four proxy flags, the carrier, satellite and service flags, `company` and `abuse`, and of the detail behind each flag it answers only Tor's and relay's. A field your plan does not include is `None`, which means "not in your plan" rather than "checked, and no".
|
|
134
|
+
Unlimited, with a key or without one, leaves out `is_hosting`, `is_cdn`, the four proxy flags, the carrier, satellite and service flags, `bot`, `company` and `abuse`, and of the detail behind each flag it answers only Tor's and relay's. A field your plan does not include is `None`, which means "not in your plan" rather than "checked, and no".
|
|
120
135
|
|
|
121
136
|
```python
|
|
122
137
|
lookup(request).result.is_hosting # None when your plan does not include it
|
{vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/src/vpndetection_fastapi/__init__.py
RENAMED
|
@@ -45,7 +45,7 @@ __all__ = [
|
|
|
45
45
|
"xff_ip_selector",
|
|
46
46
|
]
|
|
47
47
|
|
|
48
|
-
__version__ = "2.
|
|
48
|
+
__version__ = "2.2.0"
|
|
49
49
|
|
|
50
50
|
# Set on a request ``skip`` claimed, so block_if can tell it from one the middleware
|
|
51
51
|
# never saw.
|
|
@@ -147,6 +147,8 @@ class VPNDetectionMiddleware:
|
|
|
147
147
|
"""Classify the visitor, and optionally refuse the request.
|
|
148
148
|
|
|
149
149
|
Takes everything :class:`vpndetection.middleware.Options` does, plus ``on_blocked``.
|
|
150
|
+
``allow_bots=True`` sends the request's own ``User-Agent`` with its lookup and never
|
|
151
|
+
refuses a crawler the answer verifies, here or in :func:`block_if`.
|
|
150
152
|
|
|
151
153
|
Written as raw ASGI rather than on ``BaseHTTPMiddleware``, which wraps the response
|
|
152
154
|
in a streaming bridge that breaks background tasks and server-sent events - a cost
|
|
@@ -162,7 +164,9 @@ class VPNDetectionMiddleware:
|
|
|
162
164
|
) -> None:
|
|
163
165
|
self.app = app
|
|
164
166
|
self._on_blocked = on_blocked or _refuse
|
|
165
|
-
self._core: AsyncCore[Request] = AsyncCore(
|
|
167
|
+
self._core: AsyncCore[Request] = AsyncCore(
|
|
168
|
+
Options(**options), default_ip_selector, _user_agent
|
|
169
|
+
)
|
|
166
170
|
|
|
167
171
|
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
|
|
168
172
|
if scope["type"] != "http":
|
|
@@ -188,5 +192,9 @@ class VPNDetectionMiddleware:
|
|
|
188
192
|
await self.app(scope, receive, send)
|
|
189
193
|
|
|
190
194
|
|
|
195
|
+
def _user_agent(request: Request) -> str | None:
|
|
196
|
+
return request.headers.get("User-Agent")
|
|
197
|
+
|
|
198
|
+
|
|
191
199
|
def _refuse(_request: Request, _lookup: Lookup) -> Response:
|
|
192
200
|
return JSONResponse({"error": "access denied"}, status_code=403)
|
|
@@ -1438,6 +1438,7 @@
|
|
|
1438
1438
|
"is_relay",
|
|
1439
1439
|
"is_tor",
|
|
1440
1440
|
"is_cdn",
|
|
1441
|
+
"is_bot",
|
|
1441
1442
|
"is_resproxy",
|
|
1442
1443
|
"is_dcproxy",
|
|
1443
1444
|
"is_mobproxy",
|
|
@@ -1457,6 +1458,7 @@
|
|
|
1457
1458
|
"relay",
|
|
1458
1459
|
"tor",
|
|
1459
1460
|
"cdn",
|
|
1461
|
+
"bot",
|
|
1460
1462
|
"resproxy",
|
|
1461
1463
|
"dcproxy",
|
|
1462
1464
|
"mobproxy",
|
|
@@ -1864,7 +1866,9 @@
|
|
|
1864
1866
|
"name": "M247 Europe SRL",
|
|
1865
1867
|
"domain": "m247global.com",
|
|
1866
1868
|
"type": "hosting",
|
|
1867
|
-
"prefix": "146.70.116.0/24"
|
|
1869
|
+
"prefix": "146.70.116.0/24",
|
|
1870
|
+
"country": "US",
|
|
1871
|
+
"rpki_status": "valid"
|
|
1868
1872
|
}
|
|
1869
1873
|
},
|
|
1870
1874
|
"expect": {
|
|
@@ -1912,7 +1916,9 @@
|
|
|
1912
1916
|
"name": "M247 Europe SRL",
|
|
1913
1917
|
"domain": "m247global.com",
|
|
1914
1918
|
"type": "hosting",
|
|
1915
|
-
"prefix": "146.70.116.0/24"
|
|
1919
|
+
"prefix": "146.70.116.0/24",
|
|
1920
|
+
"country": "US",
|
|
1921
|
+
"rpki_status": "valid"
|
|
1916
1922
|
}
|
|
1917
1923
|
}
|
|
1918
1924
|
},
|
|
@@ -1950,7 +1956,9 @@
|
|
|
1950
1956
|
"name": "M247 Europe SRL",
|
|
1951
1957
|
"domain": "m247global.com",
|
|
1952
1958
|
"type": "hosting",
|
|
1953
|
-
"prefix": "146.70.116.0/24"
|
|
1959
|
+
"prefix": "146.70.116.0/24",
|
|
1960
|
+
"country": "US",
|
|
1961
|
+
"rpki_status": "valid"
|
|
1954
1962
|
}
|
|
1955
1963
|
},
|
|
1956
1964
|
"expect": {
|
|
@@ -1997,7 +2005,9 @@
|
|
|
1997
2005
|
"name": "M247 Europe SRL",
|
|
1998
2006
|
"domain": "m247global.com",
|
|
1999
2007
|
"type": "hosting",
|
|
2000
|
-
"prefix": "146.70.116.0/24"
|
|
2008
|
+
"prefix": "146.70.116.0/24",
|
|
2009
|
+
"country": "US",
|
|
2010
|
+
"rpki_status": "valid"
|
|
2001
2011
|
}
|
|
2002
2012
|
}
|
|
2003
2013
|
},
|
|
@@ -2050,7 +2060,9 @@
|
|
|
2050
2060
|
"name": "M247 Europe SRL",
|
|
2051
2061
|
"domain": "m247global.com",
|
|
2052
2062
|
"type": "hosting",
|
|
2053
|
-
"prefix": "146.70.116.0/24"
|
|
2063
|
+
"prefix": "146.70.116.0/24",
|
|
2064
|
+
"country": "US",
|
|
2065
|
+
"rpki_status": "valid"
|
|
2054
2066
|
},
|
|
2055
2067
|
"trial_expired": false
|
|
2056
2068
|
},
|
|
@@ -2100,7 +2112,9 @@
|
|
|
2100
2112
|
"name": "M247 Europe SRL",
|
|
2101
2113
|
"domain": "m247global.com",
|
|
2102
2114
|
"type": "hosting",
|
|
2103
|
-
"prefix": "146.70.116.0/24"
|
|
2115
|
+
"prefix": "146.70.116.0/24",
|
|
2116
|
+
"country": "US",
|
|
2117
|
+
"rpki_status": "valid"
|
|
2104
2118
|
}
|
|
2105
2119
|
}
|
|
2106
2120
|
},
|
|
@@ -2132,7 +2146,9 @@
|
|
|
2132
2146
|
"name": "M247 Europe SRL",
|
|
2133
2147
|
"domain": "m247global.com",
|
|
2134
2148
|
"type": "hosting",
|
|
2135
|
-
"prefix": "146.70.116.0/24"
|
|
2149
|
+
"prefix": "146.70.116.0/24",
|
|
2150
|
+
"country": "US",
|
|
2151
|
+
"rpki_status": "valid"
|
|
2136
2152
|
},
|
|
2137
2153
|
"trial_expired": true
|
|
2138
2154
|
},
|
|
@@ -2181,7 +2197,9 @@
|
|
|
2181
2197
|
"name": "M247 Europe SRL",
|
|
2182
2198
|
"domain": "m247global.com",
|
|
2183
2199
|
"type": "hosting",
|
|
2184
|
-
"prefix": "146.70.116.0/24"
|
|
2200
|
+
"prefix": "146.70.116.0/24",
|
|
2201
|
+
"country": "US",
|
|
2202
|
+
"rpki_status": "valid"
|
|
2185
2203
|
}
|
|
2186
2204
|
}
|
|
2187
2205
|
},
|
|
@@ -2213,7 +2231,9 @@
|
|
|
2213
2231
|
"name": "M247 Europe SRL",
|
|
2214
2232
|
"domain": "m247global.com",
|
|
2215
2233
|
"type": "hosting",
|
|
2216
|
-
"prefix": "146.70.116.0/24"
|
|
2234
|
+
"prefix": "146.70.116.0/24",
|
|
2235
|
+
"country": "US",
|
|
2236
|
+
"rpki_status": "valid"
|
|
2217
2237
|
},
|
|
2218
2238
|
"is_bogon": false,
|
|
2219
2239
|
"cap_reached": true
|
|
@@ -2263,13 +2283,15 @@
|
|
|
2263
2283
|
"name": "M247 Europe SRL",
|
|
2264
2284
|
"domain": "m247global.com",
|
|
2265
2285
|
"type": "hosting",
|
|
2266
|
-
"prefix": "146.70.116.0/24"
|
|
2286
|
+
"prefix": "146.70.116.0/24",
|
|
2287
|
+
"country": "US",
|
|
2288
|
+
"rpki_status": "valid"
|
|
2267
2289
|
}
|
|
2268
2290
|
}
|
|
2269
2291
|
},
|
|
2270
2292
|
{
|
|
2271
2293
|
"name": "unlimited-anycast-hostname",
|
|
2272
|
-
"why": "Unlimited's answer, with a key or without one, also carries is_anycast, hostname, and the AS's country and RPKI status. The paid members stay absent, never false or empty.",
|
|
2294
|
+
"why": "Unlimited's answer, with a key or without one, also carries is_bot, is_anycast, hostname, and the AS's country and RPKI status. The paid members stay absent, never false or empty.",
|
|
2273
2295
|
"status": 200,
|
|
2274
2296
|
"body": {
|
|
2275
2297
|
"ip": "1.1.1.1",
|
|
@@ -2277,6 +2299,7 @@
|
|
|
2277
2299
|
"is_vpn": false,
|
|
2278
2300
|
"is_relay": false,
|
|
2279
2301
|
"is_tor": false,
|
|
2302
|
+
"is_bot": false,
|
|
2280
2303
|
"is_anycast": true,
|
|
2281
2304
|
"relay": {},
|
|
2282
2305
|
"tor": {},
|
|
@@ -2310,6 +2333,7 @@
|
|
|
2310
2333
|
"is_vpn": false,
|
|
2311
2334
|
"is_relay": false,
|
|
2312
2335
|
"is_tor": false,
|
|
2336
|
+
"is_bot": false,
|
|
2313
2337
|
"is_anycast": true
|
|
2314
2338
|
},
|
|
2315
2339
|
"absent": [
|
|
@@ -2341,7 +2365,8 @@
|
|
|
2341
2365
|
"bittorrent",
|
|
2342
2366
|
"web",
|
|
2343
2367
|
"company",
|
|
2344
|
-
"abuse"
|
|
2368
|
+
"abuse",
|
|
2369
|
+
"bot"
|
|
2345
2370
|
],
|
|
2346
2371
|
"emptyPresent": [
|
|
2347
2372
|
"relay",
|
|
@@ -2383,6 +2408,7 @@
|
|
|
2383
2408
|
"is_relay": false,
|
|
2384
2409
|
"is_tor": false,
|
|
2385
2410
|
"is_cdn": false,
|
|
2411
|
+
"is_bot": false,
|
|
2386
2412
|
"is_resproxy": false,
|
|
2387
2413
|
"is_dcproxy": false,
|
|
2388
2414
|
"is_mobproxy": false,
|
|
@@ -2400,6 +2426,7 @@
|
|
|
2400
2426
|
"relay": {},
|
|
2401
2427
|
"tor": {},
|
|
2402
2428
|
"cdn": {},
|
|
2429
|
+
"bot": {},
|
|
2403
2430
|
"resproxy": {},
|
|
2404
2431
|
"dcproxy": {},
|
|
2405
2432
|
"mobproxy": {},
|
|
@@ -2508,6 +2535,7 @@
|
|
|
2508
2535
|
"is_anycast": true,
|
|
2509
2536
|
"is_carrier": false,
|
|
2510
2537
|
"is_satellite": false,
|
|
2538
|
+
"is_bot": false,
|
|
2511
2539
|
"is_ssh": false,
|
|
2512
2540
|
"is_smtp": false,
|
|
2513
2541
|
"is_web": true,
|
|
@@ -2523,7 +2551,8 @@
|
|
|
2523
2551
|
"satellite",
|
|
2524
2552
|
"ssh",
|
|
2525
2553
|
"smtp",
|
|
2526
|
-
"bittorrent"
|
|
2554
|
+
"bittorrent",
|
|
2555
|
+
"bot"
|
|
2527
2556
|
],
|
|
2528
2557
|
"web": [
|
|
2529
2558
|
{
|
|
@@ -2629,6 +2658,7 @@
|
|
|
2629
2658
|
"is_relay": false,
|
|
2630
2659
|
"is_tor": false,
|
|
2631
2660
|
"is_cdn": false,
|
|
2661
|
+
"is_bot": false,
|
|
2632
2662
|
"is_resproxy": false,
|
|
2633
2663
|
"is_dcproxy": false,
|
|
2634
2664
|
"is_mobproxy": false,
|
|
@@ -2646,6 +2676,7 @@
|
|
|
2646
2676
|
"relay": {},
|
|
2647
2677
|
"tor": {},
|
|
2648
2678
|
"cdn": {},
|
|
2679
|
+
"bot": {},
|
|
2649
2680
|
"resproxy": {},
|
|
2650
2681
|
"dcproxy": {},
|
|
2651
2682
|
"mobproxy": {},
|
|
@@ -2747,6 +2778,7 @@
|
|
|
2747
2778
|
"is_anycast": false,
|
|
2748
2779
|
"is_carrier": true,
|
|
2749
2780
|
"is_satellite": false,
|
|
2781
|
+
"is_bot": false,
|
|
2750
2782
|
"is_ssh": true,
|
|
2751
2783
|
"is_smtp": true,
|
|
2752
2784
|
"is_web": false,
|
|
@@ -2756,7 +2788,8 @@
|
|
|
2756
2788
|
"absent": [],
|
|
2757
2789
|
"emptyPresent": [
|
|
2758
2790
|
"satellite",
|
|
2759
|
-
"dns_resolver"
|
|
2791
|
+
"dns_resolver",
|
|
2792
|
+
"bot"
|
|
2760
2793
|
],
|
|
2761
2794
|
"carrier": {
|
|
2762
2795
|
"name": "T-Mobile US",
|
|
@@ -2858,6 +2891,7 @@
|
|
|
2858
2891
|
"is_relay": false,
|
|
2859
2892
|
"is_tor": false,
|
|
2860
2893
|
"is_cdn": false,
|
|
2894
|
+
"is_bot": false,
|
|
2861
2895
|
"is_resproxy": false,
|
|
2862
2896
|
"is_dcproxy": false,
|
|
2863
2897
|
"is_mobproxy": false,
|
|
@@ -2875,6 +2909,7 @@
|
|
|
2875
2909
|
"relay": {},
|
|
2876
2910
|
"tor": {},
|
|
2877
2911
|
"cdn": {},
|
|
2912
|
+
"bot": {},
|
|
2878
2913
|
"resproxy": {},
|
|
2879
2914
|
"dcproxy": {},
|
|
2880
2915
|
"mobproxy": {},
|
|
@@ -2949,6 +2984,7 @@
|
|
|
2949
2984
|
"isBogon": false,
|
|
2950
2985
|
"present": {
|
|
2951
2986
|
"is_satellite": true,
|
|
2987
|
+
"is_bot": false,
|
|
2952
2988
|
"is_carrier": false,
|
|
2953
2989
|
"is_web": false
|
|
2954
2990
|
},
|
|
@@ -2958,7 +2994,8 @@
|
|
|
2958
2994
|
"ssh",
|
|
2959
2995
|
"smtp",
|
|
2960
2996
|
"dns_resolver",
|
|
2961
|
-
"bittorrent"
|
|
2997
|
+
"bittorrent",
|
|
2998
|
+
"bot"
|
|
2962
2999
|
],
|
|
2963
3000
|
"satellite": {
|
|
2964
3001
|
"provider": "starlink",
|
|
@@ -3019,6 +3056,262 @@
|
|
|
3019
3056
|
},
|
|
3020
3057
|
"hostname": "customer.lsancax1.isp.starlinkisp.net"
|
|
3021
3058
|
}
|
|
3059
|
+
},
|
|
3060
|
+
{
|
|
3061
|
+
"name": "unlimited-bot",
|
|
3062
|
+
"why": "Unlimited answers is_bot, true for an address a bot uses, here a verified Googlebot crawler's; whose bot it is, the bot object, is a paid plan's and stays absent, never empty.",
|
|
3063
|
+
"status": 200,
|
|
3064
|
+
"body": {
|
|
3065
|
+
"ip": "66.249.66.1",
|
|
3066
|
+
"is_bogon": false,
|
|
3067
|
+
"is_vpn": false,
|
|
3068
|
+
"is_relay": false,
|
|
3069
|
+
"is_tor": false,
|
|
3070
|
+
"is_bot": true,
|
|
3071
|
+
"is_anycast": false,
|
|
3072
|
+
"relay": {},
|
|
3073
|
+
"tor": {},
|
|
3074
|
+
"location": {
|
|
3075
|
+
"continent": "NA",
|
|
3076
|
+
"continent_name": "North America",
|
|
3077
|
+
"country": "US",
|
|
3078
|
+
"country_name": "United States",
|
|
3079
|
+
"timezone": "America/Los_Angeles",
|
|
3080
|
+
"currency_code": "USD",
|
|
3081
|
+
"currency_name": "Dollar",
|
|
3082
|
+
"currency_symbol": "$",
|
|
3083
|
+
"flag_emoji": "🇺🇸",
|
|
3084
|
+
"flag_unicode": "U+1F1FA U+1F1F8"
|
|
3085
|
+
},
|
|
3086
|
+
"asn": {
|
|
3087
|
+
"asn": 15169,
|
|
3088
|
+
"name": "Google LLC",
|
|
3089
|
+
"domain": "google.com",
|
|
3090
|
+
"type": "hosting",
|
|
3091
|
+
"prefix": "66.249.64.0/20",
|
|
3092
|
+
"country": "US",
|
|
3093
|
+
"rpki_status": "valid"
|
|
3094
|
+
},
|
|
3095
|
+
"hostname": "crawl-66-249-66-1.googlebot.com"
|
|
3096
|
+
},
|
|
3097
|
+
"expect": {
|
|
3098
|
+
"ip": "66.249.66.1",
|
|
3099
|
+
"isBogon": false,
|
|
3100
|
+
"present": {
|
|
3101
|
+
"is_vpn": false,
|
|
3102
|
+
"is_relay": false,
|
|
3103
|
+
"is_tor": false,
|
|
3104
|
+
"is_bot": true,
|
|
3105
|
+
"is_anycast": false
|
|
3106
|
+
},
|
|
3107
|
+
"absent": [
|
|
3108
|
+
"is_hosting",
|
|
3109
|
+
"is_cdn",
|
|
3110
|
+
"is_resproxy",
|
|
3111
|
+
"is_dcproxy",
|
|
3112
|
+
"is_mobproxy",
|
|
3113
|
+
"is_pubproxy",
|
|
3114
|
+
"is_carrier",
|
|
3115
|
+
"is_satellite",
|
|
3116
|
+
"is_ssh",
|
|
3117
|
+
"is_smtp",
|
|
3118
|
+
"is_web",
|
|
3119
|
+
"is_dns_resolver",
|
|
3120
|
+
"is_bittorrent",
|
|
3121
|
+
"vpn",
|
|
3122
|
+
"hosting",
|
|
3123
|
+
"cdn",
|
|
3124
|
+
"resproxy",
|
|
3125
|
+
"dcproxy",
|
|
3126
|
+
"mobproxy",
|
|
3127
|
+
"pubproxy",
|
|
3128
|
+
"carrier",
|
|
3129
|
+
"satellite",
|
|
3130
|
+
"ssh",
|
|
3131
|
+
"smtp",
|
|
3132
|
+
"dns_resolver",
|
|
3133
|
+
"bittorrent",
|
|
3134
|
+
"web",
|
|
3135
|
+
"company",
|
|
3136
|
+
"abuse",
|
|
3137
|
+
"bot"
|
|
3138
|
+
],
|
|
3139
|
+
"emptyPresent": [
|
|
3140
|
+
"relay",
|
|
3141
|
+
"tor"
|
|
3142
|
+
],
|
|
3143
|
+
"location": {
|
|
3144
|
+
"continent": "NA",
|
|
3145
|
+
"continent_name": "North America",
|
|
3146
|
+
"country": "US",
|
|
3147
|
+
"country_name": "United States",
|
|
3148
|
+
"timezone": "America/Los_Angeles",
|
|
3149
|
+
"currency_code": "USD",
|
|
3150
|
+
"currency_name": "Dollar",
|
|
3151
|
+
"currency_symbol": "$",
|
|
3152
|
+
"flag_emoji": "🇺🇸",
|
|
3153
|
+
"flag_unicode": "U+1F1FA U+1F1F8"
|
|
3154
|
+
},
|
|
3155
|
+
"asn": {
|
|
3156
|
+
"asn": 15169,
|
|
3157
|
+
"name": "Google LLC",
|
|
3158
|
+
"domain": "google.com",
|
|
3159
|
+
"type": "hosting",
|
|
3160
|
+
"prefix": "66.249.64.0/20",
|
|
3161
|
+
"country": "US",
|
|
3162
|
+
"rpki_status": "valid"
|
|
3163
|
+
},
|
|
3164
|
+
"hostname": "crawl-66-249-66-1.googlebot.com"
|
|
3165
|
+
}
|
|
3166
|
+
},
|
|
3167
|
+
{
|
|
3168
|
+
"name": "paid-verified-bot",
|
|
3169
|
+
"why": "A paid answer names whose bot uses the address in bot: the operator by ID and name, the bots by their user agents' names, what they do, and whether the operator vouches for the address (verified, identity, verified_by), with the confidence and the first and last day. agents and categories are lists, which a client keeps in order.",
|
|
3170
|
+
"status": 200,
|
|
3171
|
+
"body": {
|
|
3172
|
+
"ip": "66.249.66.1",
|
|
3173
|
+
"is_bogon": false,
|
|
3174
|
+
"is_vpn": false,
|
|
3175
|
+
"is_hosting": false,
|
|
3176
|
+
"is_relay": false,
|
|
3177
|
+
"is_tor": false,
|
|
3178
|
+
"is_cdn": false,
|
|
3179
|
+
"is_bot": true,
|
|
3180
|
+
"is_resproxy": false,
|
|
3181
|
+
"is_dcproxy": false,
|
|
3182
|
+
"is_mobproxy": false,
|
|
3183
|
+
"is_pubproxy": false,
|
|
3184
|
+
"is_anycast": false,
|
|
3185
|
+
"is_carrier": false,
|
|
3186
|
+
"is_satellite": false,
|
|
3187
|
+
"is_ssh": false,
|
|
3188
|
+
"is_smtp": false,
|
|
3189
|
+
"is_web": false,
|
|
3190
|
+
"is_dns_resolver": false,
|
|
3191
|
+
"is_bittorrent": false,
|
|
3192
|
+
"vpn": {},
|
|
3193
|
+
"hosting": {},
|
|
3194
|
+
"relay": {},
|
|
3195
|
+
"tor": {},
|
|
3196
|
+
"cdn": {},
|
|
3197
|
+
"bot": {
|
|
3198
|
+
"provider": "google",
|
|
3199
|
+
"provider_name": "Google",
|
|
3200
|
+
"agents": [
|
|
3201
|
+
"Google-CloudVertexBot",
|
|
3202
|
+
"GoogleOther",
|
|
3203
|
+
"Googlebot"
|
|
3204
|
+
],
|
|
3205
|
+
"categories": [
|
|
3206
|
+
"ai_search",
|
|
3207
|
+
"other",
|
|
3208
|
+
"search_engine"
|
|
3209
|
+
],
|
|
3210
|
+
"verified": true,
|
|
3211
|
+
"identity": "verified",
|
|
3212
|
+
"verified_by": "list",
|
|
3213
|
+
"confidence": "high",
|
|
3214
|
+
"first_seen": "2026-11-21",
|
|
3215
|
+
"last_seen": "2026-11-21"
|
|
3216
|
+
},
|
|
3217
|
+
"resproxy": {},
|
|
3218
|
+
"dcproxy": {},
|
|
3219
|
+
"mobproxy": {},
|
|
3220
|
+
"pubproxy": {},
|
|
3221
|
+
"carrier": {},
|
|
3222
|
+
"satellite": {},
|
|
3223
|
+
"ssh": {},
|
|
3224
|
+
"smtp": {},
|
|
3225
|
+
"web": [],
|
|
3226
|
+
"dns_resolver": {},
|
|
3227
|
+
"bittorrent": {},
|
|
3228
|
+
"location": {
|
|
3229
|
+
"continent": "NA",
|
|
3230
|
+
"continent_name": "North America",
|
|
3231
|
+
"country": "US",
|
|
3232
|
+
"country_name": "United States",
|
|
3233
|
+
"timezone": "America/Los_Angeles",
|
|
3234
|
+
"currency_code": "USD",
|
|
3235
|
+
"currency_name": "US Dollar",
|
|
3236
|
+
"currency_symbol": "$",
|
|
3237
|
+
"flag_emoji": "🇺🇸",
|
|
3238
|
+
"flag_unicode": "U+1F1FA U+1F1F8",
|
|
3239
|
+
"region": "California",
|
|
3240
|
+
"region_code": "US-CA",
|
|
3241
|
+
"city": "Los Angeles",
|
|
3242
|
+
"postal_code": "90001",
|
|
3243
|
+
"latitude": 34.05223,
|
|
3244
|
+
"longitude": -118.24368,
|
|
3245
|
+
"accuracy_radius": 500,
|
|
3246
|
+
"geoname_id": "5368361",
|
|
3247
|
+
"dma_code": "803",
|
|
3248
|
+
"last_changed": "2026-10-20"
|
|
3249
|
+
},
|
|
3250
|
+
"asn": {
|
|
3251
|
+
"asn": 14593,
|
|
3252
|
+
"name": "Space Exploration Technologies Corporation",
|
|
3253
|
+
"domain": "spacex.com",
|
|
3254
|
+
"type": "isp",
|
|
3255
|
+
"prefix": "98.97.0.0/20",
|
|
3256
|
+
"country": "US",
|
|
3257
|
+
"rpki_status": "valid"
|
|
3258
|
+
},
|
|
3259
|
+
"company": {
|
|
3260
|
+
"name": "Starlink",
|
|
3261
|
+
"domain": "starlink.com",
|
|
3262
|
+
"type": "isp",
|
|
3263
|
+
"country": "US"
|
|
3264
|
+
},
|
|
3265
|
+
"hostname": "customer.lsancax1.isp.starlinkisp.net",
|
|
3266
|
+
"abuse": {
|
|
3267
|
+
"email": "abuse@spacex.com",
|
|
3268
|
+
"name": "SpaceX Abuse",
|
|
3269
|
+
"phone": "",
|
|
3270
|
+
"address": "Hawthorne, CA, US",
|
|
3271
|
+
"country": "US",
|
|
3272
|
+
"network": "98.97.0.0-98.97.15.255",
|
|
3273
|
+
"validated": true,
|
|
3274
|
+
"unvalidated_since": ""
|
|
3275
|
+
},
|
|
3276
|
+
"cap_reached": false
|
|
3277
|
+
},
|
|
3278
|
+
"expect": {
|
|
3279
|
+
"ip": "66.249.66.1",
|
|
3280
|
+
"isBogon": false,
|
|
3281
|
+
"present": {
|
|
3282
|
+
"is_vpn": false,
|
|
3283
|
+
"is_bot": true,
|
|
3284
|
+
"is_hosting": false,
|
|
3285
|
+
"is_satellite": false
|
|
3286
|
+
},
|
|
3287
|
+
"absent": [],
|
|
3288
|
+
"emptyPresent": [
|
|
3289
|
+
"vpn",
|
|
3290
|
+
"hosting",
|
|
3291
|
+
"satellite",
|
|
3292
|
+
"cdn"
|
|
3293
|
+
],
|
|
3294
|
+
"bot": {
|
|
3295
|
+
"provider": "google",
|
|
3296
|
+
"provider_name": "Google",
|
|
3297
|
+
"agents": [
|
|
3298
|
+
"Google-CloudVertexBot",
|
|
3299
|
+
"GoogleOther",
|
|
3300
|
+
"Googlebot"
|
|
3301
|
+
],
|
|
3302
|
+
"categories": [
|
|
3303
|
+
"ai_search",
|
|
3304
|
+
"other",
|
|
3305
|
+
"search_engine"
|
|
3306
|
+
],
|
|
3307
|
+
"verified": true,
|
|
3308
|
+
"identity": "verified",
|
|
3309
|
+
"verified_by": "list",
|
|
3310
|
+
"confidence": "high",
|
|
3311
|
+
"first_seen": "2026-11-21",
|
|
3312
|
+
"last_seen": "2026-11-21"
|
|
3313
|
+
}
|
|
3314
|
+
}
|
|
3022
3315
|
}
|
|
3023
3316
|
],
|
|
3024
3317
|
"errors": [
|
|
@@ -8072,7 +8365,9 @@
|
|
|
8072
8365
|
"name": "M247 Europe SRL",
|
|
8073
8366
|
"domain": "m247global.com",
|
|
8074
8367
|
"type": "hosting",
|
|
8075
|
-
"prefix": "146.70.116.0/24"
|
|
8368
|
+
"prefix": "146.70.116.0/24",
|
|
8369
|
+
"country": "US",
|
|
8370
|
+
"rpki_status": "valid"
|
|
8076
8371
|
}
|
|
8077
8372
|
},
|
|
8078
8373
|
"condition": {
|
|
@@ -8112,7 +8407,9 @@
|
|
|
8112
8407
|
"name": "M247 Europe SRL",
|
|
8113
8408
|
"domain": "m247global.com",
|
|
8114
8409
|
"type": "hosting",
|
|
8115
|
-
"prefix": "146.70.116.0/24"
|
|
8410
|
+
"prefix": "146.70.116.0/24",
|
|
8411
|
+
"country": "US",
|
|
8412
|
+
"rpki_status": "valid"
|
|
8116
8413
|
}
|
|
8117
8414
|
},
|
|
8118
8415
|
"condition": {
|
|
@@ -8155,7 +8452,9 @@
|
|
|
8155
8452
|
"name": "M247 Europe SRL",
|
|
8156
8453
|
"domain": "m247global.com",
|
|
8157
8454
|
"type": "hosting",
|
|
8158
|
-
"prefix": "146.70.116.0/24"
|
|
8455
|
+
"prefix": "146.70.116.0/24",
|
|
8456
|
+
"country": "US",
|
|
8457
|
+
"rpki_status": "valid"
|
|
8159
8458
|
}
|
|
8160
8459
|
},
|
|
8161
8460
|
"condition": {
|
|
@@ -8195,7 +8494,9 @@
|
|
|
8195
8494
|
"name": "M247 Europe SRL",
|
|
8196
8495
|
"domain": "m247global.com",
|
|
8197
8496
|
"type": "hosting",
|
|
8198
|
-
"prefix": "146.70.116.0/24"
|
|
8497
|
+
"prefix": "146.70.116.0/24",
|
|
8498
|
+
"country": "US",
|
|
8499
|
+
"rpki_status": "valid"
|
|
8199
8500
|
}
|
|
8200
8501
|
},
|
|
8201
8502
|
"condition": {
|
|
@@ -8235,7 +8536,9 @@
|
|
|
8235
8536
|
"name": "M247 Europe SRL",
|
|
8236
8537
|
"domain": "m247global.com",
|
|
8237
8538
|
"type": "hosting",
|
|
8238
|
-
"prefix": "146.70.116.0/24"
|
|
8539
|
+
"prefix": "146.70.116.0/24",
|
|
8540
|
+
"country": "US",
|
|
8541
|
+
"rpki_status": "valid"
|
|
8239
8542
|
}
|
|
8240
8543
|
},
|
|
8241
8544
|
"condition": {
|
|
@@ -106,6 +106,19 @@ def test_blocks_when_the_condition_matches_and_the_endpoint_never_runs() -> None
|
|
|
106
106
|
assert status == 200
|
|
107
107
|
|
|
108
108
|
|
|
109
|
+
@pytest.mark.parametrize("condition", [{"is_bot": True}, {"bot": {"verified": True}}])
|
|
110
|
+
def test_a_condition_on_a_bot_blocks_a_bot_and_passes_the_rest(
|
|
111
|
+
condition: dict[str, Any],
|
|
112
|
+
) -> None:
|
|
113
|
+
for is_bot, bot in ((True, {"provider": "google", "verified": True}), (False, {})):
|
|
114
|
+
served = serving({"is_vpn": False, "is_bot": is_bot, "bot": bot})
|
|
115
|
+
status, _ = get(
|
|
116
|
+
app_with(client=served, ip_selector=fixed_ip, block_condition=condition)
|
|
117
|
+
)
|
|
118
|
+
assert status == (403 if is_bot else 200), f"{condition} against is_bot {is_bot}"
|
|
119
|
+
assert served.asked == [PUBLIC_IP]
|
|
120
|
+
|
|
121
|
+
|
|
109
122
|
def test_a_condition_reaches_the_evidence_fields() -> None:
|
|
110
123
|
nord = serving({"is_vpn": True, "vpn": {"provider": "nordvpn"}})
|
|
111
124
|
status, _ = get(
|
|
@@ -406,3 +419,119 @@ def test_the_readme_middleware_sends_its_key_for_a_public_peer(
|
|
|
406
419
|
assert body["error"] is None and body["is_vpn"] is True
|
|
407
420
|
assert len(sent) == 1 and sent[0][0].endswith(PUBLIC_IP)
|
|
408
421
|
assert sent[0][1] == "Bearer a-key"
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
GOOGLEBOT = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
def api_answering(
|
|
428
|
+
monkeypatch: pytest.MonkeyPatch, verdicts: dict[str, str] | None
|
|
429
|
+
) -> list[str | None]:
|
|
430
|
+
"""The API's host, answering every lookup as a match for ``{"is_hosting": True}`` and,
|
|
431
|
+
for a sent agent, with the verdict ``verdicts`` holds for it (None: no verdict, as
|
|
432
|
+
Unlimited answers). Returns the ``user_agent`` each lookup sent."""
|
|
433
|
+
sent: list[str | None] = []
|
|
434
|
+
|
|
435
|
+
async def handle(
|
|
436
|
+
_transport: httpx.AsyncHTTPTransport, request: httpx.Request
|
|
437
|
+
) -> httpx.Response:
|
|
438
|
+
if request.url.host != "api.vpndetection.io":
|
|
439
|
+
raise httpx.ConnectError("only the API's host answers here", request=request)
|
|
440
|
+
agent = request.url.params.get("user_agent")
|
|
441
|
+
sent.append(agent)
|
|
442
|
+
body: dict[str, Any] = {
|
|
443
|
+
"ip": request.url.path.lstrip("/"),
|
|
444
|
+
"is_vpn": False,
|
|
445
|
+
"is_hosting": True,
|
|
446
|
+
}
|
|
447
|
+
if agent and verdicts is not None:
|
|
448
|
+
verdict = verdicts.get(agent, "not_bot")
|
|
449
|
+
body["user_agent"] = {"agent": "Googlebot", "kind": "bot", "verdict": verdict}
|
|
450
|
+
return httpx.Response(200, json=body)
|
|
451
|
+
|
|
452
|
+
monkeypatch.setattr(httpx.AsyncHTTPTransport, "handle_async_request", handle)
|
|
453
|
+
monkeypatch.setenv("VPNDETECTION_API_KEY", "a-key")
|
|
454
|
+
return sent
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def visit(app: Any, *requests: tuple[str | None, str, str]) -> list[int]:
|
|
458
|
+
"""Each (User-Agent, path, peer) through one app, answering each status."""
|
|
459
|
+
statuses: list[int] = []
|
|
460
|
+
for user_agent, url, peer in requests:
|
|
461
|
+
with TestClient(app, client=(peer, 12345)) as client:
|
|
462
|
+
# The test client sends a User-Agent of its own unless told otherwise.
|
|
463
|
+
client.headers.pop("User-Agent", None)
|
|
464
|
+
headers = {} if user_agent is None else {"User-Agent": user_agent}
|
|
465
|
+
statuses.append(client.get(url, headers=headers).status_code)
|
|
466
|
+
return statuses
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
def readme_app(**options: Any) -> FastAPI:
|
|
470
|
+
"""The README's build, plus ``options``, with ``/guarded`` depending on
|
|
471
|
+
``block_if({"is_hosting": True})``."""
|
|
472
|
+
return fastapi_with(
|
|
473
|
+
{"condition": {"is_hosting": True}},
|
|
474
|
+
api_key=os.environ["VPNDETECTION_API_KEY"],
|
|
475
|
+
**options,
|
|
476
|
+
)
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
def test_allow_bots_sends_the_requests_own_user_agent(
|
|
480
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
481
|
+
) -> None:
|
|
482
|
+
sent = api_answering(monkeypatch, {GOOGLEBOT: "verified"})
|
|
483
|
+
|
|
484
|
+
visit(
|
|
485
|
+
readme_app(allow_bots=True),
|
|
486
|
+
(GOOGLEBOT, "/", PUBLIC_IP),
|
|
487
|
+
("", "/", "45.83.91.2"),
|
|
488
|
+
(None, "/", "45.83.91.3"),
|
|
489
|
+
)
|
|
490
|
+
|
|
491
|
+
assert sent == [GOOGLEBOT, None, None], "an empty or absent header sent an agent"
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
def test_without_allow_bots_no_user_agent_is_sent(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
495
|
+
sent = api_answering(monkeypatch, {GOOGLEBOT: "verified"})
|
|
496
|
+
|
|
497
|
+
statuses = visit(
|
|
498
|
+
readme_app(block_condition={"is_hosting": True}), (GOOGLEBOT, "/", PUBLIC_IP)
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
assert sent == [None]
|
|
502
|
+
assert statuses == [403]
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
@pytest.mark.parametrize(
|
|
506
|
+
("verdict", "status"), [("verified", 200), ("spoofed", 403), ("not_bot", 403)]
|
|
507
|
+
)
|
|
508
|
+
@pytest.mark.parametrize("url", ["/", "/guarded"])
|
|
509
|
+
def test_a_verified_crawler_passes_a_condition_it_meets_and_no_other_does(
|
|
510
|
+
monkeypatch: pytest.MonkeyPatch, url: str, verdict: str, status: int
|
|
511
|
+
) -> None:
|
|
512
|
+
api_answering(monkeypatch, {GOOGLEBOT: verdict})
|
|
513
|
+
options: dict[str, Any] = {"allow_bots": True}
|
|
514
|
+
if url == "/":
|
|
515
|
+
options["block_condition"] = {"is_hosting": True}
|
|
516
|
+
|
|
517
|
+
assert visit(readme_app(**options), (GOOGLEBOT, url, PUBLIC_IP)) == [status]
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
def test_a_condition_naming_the_verdict_refuses_a_forged_crawler(
|
|
521
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
522
|
+
) -> None:
|
|
523
|
+
api_answering(monkeypatch, {GOOGLEBOT: "spoofed"})
|
|
524
|
+
app = readme_app(allow_bots=True, block_condition={"user_agent": {"verdict": "spoofed"}})
|
|
525
|
+
|
|
526
|
+
assert visit(app, (GOOGLEBOT, "/", PUBLIC_IP)) == [403]
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
def test_an_answer_without_a_verdict_warns_once(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
530
|
+
sent = api_answering(monkeypatch, None)
|
|
531
|
+
warnings: list[str] = []
|
|
532
|
+
app = readme_app(allow_bots=True, on_warn=warnings.append)
|
|
533
|
+
|
|
534
|
+
visit(app, (GOOGLEBOT, "/", PUBLIC_IP), (GOOGLEBOT, "/", "45.83.91.2"))
|
|
535
|
+
|
|
536
|
+
assert sent == [GOOGLEBOT, GOOGLEBOT]
|
|
537
|
+
assert len([w for w in warnings if "user_agent verdict" in w]) == 1, warnings
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{vpndetection_fastapi-2.1.28 → vpndetection_fastapi-2.2.0}/src/vpndetection_fastapi/py.typed
RENAMED
|
File without changes
|
|
File without changes
|