test_react_page.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. from django.urls import reverse
  2. from sentry.testutils import TestCase
  3. class ReactPageViewTest(TestCase):
  4. def test_redirects_unauthenticated_request(self):
  5. owner = self.create_user("bar@example.com")
  6. org = self.create_organization(owner=owner)
  7. path = reverse("sentry-organization-home", args=[org.slug])
  8. resp = self.client.get(path)
  9. self.assertRedirects(resp, reverse("sentry-auth-organization", args=[org.slug]))
  10. assert resp["X-Robots-Tag"] == "noindex, nofollow"
  11. def test_superuser_can_load(self):
  12. org = self.create_organization(owner=self.user)
  13. path = reverse("sentry-organization-home", args=[org.slug])
  14. self.login_as(self.user)
  15. resp = self.client.get(path)
  16. assert resp.status_code == 200
  17. self.assertTemplateUsed(resp, "sentry/bases/react.html")
  18. assert resp.context["request"]
  19. def test_redirects_user_to_auth_without_membership(self):
  20. owner = self.create_user("bar@example.com")
  21. org = self.create_organization(owner=owner)
  22. non_member = self.create_user("foo@example.com")
  23. path = reverse("sentry-organization-home", args=[org.slug])
  24. self.login_as(non_member)
  25. resp = self.client.get(path)
  26. self.assertRedirects(resp, reverse("sentry-auth-organization", args=[org.slug]))
  27. # ensure we dont redirect to auth if its not a valid org
  28. path = reverse("sentry-organization-home", args=["foobar"])
  29. resp = self.client.get(path)
  30. assert resp.status_code == 302
  31. assert resp["Location"] != reverse("sentry-auth-organization", args=[org.slug])
  32. # ensure we dont redirect with valid membership
  33. path = reverse("sentry-organization-home", args=[org.slug])
  34. self.login_as(owner)
  35. resp = self.client.get(path)
  36. assert resp.status_code == 200
  37. self.assertTemplateUsed(resp, "sentry/bases/react.html")
  38. assert resp.context["request"]
  39. def test_inactive_superuser_bypasses_server_auth(self):
  40. owner = self.create_user("bar@example.com")
  41. org = self.create_organization(owner=owner)
  42. non_member = self.create_user("foo@example.com", is_superuser=True)
  43. path = reverse("sentry-organization-home", args=[org.slug])
  44. self.login_as(non_member)
  45. resp = self.client.get(path)
  46. assert resp.status_code == 200
  47. self.assertTemplateUsed(resp, "sentry/bases/react.html")
  48. assert resp.context["request"]
  49. def test_org_subpages_capture_slug(self):
  50. owner = self.create_user("bar@example.com")
  51. org = self.create_organization(owner=owner)
  52. # User is *not* logged in. Check for redirect to org's auth login.
  53. # TODO(RyanSkonnord): Generalize URL pattern; add
  54. # f"/organizations/{org.slug}/new_page_that_does_not_exist_yet/"
  55. # to list of test paths without causing other regressions.
  56. # See OrganizationReleasesTest.test_detail_global_header,
  57. # which exposes a buggy interaction with appendTrailingSlash
  58. # in static/app/routes.tsx.
  59. for path in [
  60. f"/organizations/{org.slug}/settings/",
  61. f"/organizations/{org.slug}/discover/",
  62. f"/settings/{org.slug}/developer-settings/",
  63. f"/settings/{org.slug}/new_page_that_does_not_exist_yet/",
  64. ]:
  65. resp = self.client.get(path)
  66. assert resp.status_code == 302
  67. assert resp.url == f"/auth/login/{org.slug}/"