]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
oauth_validator: Shorten JSON responses in test logs
authorJacob Champion <jchampion@postgresql.org>
Wed, 26 Nov 2025 04:32:52 +0000 (20:32 -0800)
committerJacob Champion <jchampion@postgresql.org>
Wed, 26 Nov 2025 04:39:47 +0000 (20:39 -0800)
Response padding from the oauth_validator abuse tests was adding a
couple megabytes to the test logs. We don't need the buildfarm to hold
onto that, and we don't need to read it when debugging; truncate it.

Reported-by: Álvaro Herrera <alvherre@kurilemu.de>
Discussion: https://postgr.es/m/202511251218.zfs4nu2qnh2m%40alvherre.pgsql
Backpatch-through: 18

src/test/modules/oauth_validator/t/oauth_server.py

index 0f8836aadf3729980813214b7668fc18bb9af043..c70783ecbe49d4ab0cc945021e9507040b564bb8 100755 (executable)
@@ -257,13 +257,33 @@ class OAuthHandler(http.server.BaseHTTPRequestHandler):
 
         return token
 
+    def _log_response(self, js: JsonObject) -> None:
+        """
+        Trims the response JSON, if necessary, and logs it for later debugging.
+        """
+        # At the moment the biggest problem for tests is the _pad_ member, which
+        # is a megabyte in size, so truncate that to something more reasonable.
+        if "_pad_" in js:
+            pad = js["_pad_"]
+
+            # Don't modify the original dict.
+            js = dict(js)
+            js["_pad_"] = pad[:64] + f"[...truncated from {len(pad)} bytes]"
+
+        resp = json.dumps(js).encode("ascii")
+        self.log_message("sending JSON response: %s", resp)
+
+        # If you've tripped this assertion, please truncate the new addition as
+        # above, or else come up with a new strategy.
+        assert len(resp) < 1024, "_log_response must be adjusted for new JSON"
+
     def _send_json(self, js: JsonObject) -> None:
         """
         Sends the provided JSON dict as an application/json response.
         self._response_code can be modified to send JSON error responses.
         """
         resp = json.dumps(js).encode("ascii")
-        self.log_message("sending JSON response: %s", resp)
+        self._log_response(js)
 
         self.send_response(self._response_code)
         self.send_header("Content-Type", self._content_type)