From 910421c792704fd1e74c3387612fe75a2040cddf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Feb 2026 09:11:40 +0000 Subject: [PATCH] Add test to verify JSON body dumping still works for non-multipart requests Co-authored-by: kevwan <1918356+kevwan@users.noreply.github.com> --- rest/handler/authhandler_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/rest/handler/authhandler_test.go b/rest/handler/authhandler_test.go index a9b131196..56ed728e5 100644 --- a/rest/handler/authhandler_test.go +++ b/rest/handler/authhandler_test.go @@ -5,6 +5,7 @@ import ( "net" "net/http" "net/http/httptest" + "strings" "testing" "time" @@ -90,6 +91,28 @@ func TestAuthHandler_NilError(t *testing.T) { }) } +func TestAuthHandlerWithJSONBody(t *testing.T) { + const key = "B63F477D-BBA3-4E52-96D3-C0034C27694A" + + // Create a request with JSON body + jsonBody := `{"username":"test","password":"secret"}` + req := httptest.NewRequest(http.MethodPost, "http://localhost/login", + strings.NewReader(jsonBody)) + req.Header.Set("Content-Type", "application/json") + // Missing authorization header to trigger the unauthorized path + + handler := Authorize(key)( + http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + })) + + resp := httptest.NewRecorder() + handler.ServeHTTP(resp, req) + + // Should return unauthorized + assert.Equal(t, http.StatusUnauthorized, resp.Code) +} + func TestAuthHandlerWithMultipartFormData(t *testing.T) { const key = "B63F477D-BBA3-4E52-96D3-C0034C27694A"