|
@@ -8,14 +8,16 @@ from sentry.testutils.silo import region_silo_test
|
|
|
|
|
|
@region_silo_test
|
|
|
class AuthOrganizationChannelLoginTest(TestCase):
|
|
|
- def setup(self):
|
|
|
- self.organization = self.create_organization(name="test org", owner=self.user)
|
|
|
- self.partner_org_id = "foobar"
|
|
|
- config_data = FlyOAuth2Provider.build_config(resource={"id": self.partner_org_id})
|
|
|
+ def create_auth_provider(self, partner_org_id, sentry_org_id):
|
|
|
+ config_data = FlyOAuth2Provider.build_config(resource={"id": partner_org_id})
|
|
|
AuthProvider.objects.create(
|
|
|
- organization_id=self.organization.id, provider="fly", config=config_data
|
|
|
+ organization_id=sentry_org_id, provider="fly", config=config_data
|
|
|
)
|
|
|
- self.path = reverse("sentry-auth-channel", args=["fly", self.partner_org_id])
|
|
|
+
|
|
|
+ def setup(self):
|
|
|
+ self.organization = self.create_organization(name="test org", owner=self.user)
|
|
|
+ self.create_auth_provider("fly-test-org", self.organization.id)
|
|
|
+ self.path = reverse("sentry-auth-channel", args=["fly", "fly-test-org"])
|
|
|
|
|
|
def test_redirect_for_logged_in_user(self):
|
|
|
self.setup()
|
|
@@ -26,6 +28,19 @@ class AuthOrganizationChannelLoginTest(TestCase):
|
|
|
(f"/organizations/{self.organization.slug}/issues/", 302),
|
|
|
]
|
|
|
|
|
|
+ def test_redirect_for_logged_in_user_with_different_active_org(self):
|
|
|
+ self.setup()
|
|
|
+ self.login_as(self.user) # log in to "test org"
|
|
|
+ another_org = self.create_organization(name="another org", owner=self.user)
|
|
|
+ self.create_auth_provider("another-fly-org", another_org.id)
|
|
|
+ path = reverse("sentry-auth-channel", args=["fly", "another-fly-org"])
|
|
|
+ response = self.client.get(path + "?next=/projects/", follow=True)
|
|
|
+ assert response.status_code == 200
|
|
|
+ # redirects to login to the org in the url
|
|
|
+ assert response.redirect_chain == [
|
|
|
+ (f"/auth/login/{another_org.slug}/?next=/projects/", 302),
|
|
|
+ ]
|
|
|
+
|
|
|
def test_redirect_for_logged_out_user(self):
|
|
|
self.setup()
|
|
|
response = self.client.get(self.path, follow=True)
|