From bfda2fe8d42897ed6020aff599c2ab099128ab5c Mon Sep 17 00:00:00 2001 From: ZayanKhan-12 <108294002+ZayanKhan-12@users.noreply.github.com> Date: Wed, 22 Jul 2026 13:05:59 -0400 Subject: [PATCH] httpserver: return an error for unknown notifier class in config detail configNotifierDetail's class-name switch had no default case, so a notifier module with an unhandled class-name returned an empty body with a 200 status code from /v3/config/notifier/{name}. Return a 500 error response instead, and cover it with a test. Co-Authored-By: Claude Fable 5 --- core/internal/httpserver/config.go | 3 +++ core/internal/httpserver/config_test.go | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/core/internal/httpserver/config.go b/core/internal/httpserver/config.go index 92f04532..5b5be60e 100644 --- a/core/internal/httpserver/config.go +++ b/core/internal/httpserver/config.go @@ -304,6 +304,9 @@ func (hc *Coordinator) configNotifierDetail(w http.ResponseWriter, r *http.Reque hc.configNotifierSlack(w, r, configRoot) case "null": hc.configNotifierNull(w, r, configRoot) + default: + // Without this, an unhandled class-name would return an empty response with a 200 status code + hc.writeErrorResponse(w, r, http.StatusInternalServerError, "unknown notifier class") } } } diff --git a/core/internal/httpserver/config_test.go b/core/internal/httpserver/config_test.go index 44cb1bc6..2c9f10ba 100644 --- a/core/internal/httpserver/config_test.go +++ b/core/internal/httpserver/config_test.go @@ -325,3 +325,23 @@ func TestHttpServer_configNotifierDetail(t *testing.T) { coordinator.router.ServeHTTP(rr, req) assert.Equalf(t, http.StatusNotFound, rr.Code, "Expected response code to be 404, not %v", rr.Code) } + +func TestHttpServer_configNotifierDetail_UnknownClass(t *testing.T) { + coordinator := fixtureConfiguredCoordinator() + setupConfiguration() + viper.Set("notifier.badnotifier.class-name", "unknownclass") + + // A notifier with an unhandled class-name should return an error, not an empty 200 response + req, err := http.NewRequest("GET", "/v3/config/notifier/badnotifier", http.NoBody) + assert.NoError(t, err, "Expected request setup to return no error") + rr := httptest.NewRecorder() + coordinator.router.ServeHTTP(rr, req) + assert.Equalf(t, http.StatusInternalServerError, rr.Code, "Expected response code to be 500, not %v", rr.Code) + + // Parse response body + decoder := json.NewDecoder(rr.Body) + var resp httpResponseError + err = decoder.Decode(&resp) + assert.NoError(t, err, "Expected body decode to return no error") + assert.True(t, resp.Error, "Expected response Error to be true") +}