Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/internal/httpserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
20 changes: 20 additions & 0 deletions core/internal/httpserver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}