From 9361a3cffe7c2411dd903804fdb7a0a124759def Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 3 Oct 2025 13:59:14 -0700 Subject: [PATCH] test_classes: Give useful error when using /json/ URLs wrong. --- zerver/lib/test_classes.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py index 399dcecff6..48e2d0d7fd 100644 --- a/zerver/lib/test_classes.py +++ b/zerver/lib/test_classes.py @@ -1074,6 +1074,7 @@ Output: def api_get( self, user: UserProfile, url: str, info: Mapping[str, Any] = {}, **extra: str ) -> "TestHttpResponse": + assert not url.startswith("/json/"), "Invalid URL for API authentication" extra["HTTP_AUTHORIZATION"] = self.encode_user(user) return self.client_get( url, @@ -1096,6 +1097,7 @@ Output: intentionally_undocumented: bool = False, **extra: str, ) -> "TestHttpResponse": + assert not url.startswith("/json/"), "Invalid URL for API authentication" extra["HTTP_AUTHORIZATION"] = self.encode_user(user) return self.client_post( url, @@ -1112,6 +1114,7 @@ Output: def api_patch( self, user: UserProfile, url: str, info: Mapping[str, Any] = {}, **extra: str ) -> "TestHttpResponse": + assert not url.startswith("/json/"), "Invalid URL for API authentication" extra["HTTP_AUTHORIZATION"] = self.encode_user(user) return self.client_patch( url, @@ -1128,6 +1131,7 @@ Output: def api_delete( self, user: UserProfile, url: str, info: Mapping[str, Any] = {}, **extra: str ) -> "TestHttpResponse": + assert not url.startswith("/json/"), "Invalid URL for API authentication" extra["HTTP_AUTHORIZATION"] = self.encode_user(user) return self.client_delete( url,