[bugfix] validate ServerChan notification response codes by 9184290-cpu · Pull Request #4472 · apache/hertzbeat · GitHub
Skip to content

[bugfix] validate ServerChan notification response codes - #4472

Open
9184290-cpu wants to merge 1 commit into
apache:masterfrom
9184290-cpu:fix/serverchan-response-validation
Open

9184290-cpu wants to merge 1 commit into
apache:masterfrom
9184290-cpu:fix/serverchan-response-validation

Conversation

@9184290-cpu

@9184290-cpu 9184290-cpu commented Oct 18, 2026 •

Copy link
Copy Markdown

What's changed?

The ServerChan handler currently treats every HTTP 200 response as success, even when the response contains a nonzero business code or no success code. This lets a rejected or invalid response return without an AlertNoticeException.

Require a non-null response body and an explicit code == 0 before logging success. Report missing codes and nonzero codes through the existing exception path. The ServerChan FAQ documents nonzero code as an error.

Correct the existing success fixture to use code, and add regression tests using a real RestTemplate with MockRestServiceServer. These exercise JSON conversion, positive/negative business errors, empty/null/missing-code responses, malformed JSON, HTTP errors and transport failures. The HTTP responses are synthetic fixtures, not observations from a live delivery.

Only the ServerChan handler and its tests change; the shared response DTO and other channels are unchanged.

Validation

Windows, Zulu OpenJDK 25.0.4.1, Maven 3.9.16; baseline d823f2dcd52903c01d2f79b93019d379208584dc.

  • Before the production fix: 13 tests, 7 failures, 0 errors, 0 skipped. The two business-error cases and five missing-success-code cases failed because no exception was thrown.
  • After the fix: 13 tests, 0 failures, 0 errors, 0 skipped.
  • Notification-handler regression suite (including ServerChan): 75 tests, 0 failures, 0 errors, 0 skipped.
  • Maven Checkstyle passed; git diff --check passed.
mvn -B -ntp -pl hertzbeat-alerter -am -Dtest=ServerChanAlertNotifyHandlerImplTest -Dsurefire.failIfNoSpecifiedTests=false -Dmaven.test.skip=false -Djacoco.skip=true test
mvn -B -ntp -pl hertzbeat-alerter -am -Dtest=*AlertNotifyHandlerImplTest -Dsurefire.failIfNoSpecifiedTests=false -Dmaven.test.skip=false -Djacoco.skip=true test

These local runs disable coverage instrumentation; the repository POM is unchanged. Full-repository tests, packaging and live ServerChan delivery were not tested.

AI-assisted contribution

  • AI assistance: Codex assisted with source inspection, regression tests, implementation, local validation and PR preparation.
  • Human validation: Contributor review and personal rerun are pending. This PR is submitted as a draft for that review; automated results above were obtained by Codex.
  • Risk notes: HTTP 200 responses without an explicit zero code will now fail. Custom compatible endpoints must provide the same response contract. Existing URL handling and retry behavior are unchanged.

Checklist

  • Contribution and code quality guides reviewed during preparation.
  • Necessary regression tests added and selected suites passed.
  • Contributor personally reviewed the code and validation results.

Add or update API

Not applicable: no public API added or changed.

Signed-off-by: Gumouer <2663769371@qq.com>
@9184290-cpu
9184290-cpu marked this pull request as ready for review October 18, 2026 06:48

@zqr10159 zqr10159 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed against master 6ca9022. Requiring an explicit code == 0 matches the configured sctapi.ftqq.com response contract. All 13 ServerChan tests passed locally, covering JSON conversion, nonzero/missing code, empty/malformed responses, HTTP errors and transport failures; Checkstyle passed. No live delivery was performed. Compatible custom endpoints must return the same explicit code contract. Code review passes; Backend CI and License Checker are action_required (awaiting maintainer approval to run), not failed tests. Please complete those checks before merging.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants