test_sso.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from __future__ import absolute_import
  2. import six
  3. from sentry.models import AuthIdentity, AuthProvider
  4. from sentry.testutils import AuthProviderTestCase
  5. from sentry.utils.auth import SSO_SESSION_KEY
  6. class OrganizationAuthLoginTest(AuthProviderTestCase):
  7. def test_sso_auth_required(self):
  8. user = self.create_user("foo@example.com", is_superuser=False)
  9. organization = self.create_organization(name="foo")
  10. member = self.create_member(user=user, organization=organization)
  11. setattr(member.flags, "sso:linked", True)
  12. member.save()
  13. auth_provider = AuthProvider.objects.create(
  14. organization=organization, provider="dummy", flags=0
  15. )
  16. AuthIdentity.objects.create(auth_provider=auth_provider, user=user)
  17. self.login_as(user)
  18. path = u"/{}/".format(organization.slug)
  19. redirect_uri = u"http://testserver/auth/login/{}/".format(organization.slug)
  20. # we should be redirecting the user to the authentication form as they
  21. # haven't verified this specific organization
  22. resp = self.client.get(path)
  23. assert resp.status_code == 302
  24. assert resp["Location"] == redirect_uri
  25. # superuser should still require SSO as they're a member of the org
  26. user.update(is_superuser=True)
  27. resp = self.client.get(path)
  28. assert resp.status_code == 302
  29. assert resp["Location"] == redirect_uri
  30. # XXX(dcramer): using internal API as exposing a request object is hard
  31. self.session[SSO_SESSION_KEY] = six.text_type(organization.id)
  32. self.save_session()
  33. # now that SSO is marked as complete, we should be able to access dash
  34. resp = self.client.get(path)
  35. assert resp.status_code == 200