: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(oauth): cover inlined allowed_origins and RS256 validation (#65879)
Matt Brooker91ff9d88c3ef
diff --git a/posthog/models/test/test_oauth.py b/posthog/models/test/test_oauth.pyindex 29b95c424a2a..f572b7816014 100644--- a/posthog/models/test/test_oauth.py+++ b/posthog/models/test/test_oauth.py@@ -3,6 +3,7 @@ from datetime import timedeltafrom freezegun import freeze_time+from django.conf import settingsfrom django.core.exceptions import ValidationErrorfrom django.test import TestCase, override_settingsfrom django.utils import timezone@@ -447,6 +448,29 @@ class TestOAuthModels(TestCase):algorithm="RS256",)+ def test_valid_allowed_origins_accepted(self):+ app = self._make_app(+ "Allowed Origins App",+ "allowed_origins_client",+ allowed_origins="https://app.example.com https://www.example.com",+ )+ self.assertIn("app.example.com", app.allowed_origins)++ @parameterized.expand(+ [+ ("non-https scheme", "http://app.example.com"),+ ("origin with path", "https://app.example.com/callback"),+ ]+ )+ def test_invalid_allowed_origins_rejected(self, _name, allowed_origins):+ with self.assertRaises(ValidationError):+ self._make_app("Bad Origin App", "bad_origin_client", allowed_origins=allowed_origins)++ def test_rs256_without_private_key_rejected(self):+ with override_settings(OAUTH2_PROVIDER={**settings.OAUTH2_PROVIDER, "OIDC_RSA_PRIVATE_KEY": ""}):+ with self.assertRaises(ValidationError):+ self._make_app("No Key App", "no_key_client")+def test_invalid_redirect_uri_no_host(self):with self.assertRaises(ValidationError):OAuthApplication.objects.create(