|
13 | 13 | Components, |
14 | 14 | Dsn, |
15 | 15 | _get_installed_modules, |
| 16 | + _is_localhost, |
16 | 17 | datetime_from_isoformat, |
17 | 18 | ensure_integration_enabled, |
18 | 19 | env_to_bool, |
@@ -1409,3 +1410,53 @@ def __init__(self): |
1409 | 1410 |
|
1410 | 1411 | def test_package_version_is_none(): |
1411 | 1412 | assert package_version("non_existent_package") is None |
| 1413 | + |
| 1414 | + |
| 1415 | +@pytest.mark.parametrize( |
| 1416 | + "kwargs, expected", |
| 1417 | + [ |
| 1418 | + # Client IP matches |
| 1419 | + ({"client_ip": "127.0.0.1"}, True), |
| 1420 | + ({"client_ip": "::1"}, True), |
| 1421 | + ({"client_ip": "192.168.1.1"}, False), |
| 1422 | + ({"client_ip": "10.0.0.1"}, False), |
| 1423 | + ({"client_ip": "8.8.8.8"}, False), |
| 1424 | + ({"client_ip": "::2"}, False), |
| 1425 | + # URL host (subdomain-aware matching) |
| 1426 | + ({"url_host": "localhost"}, True), |
| 1427 | + ({"url_host": "127.0.0.1"}, True), |
| 1428 | + ({"url_host": "foo.localhost"}, True), |
| 1429 | + ({"url_host": "bar.foo.localhost"}, True), |
| 1430 | + ({"url_host": "foolocalhost"}, False), |
| 1431 | + ({"url_host": "notlocalhost"}, False), |
| 1432 | + ({"url_host": "example.com"}, False), |
| 1433 | + # Host header (subdomain-aware matching after port strip) |
| 1434 | + ({"host_header": "localhost"}, True), |
| 1435 | + ({"host_header": "localhost:3000"}, True), |
| 1436 | + ({"host_header": "127.0.0.1:8080"}, True), |
| 1437 | + ({"host_header": "foo.localhost"}, True), |
| 1438 | + ({"host_header": "foo.localhost:8080"}, True), |
| 1439 | + ({"host_header": "example.com"}, False), |
| 1440 | + ({"host_header": "localhost.example.com"}, False), |
| 1441 | + # X-Forwarded-Host header |
| 1442 | + ({"forwarded_host_header": "localhost"}, True), |
| 1443 | + ({"forwarded_host_header": "localhost:3000"}, True), |
| 1444 | + ({"forwarded_host_header": "127.0.0.1:8080"}, True), |
| 1445 | + ({"forwarded_host_header": "foo.localhost"}, True), |
| 1446 | + ({"forwarded_host_header": "example.com"}, False), |
| 1447 | + # No args |
| 1448 | + ({}, False), |
| 1449 | + # All non-local |
| 1450 | + ( |
| 1451 | + { |
| 1452 | + "client_ip": "8.8.8.8", |
| 1453 | + "url_host": "example.com", |
| 1454 | + "host_header": "example.com", |
| 1455 | + "forwarded_host_header": "example.com", |
| 1456 | + }, |
| 1457 | + False, |
| 1458 | + ), |
| 1459 | + ], |
| 1460 | +) |
| 1461 | +def test_is_localhost(kwargs, expected): |
| 1462 | + assert _is_localhost(**kwargs) is expected |
0 commit comments