Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,19 @@ def __init__(
org_id_match = Dsn.ORG_ID_REGEX.match(self.host)
self.org_id = org_id_match.group(1) if org_id_match else None

if parts.port is None:
try:
# `urlsplit` parses the port lazily and raises a bare `ValueError`
# for ports that are not an integer in the range 0-65535.
port = parts.port
except ValueError:
raise BadDsn(
"Invalid port in DSN (%r)" % (parts.netloc.rpartition("@")[-1],)
)

if port is None:
self.port: int = self.scheme == "https" and 443 or 80
else:
self.port = parts.port
self.port = port

if not parts.username:
raise BadDsn("Missing public key")
Expand Down
5 changes: 5 additions & 0 deletions tests/utils/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ def test_parse_invalid_dsn(dsn):
("foo://barbaz@sentry.io", "Unsupported scheme 'foo'"),
("https://foobar@", "Missing hostname"),
("https://@sentry.io", "Missing public key"),
("https://foobar@example.com:foo/1", "Invalid port in DSN ('example.com:foo')"),
(
"https://foobar@example.com:65536/1",
"Invalid port in DSN ('example.com:65536')",
),
],
)
def test_dsn_validations(dsn, error_message):
Expand Down
Loading