Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
bugfix: Make DSN secret optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko authored and ashwoods committed Apr 18, 2018
1 parent 9a4eaaa commit d29fed6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion raven/conf/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def from_string(cls, value, transport=None, transport_registry=None):
path = ''
project = path_bits[-1]

if not all([netloc, project, url.username, url.password]):
if not all([netloc, project, url.username]):
raise InvalidDsn('Invalid Sentry DSN: %r' % url.geturl())

base_url = '%s://%s%s' % (url.scheme.rsplit('+', 1)[-1], netloc, path)
Expand Down
21 changes: 17 additions & 4 deletions tests/conf/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from raven.conf import setup_logging
from raven.conf.remote import RemoteConfig
from raven.exceptions import InvalidDsn
from raven.utils import get_auth_header
from raven.utils.testutils import TestCase


Expand Down Expand Up @@ -80,6 +81,22 @@ def test_options(self):
assert res.secret_key == 'bar'
assert res.options == {'timeout': '1'}

def test_no_secret_key(self):
dsn = 'https://foo@sentry.local/1'
res = RemoteConfig.from_string(dsn)
assert res.project == '1'
assert res.base_url == 'https://sentry.local'
assert res.store_endpoint == 'https://sentry.local/api/1/store/'
assert res.public_key == 'foo'
assert res.secret_key is None
assert res.options == {}

assert get_auth_header(protocol=7, timestamp=42,
client='raven-python/1.0',
api_key=res.public_key) == (
'Sentry sentry_timestamp=42, sentry_client=raven-python/1.0, '
'sentry_version=7, sentry_key=foo')

def test_missing_netloc(self):
dsn = 'https://foo:bar@/1'
self.assertRaises(InvalidDsn, RemoteConfig.from_string, dsn)
Expand All @@ -92,10 +109,6 @@ def test_missing_public_key(self):
dsn = 'https://:bar@example.com'
self.assertRaises(InvalidDsn, RemoteConfig.from_string, dsn)

def test_missing_secret_key(self):
dsn = 'https://bar@example.com'
self.assertRaises(InvalidDsn, RemoteConfig.from_string, dsn)

def test_invalid_scheme(self):
dsn = 'ftp://foo:bar@sentry.local/1'
self.assertRaises(InvalidDsn, RemoteConfig.from_string, dsn)
Expand Down

0 comments on commit d29fed6

Please sign in to comment.