test_sso.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. # TODO(dcramer): this is an integration test
  7. class OrganizationAuthLoginTest(AuthProviderTestCase):
  8. def test_sso_auth_required(self):
  9. user = self.create_user('foo@example.com', is_superuser=False)
  10. organization = self.create_organization(name='foo')
  11. member = self.create_member(user=user, organization=organization)
  12. setattr(member.flags, 'sso:linked', True)
  13. member.save()
  14. auth_provider = AuthProvider.objects.create(
  15. organization=organization,
  16. provider='dummy',
  17. flags=0,
  18. )
  19. AuthIdentity.objects.create(
  20. auth_provider=auth_provider,
  21. user=user,
  22. )
  23. self.login_as(user)
  24. path = '/{}/'.format(organization.slug)
  25. redirect_uri = 'http://testserver/auth/login/{}/'.format(organization.slug)
  26. # we should be redirecting the user to the authentication form as they
  27. # haven't verified this specific organization
  28. resp = self.client.get(path)
  29. assert resp.status_code == 302
  30. assert resp['Location'] == redirect_uri
  31. # superuser should still require SSO as they're a member of the org
  32. user.update(is_superuser=True)
  33. resp = self.client.get(path)
  34. assert resp.status_code == 302
  35. assert resp['Location'] == redirect_uri
  36. # XXX(dcramer): using internal API as exposing a request object is hard
  37. self.session[SSO_SESSION_KEY] = six.text_type(organization.id)
  38. self.save_session()
  39. # now that SSO is marked as complete, we should be able to access dash
  40. resp = self.client.get(path)
  41. assert resp.status_code == 200