Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aliu39 committed Sep 21, 2024
1 parent d20ff40 commit 5665b05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 43 deletions.
57 changes: 16 additions & 41 deletions tests/sentry/toolbar/utils/test_url.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,29 @@
from sentry.toolbar.utils.url import url_matches


class UrlMatchesTest:
def __init__(self, test_cases):
self.test_cases = test_cases

def run(self):
for url, target_url, expected in self.test_cases:
assert url_matches(url, target_url) == expected


def test_url_matches_basic():
UrlMatchesTest(
[
("http://abc.net", "http://abc.net", True),
("http://pocketpair.io", "http://sentry.io", False),
("http://sentry.io/issues/", "http://sentry.io", True),
("http://sentry.io", "http://sentry.io/issues/", True),
("https://cmu.edu", "https://cmu.com", False),
("https://youtube.com:443/watch?v=3xhb", "https://youtube.com/profile", True),
]
).run()
assert url_matches("http://abc.net", "http://abc.net")
assert not url_matches("http://pocketpair.io", "http://sentry.io")
assert url_matches("http://sentry.io/issues/", "http://sentry.io")
assert url_matches("http://sentry.io", "http://sentry.io/issues/")
assert not url_matches("https://cmu.edu", "https://cmu.com")
assert url_matches("https://youtube.com:443/watch?v=3xhb", "https://youtube.com/profile")


def test_url_matches_wildcard():
UrlMatchesTest(
[
("https://nugettrends.sentry.io", "https://*.sentry.io", True),
("https://nugettrends.sentry.com", "https://*.sentry.io", False),
("https://nugettrends.sentry.io", "https://*.io", False),
("https://sentry.io", "https://*.sentry.io", False),
]
).run()
assert url_matches("https://nugettrends.sentry.io", "https://*.sentry.io")
assert not url_matches("https://nugettrends.sentry.com", "https://*.sentry.io")
assert not url_matches("https://nugettrends.sentry.io", "https://*.io")
assert not url_matches("https://sentry.io", "https://*.sentry.io")


def test_url_matches_port():
UrlMatchesTest(
[
("https://sentry.io:42", "https://sentry.io:42", True),
("https://sentry.io", "https://sentry.io:42", False),
("https://sentry.io:42", "https://sentry.io", True),
]
).run()
assert url_matches("https://sentry.io:42", "https://sentry.io:42")
assert not url_matches("https://sentry.io", "https://sentry.io:42")
assert url_matches("https://sentry.io:42", "https://sentry.io")


def test_url_matches_scheme():
UrlMatchesTest(
[
("https://sentry.io", "sentry.io", True),
("http://sentry.io", "sentry.io", True),
("http://sentry.io", "https://sentry.io", False),
]
).run()
assert url_matches("https://sentry.io", "sentry.io")
assert url_matches("http://sentry.io", "sentry.io")
assert not url_matches("http://sentry.io", "https://sentry.io")
2 changes: 0 additions & 2 deletions tests/sentry/toolbar/views/test_iframe_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ def test_allowed_origins_wildcard_subdomain(self):
assert res.status_code == 403

def test_no_referrer(self):
res = self.client.get(self.url)
assert res.status_code == 403
self.project.update_option("sentry:toolbar_allowed_origins", ["sentry.io"])
res = self.client.get(self.url)
assert res.status_code == 403
Expand Down

0 comments on commit 5665b05

Please sign in to comment.