@@ -869,15 +869,15 @@ class TestIntegration(Integration):
869869
870870
871871@pytest .fixture
872- def mock_client_with_dsn_netloc ():
872+ def mock_client_with_dsn ():
873873 """
874- Returns a mocked Client with a DSN netloc of "abcd1234.ingest.sentry.io".
874+ Returns a mocked Client with a DSN host of "abcd1234.ingest.sentry.io".
875875 """
876876 mock_client = mock .Mock (spec = sentry_sdk .Client )
877877 mock_client .transport = mock .Mock (spec = sentry_sdk .Transport )
878878 mock_client .transport .parsed_dsn = mock .Mock (spec = Dsn )
879879
880- mock_client .transport .parsed_dsn .netloc = "abcd1234.ingest.sentry.io"
880+ mock_client .transport .parsed_dsn .host = "abcd1234.ingest.sentry.io"
881881
882882 return mock_client
883883
@@ -886,13 +886,37 @@ def mock_client_with_dsn_netloc():
886886 ["test_url" , "is_sentry_url_expected" ],
887887 [
888888 ["https://asdf@abcd1234.ingest.sentry.io/123456789" , True ],
889+ ["HTTP://ABCD1234.INGEST.SENTRY.IO:8443/envelope" , True ],
890+ ["abcd1234.ingest.sentry.io" , True ],
891+ ["abcd1234.ingest.sentry.io:9000" , True ],
889892 ["https://asdf@abcd1234.ingest.notsentry.io/123456789" , False ],
893+ ["https://abcd1234.ingest.sentry.io.evil.test/api/1" , False ],
894+ ["https://abcd1234.ingest.sentry.io@attacker.test/api/1" , False ],
895+ ["https://attacker.test/abcd1234.ingest.sentry.io" , False ],
896+ ["https://attacker.test/?next=abcd1234.ingest.sentry.io" , False ],
897+ ["abcd1234.ingest.sentry.io.evil.test" , False ],
898+ ["https://[::1" , False ],
890899 ],
891900)
892- def test_is_sentry_url_true (
893- test_url , is_sentry_url_expected , mock_client_with_dsn_netloc
894- ):
895- ret_val = is_sentry_url (mock_client_with_dsn_netloc , test_url )
901+ def test_is_sentry_url (test_url , is_sentry_url_expected , mock_client_with_dsn ):
902+ ret_val = is_sentry_url (mock_client_with_dsn , test_url )
903+
904+ assert ret_val == is_sentry_url_expected
905+
906+
907+ @pytest .mark .parametrize (
908+ ["test_url" , "is_sentry_url_expected" ],
909+ [
910+ ["2001:db8::1" , True ],
911+ ["[2001:db8::1]:9000" , True ],
912+ ["HTTP://[2001:DB8::1]:9000/envelope" , True ],
913+ ["http://[2001:db8::2]:9000/envelope" , False ],
914+ ],
915+ )
916+ def test_is_sentry_url_ipv6 (test_url , is_sentry_url_expected , mock_client_with_dsn ):
917+ mock_client_with_dsn .transport .parsed_dsn .host = "2001:db8::1"
918+
919+ ret_val = is_sentry_url (mock_client_with_dsn , test_url )
896920
897921 assert ret_val == is_sentry_url_expected
898922
0 commit comments