Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: fix shadowing of make_request in tests #74801

Merged
merged 1 commit into from
Jul 23, 2024
Merged
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
38 changes: 19 additions & 19 deletions tests/sentry/utils/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_does_not_authenticate_with_invalid_password(self):

@control_silo_test
class GetLoginRedirectTest(TestCase):
def make_request(self, next=None):
def _make_request(self, next=None):
request = HttpRequest()
request.META["SERVER_NAME"] = "testserver"
request.META["SERVER_PORT"] = "80"
Expand All @@ -67,75 +67,75 @@ def make_request(self, next=None):
return request

def test_schema_uses_default(self):
result = get_login_redirect(self.make_request("http://example.com"))
result = get_login_redirect(self._make_request("http://example.com"))
assert result == reverse("sentry-login")

result = get_login_redirect(self.make_request("ftp://testserver"))
result = get_login_redirect(self._make_request("ftp://testserver"))
assert result == reverse("sentry-login")

def test_next(self):
result = get_login_redirect(self.make_request("http://testserver/foobar/"))
result = get_login_redirect(self._make_request("http://testserver/foobar/"))
assert result == "http://testserver/foobar/"

result = get_login_redirect(self.make_request("ftp://testserver/foobar/"))
result = get_login_redirect(self._make_request("ftp://testserver/foobar/"))
assert result == reverse("sentry-login")

request = self.make_request("/foobar/")
request = self._make_request("/foobar/")
request.subdomain = "orgslug"
result = get_login_redirect(request)
assert result == "http://orgslug.testserver/foobar/"

request = self.make_request("http://testserver/foobar/")
request = self._make_request("http://testserver/foobar/")
request.subdomain = "orgslug"
result = get_login_redirect(request)
assert result == "http://testserver/foobar/"

request = self.make_request("ftp://testserver/foobar/")
request = self._make_request("ftp://testserver/foobar/")
request.subdomain = "orgslug"
result = get_login_redirect(request)
assert result == f"http://orgslug.testserver{reverse('sentry-login')}"

def test_after_2fa(self):
request = self.make_request()
request = self._make_request()
request.session["_after_2fa"] = "http://testserver/foobar/"
result = get_login_redirect(request)
assert result == "http://testserver/foobar/"

request = self.make_request()
request = self._make_request()
request.subdomain = "orgslug"
request.session["_after_2fa"] = "/foobar/"
result = get_login_redirect(request)
assert result == "http://orgslug.testserver/foobar/"

def test_pending_2fa(self):
request = self.make_request()
request = self._make_request()
request.session["_pending_2fa"] = [1234, 1234, 1234]
result = get_login_redirect(request)
assert result == reverse("sentry-2fa-dialog")

request = self.make_request()
request = self._make_request()
request.subdomain = "orgslug"
request.session["_pending_2fa"] = [1234, 1234, 1234]
result = get_login_redirect(request)
assert result == f"http://orgslug.testserver{reverse('sentry-2fa-dialog')}"

def test_login_uses_default(self):
result = get_login_redirect(self.make_request(reverse("sentry-login")))
result = get_login_redirect(self._make_request(reverse("sentry-login")))
assert result == reverse("sentry-login")

def test_no_value_uses_default(self):
result = get_login_redirect(self.make_request())
result = get_login_redirect(self._make_request())
assert result == reverse("sentry-login")

request = self.make_request()
request = self._make_request()
request.subdomain = "orgslug"
result = get_login_redirect(request)
assert result == f"http://orgslug.testserver{reverse('sentry-login')}"


@control_silo_test
class LoginTest(TestCase):
def make_request(self, next=None):
def _make_request(self, next=None):
request = HttpRequest()
request.META["REMOTE_ADDR"] = "127.0.0.1"
request.session = self.session
Expand All @@ -145,14 +145,14 @@ def make_request(self, next=None):
return request

def test_simple(self):
request = self.make_request()
request = self._make_request()
assert login(request, self.user)
assert request.user == self.user
assert "_nonce" not in request.session

def test_with_organization(self):
org = self.create_organization(name="foo", owner=self.user)
request = self.make_request()
request = self._make_request()
assert login(request, self.user, organization_id=org.id)
assert request.user == self.user
assert f"{SsoSession.SSO_SESSION_KEY}:{org.id}" in request.session
Expand All @@ -161,7 +161,7 @@ def test_with_nonce(self):
self.user.refresh_session_nonce()
self.user.save()
assert self.user.session_nonce is not None
request = self.make_request()
request = self._make_request()
assert login(request, self.user)
assert request.user == self.user
assert request.session["_nonce"] == self.user.session_nonce
Expand Down
Loading