1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- from sentry.models.authidentity import AuthIdentity
- from sentry.models.authprovider import AuthProvider
- from sentry.testutils.cases import AuthProviderTestCase
- from sentry.utils.auth import SsoSession
- class OrganizationAuthLoginTest(AuthProviderTestCase):
- def test_sso_auth_required(self):
- user = self.create_user("foo@example.com", is_superuser=False)
- organization = self.create_organization(name="foo")
- member = self.create_member(user=user, organization=organization)
- setattr(member.flags, "sso:linked", True)
- member.save()
- auth_provider = AuthProvider.objects.create(
- organization_id=organization.id, provider="dummy", flags=0
- )
- AuthIdentity.objects.create(auth_provider=auth_provider, user=user)
- self.login_as(user)
- path = f"/{organization.slug}/"
- redirect_uri = f"/auth/login/{organization.slug}/?next=%2Ffoo%2F"
-
-
- resp = self.client.get(path)
- self.assertRedirects(resp, redirect_uri)
-
- user.update(is_superuser=True)
- resp = self.client.get(path)
- self.assertRedirects(resp, redirect_uri)
-
- sso_session = SsoSession.create(organization.id)
- self.session[sso_session.session_key] = sso_session.to_dict()
- self.save_session()
-
- resp = self.client.get(path)
- assert resp.status_code == 200
|