:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
test(auth): cover Google login insight redirect (#99957)
Paul D'Ambrad7f5455dbf61
diff --git a/ee/api/test/test_authentication.py b/ee/api/test/test_authentication.pyindex 5dadc4a8aa3f..7b50b8d444c1 100644--- a/ee/api/test/test_authentication.py+++ b/ee/api/test/test_authentication.py@@ -307,6 +307,26 @@ class TestEEAuthenticationAPI(APILicensedTest):second_key = self.client.session.session_keyself.assertNotEqual(first_key, second_key)+ @patch("social_core.backends.base.BaseAuth.request")+ def test_google_login_returns_to_saved_insight(self, mock_request):+ UserSocialAuth.objects.create(user=self.user, provider="google-oauth2", uid="google-sub-123")+ insight_url = "/project/1/insights/test-insight"++ with self.settings(**GOOGLE_MOCK_SETTINGS):+ response = self.client.get(f"/login/google-oauth2/?{urlencode({'next': insight_url})}")+ self.assertEqual(response.status_code, status.HTTP_302_FOUND)+ state = self.client.session["google-oauth2_state"]++ mock_request.return_value.json.return_value = {+ "access_token": "123",+ "email": self.user.email,+ "sub": "google-sub-123",+ }+ response = self.client.get(f"/complete/google-oauth2/?code=2&state={state}")++ self.assertRedirects(response, insight_url, fetch_redirect_response=False)+ self.assertEqual(self.client.session.get("_auth_user_id"), str(self.user.pk))+@parameterized.expand([("auth_failed", AuthFailed(cast(Any, "google-oauth2"), "bad")),