Skip to content

Fixes #38023: preserve 424 FAILED_SEND_EMAIL in signup/password-reset flows - #38051

Merged
yan-3005 merged 2 commits into
mainfrom
detail/bug-fix/fixes-38023-preserve-424-failed-send-email-in-sign-64cef2
Nov 19, 2026
Merged

yan-3005 merged 2 commits into
mainfrom
detail/bug-fix/fixes-38023-preserve-424-failed-send-email-in-sign-64cef2

Conversation

@detail-app

@detail-app detail-app Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Detail bug report: View on Detail

Describe your changes:

Fixes #38023

A FreeMarker TemplateException during the email send step of self-signup, registration-token resend, and password-reset was reaching the client as a generic 500 with no errorType, instead of the intended 424 FAILED_SEND_EMAIL the BasicAuthenticator catch blocks raise. In the /v1/users/password/reset flow this is especially problematic: the password has already been changed and persisted before the notification email is attempted, so a 500 led the client to believe the reset failed when it had in fact succeeded.

I worked on the SDK exception type and the basic-auth email-failure paths because the regression was introduced by PR #23239 ("Modern Fluent API Pattern", commit bb1395fc72), which rewrote WebServiceException to store only a Response.Status enum and rewrote CustomExceptionMessage(int, ...) to coerce the int through Response.Status.fromStatusCode(status). That call returns null for codes that are not enum constants (e.g. 424 "Failed Dependency"), so the exception carried a null status and WebServiceException.getResponse() later threw IllegalArgumentException: Response status must not be 'null' from inside CatalogGenericExceptionMapper, surfacing as a 500.

Type of change:

  • Bug fix

High-level design:

N/A — small change.

The fix preserves the raw int HTTP status end-to-end instead of coercing through the enum, restoring the pre-bb1395fc72 contract:

  • openmetadata-spec/.../WebServiceException.java: replaced the Response.Status status field with an int statusCode field, added a WebServiceException(int status, String errorType, String message) constructor, and made getResponse() build Response.status(statusCode) and new ErrorMessage(statusCode, ...). Response.status(int) accepts any numeric code (not just enum constants), so 424 renders correctly. The enum-accepting constructors populate statusCode = status.getStatusCode(), byte-equivalent to the previous behavior for enum-typed statuses.
  • openmetadata-service/.../CustomExceptionMessage.java: dropped the Response.Status.fromStatusCode(...) coercion from all three constructors. The (int, ...) and (Response, String) constructors now route through the new int path. The (Response.Status, ...) overload simplifies to super(status, ...), equivalent for any enum constant.

This is the idiomatic fix recommended in the bug report (option 1, "restore an int-accepting WebServiceException path"), not the degrade-to-500 fallback (option 2), so clients continue to receive the typed 424 FAILED_SEND_EMAIL they branch on. It also closes the latent-defect in the (Response, String) constructor (the DocStoreMapper call site passes a hardcoded 400 so is unaffected today, but any non-enum response code would have crashed the same way).

Tests:

Use cases covered

  • A TemplateException from EmailUtil.sendEmailVerification (reached by POST /v1/users/signup and POST /v1/users/resendRegistrationToken) throws a CustomExceptionMessage with status 424 / errorType = FAILED_SEND_EMAIL, and no email-verification token is persisted.
  • A TemplateException from EmailUtil.sendPasswordResetLink throws the same typed 424, and no password-reset token is persisted (a reset token alone can take over the account).
  • A TemplateException from EmailUtil.sendAccountStatus during resetUserPasswordWithToken (reached by POST /v1/users/password/reset) throws the typed 424 after the new password has been persisted — so the change is durable even though the notification email failed.
  • CatalogGenericExceptionMapper.toResponse(...) renders a CustomExceptionMessage(424, FAILED_SEND_EMAIL, ...) as HTTP 424 with the typed body {"code":424,"errorType":"FAILED_SEND_EMAIL","message":"..."}, without throwing inside the mapper.
  • SecurityUtil.writeFailureResponse(...) (the servlet/auth-filter path used by the MCP login form) writes status 424 to the response for the same exception, not 500.
  • Enum-typed statuses (400/401/403/409/412/500/503) still render identically — the Response.status(enum) → Response.status(int) swap is byte-equivalent for enum codes.

Unit tests

  • I added unit tests for the new/changed logic.
  • Files added/updated:
    • openmetadata-service/src/test/java/org/openmetadata/service/exception/CustomExceptionMessageTest.java (new) — pins the int / enum / (Response, String) constructor contract for both CustomExceptionMessage and the SDK WebServiceException, including a 424 with CLIENT_ERROR family and the typed body.
    • openmetadata-service/src/test/java/org/openmetadata/service/security/auth/BasicAuthenticatorEmailFailureTest.java (new) — exercises the three real throw sites in BasicAuthenticator (sendEmailVerification, sendPasswordResetLink, resetUserPasswordWithToken) with EmailUtil mocked to throw freemarker.template.TemplateException; asserts status 424 / FAILED_SEND_EMAIL, no token persisted, and (for the reset path) that the password IS persisted.
    • openmetadata-service/src/test/java/org/openmetadata/service/exception/CatalogGenericExceptionMapperTest.java — added aNonEnumStatusCodeIsRenderedWithItsTypedErrorBody and basicAuthEmailFailureConstantsRenderAs424FailedSendEmail covering the mapper rendering path.
    • openmetadata-service/src/test/java/org/openmetadata/service/security/SecurityUtilTest.java — added testWriteFailureResponseKeepsNonEnum424StatusOfCustomExceptionMessage covering the security-filter path.
  • Coverage on changed classes: CustomExceptionMessage is at 100% line/instruction/branch/method coverage (mvn jacoco:report after mvn test -P static-code-analysis -Dtest=CustomExceptionMessageTest,BasicAuthenticatorEmailFailureTest); all three constructors are exercised. The SDK WebServiceException lives in openmetadata-spec, which has no unit tests of its own and is a pre-built dependency on the service classpath, so jacoco does not record it; the new int constructor and getResponse() build-from-statusCode path are exercised directly by CustomExceptionMessageTest.webServiceExceptionIntConstructorRendersNonEnumStatus and indirectly by every new CustomExceptionMessage(...).getResponse() call in the suite.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for new/changed API endpoints.
  • Not strictly applicable — no API endpoint shape changed; the fix restores the pre-bb1395fc72 424 response the three endpoints already contractually returned. The existing LoginLockoutIT exercises the password-reset endpoint over HTTP (happy path) and continues to pass at the unit level.

The make java_affected ARGS="--scope focused" planner selected the 4 affected unit-test classes (BasicAuthenticatorEmailFailureTest, CatalogGenericExceptionMapperTest, CustomExceptionMessageTest, SecurityUtilTest) and placed the only two impacted ITs (ReindexBenchmarkIT, EntityLoaderSmokeUIIT) on the nightly lane; LoginLockoutIT was not selected as impacted for this diff. Running the planner's recommended mvn -B package -pl openmetadata-service -am -Dtest=... command gives 125 tests, 0 failures.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Visual regression baselines

  • Not applicable (no rendering change).

Manual testing performed

  • Verified the SDK WebServiceException jar installed from the fix exposes the new WebServiceException(int, String, String) constructor via javap on the installed openmetadata-spec-2.0.0-SNAPSHOT.jar.
  • Reproduced the bug at the unit level before the fix by confirming the previous CustomExceptionMessage(int, ...) coerced through Response.Status.fromStatusCode(424) (returns null), then confirmed the fix renders 424 with the typed body.
  • Attempted to run LoginLockoutIT end-to-end via the in-process TestSuiteBootstrap. The bootstrap fails to start the embedded OpenMetadata application on this environment with UnhandledServerException: App Scheduler is not Initialized (originating in Entity.initializeRepositories not seeding entityRelationshipRepository during migration). I verified this is a pre-existing infrastructure issue, not caused by this fix, by stashing the two production source files and moving the new test files out of the tree — the baseline (unmodified) run fails the same way in the same spot. The production throw paths and the mapper-rendering behavior are covered at the unit level by BasicAuthenticatorEmailFailureTest and CatalogGenericExceptionMapperTest, which invoke the real BasicAuthenticator methods (with EmailUtil mocked to throw TemplateException) and the real CatalogGenericExceptionMapper.toResponse with a CustomExceptionMessage(424, FAILED_SEND_EMAIL, ...).
  • The SMTP/HTTP end-to-end procedure (a running OM server with the fix + SMTP enabled + a broken FreeMarker template) could not be run in this environment: the in-process IT bootstrap fails as above, and docker/development/docker-compose.yml uses the published openmetadata/server:latest image (no fix).

UI screen recording:

Not applicable — backend-only fix in the exception/SDK layer; no UI rendering change.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed. — N/A, no schema changes.
  • For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable). — N/A, backend-only.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.
  • Decision check: if this PR decides something the next contributor could undo — a schema field, REST path or format another component or repo must agree with, a new default or limit, an ordering that must hold, or a rule stated only in this description — it adds a record under docs/decisions/ (see its README.md). — N/A, restores a pre-existing contract.
  • I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference. — BasicAuthenticatorEmailFailureTest covers the three exact CustomExceptionMessage(424, FAILED_SEND_EMAIL, ...) throw sites in BasicAuthenticator; CatalogGenericExceptionMapperTest.aNonEnumStatusCodeIsRenderedWithItsTypedErrorBody covers the mapper rendering surface where the bug manifested as a 500.

Automatic Fixes PRs can be configured here.

RetriggerView in GreptileConfidence Score: 4/5

The earlier testing requirement still needs to be satisfied before merging; the latest changes introduce no new findings.

Findings

  1. P2 Password persistence goes untested. ▶

Summary

This PR restores HTTP 424 with FAILED_SEND_EMAIL when an email template fails during signup or password reset.

  • Email failures reach clients with their original HTTP status and error type.

No new issues were found in the latest changes.

Reviews (2) · Last reviewed commit: "test(auth): assert persisted password on..." · Reviewed by Greptile

@detail-app
detail-app Bot requested a review from a team as a code owner November 18, 2026 04:31
@detail-app
detail-app Bot requested review from harshach and sonika-shah November 18, 2026 04:31
Comment on lines +176 to +179
// The password IS persisted before the notification email, so the change is durable.
verify(userRepository).createOrUpdate(nullable(UriInfo.class), any(User.class), anyString());
verify(tokenRepository)
.deleteTokenByUserAndType(user.getId(), TokenType.PASSWORD_RESET.toString());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Password persistence goes untested. This test mocks the internal repositories, Entity, and EmailUtil, then checks calls to createOrUpdate and deleteTokenByUserAndType. It would still pass if the password were never changed on the saved user. The repository requires: “Mocks are for boundaries … not internals” and “Assert on observable outcomes … not internal verify() calls.” Use a real repository test to check that the new password is saved and the reset token is gone after the email fails.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 50d2810: the test now captures the User passed to createOrUpdate and verifies it carries a BCrypt hash of the requested new password, so it fails if the password is never set on the saved user.

Address greptile feedback on BasicAuthenticatorEmailFailureTest: capture
the User handed to createOrUpdate and verify it carries a BCrypt hash of
the requested new password, so the test fails if the password is never
set on the saved user (instead of relying solely on createOrUpdate
being called).
@yan-3005
yan-3005 merged commit 2cc8c55 into main Nov 19, 2026
60 checks passed
@yan-3005
yan-3005 deleted the detail/bug-fix/fixes-38023-preserve-424-failed-send-email-in-sign-64cef2 branch November 19, 2026 16:03
yan-3005 added a commit that referenced this pull request Nov 19, 2026
… flows (#38051) (#38231)

* fix(auth): preserve raw HTTP status for non-enum codes in WebServiceException

* test(auth): assert persisted password on reset email-failure path

Address greptile feedback on BasicAuthenticatorEmailFailureTest: capture
the User handed to createOrUpdate and verify it carries a BCrypt hash of
the requested new password, so the test fails if the password is never
set on the saved user (instead of relying solely on createOrUpdate
being called).

---------


(cherry picked from commit 2cc8c55)

Co-authored-by: detail-app[bot] <180357370+detail-app[bot]@users.noreply.github.com>
yan-3005 added a commit that referenced this pull request Nov 19, 2026
… flows (#38051) (#38232)

* fix(auth): preserve raw HTTP status for non-enum codes in WebServiceException

* test(auth): assert persisted password on reset email-failure path

Address greptile feedback on BasicAuthenticatorEmailFailureTest: capture
the User handed to createOrUpdate and verify it carries a BCrypt hash of
the requested new password, so the test fails if the password is never
set on the saved user (instead of relying solely on createOrUpdate
being called).

---------


(cherry picked from commit 2cc8c55)

Co-authored-by: detail-app[bot] <180357370+detail-app[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Detail Bug] Auth: Email-template failures in signup/password reset return 500 due to null HTTP status handling

2 participants