Repository navigation
Fixes #38023: preserve 424 FAILED_SEND_EMAIL in signup/password-reset flows - #38051
Conversation
| // 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()); |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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).
… 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>
… 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>
Detail bug report: View on Detail
Describe your changes:
Fixes #38023
A FreeMarker
TemplateExceptionduring the email send step of self-signup, registration-token resend, and password-reset was reaching the client as a generic 500 with noerrorType, instead of the intended 424FAILED_SEND_EMAILtheBasicAuthenticatorcatch blocks raise. In the/v1/users/password/resetflow 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 rewroteWebServiceExceptionto store only aResponse.Statusenum and rewroteCustomExceptionMessage(int, ...)to coerce the int throughResponse.Status.fromStatusCode(status). That call returnsnullfor codes that are not enum constants (e.g. 424 "Failed Dependency"), so the exception carried a null status andWebServiceException.getResponse()later threwIllegalArgumentException: Response status must not be 'null'from insideCatalogGenericExceptionMapper, surfacing as a 500.Type of change:
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-
bb1395fc72contract:openmetadata-spec/.../WebServiceException.java: replaced theResponse.Status statusfield with anint statusCodefield, added aWebServiceException(int status, String errorType, String message)constructor, and madegetResponse()buildResponse.status(statusCode)andnew ErrorMessage(statusCode, ...).Response.status(int)accepts any numeric code (not just enum constants), so 424 renders correctly. The enum-accepting constructors populatestatusCode = status.getStatusCode(), byte-equivalent to the previous behavior for enum-typed statuses.openmetadata-service/.../CustomExceptionMessage.java: dropped theResponse.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 tosuper(status, ...), equivalent for any enum constant.This is the idiomatic fix recommended in the bug report (option 1, "restore an int-accepting
WebServiceExceptionpath"), not the degrade-to-500 fallback (option 2), so clients continue to receive the typed 424FAILED_SEND_EMAILthey branch on. It also closes the latent-defect in the(Response, String)constructor (theDocStoreMappercall 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
TemplateExceptionfromEmailUtil.sendEmailVerification(reached byPOST /v1/users/signupandPOST /v1/users/resendRegistrationToken) throws aCustomExceptionMessagewith status 424 /errorType = FAILED_SEND_EMAIL, and no email-verification token is persisted.TemplateExceptionfromEmailUtil.sendPasswordResetLinkthrows the same typed 424, and no password-reset token is persisted (a reset token alone can take over the account).TemplateExceptionfromEmailUtil.sendAccountStatusduringresetUserPasswordWithToken(reached byPOST /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 aCustomExceptionMessage(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.Response.status(enum)→Response.status(int)swap is byte-equivalent for enum codes.Unit tests
openmetadata-service/src/test/java/org/openmetadata/service/exception/CustomExceptionMessageTest.java(new) — pins the int / enum /(Response, String)constructor contract for bothCustomExceptionMessageand the SDKWebServiceException, including a 424 withCLIENT_ERRORfamily and the typed body.openmetadata-service/src/test/java/org/openmetadata/service/security/auth/BasicAuthenticatorEmailFailureTest.java(new) — exercises the three real throw sites inBasicAuthenticator(sendEmailVerification,sendPasswordResetLink,resetUserPasswordWithToken) withEmailUtilmocked to throwfreemarker.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— addedaNonEnumStatusCodeIsRenderedWithItsTypedErrorBodyandbasicAuthEmailFailureConstantsRenderAs424FailedSendEmailcovering the mapper rendering path.openmetadata-service/src/test/java/org/openmetadata/service/security/SecurityUtilTest.java— addedtestWriteFailureResponseKeepsNonEnum424StatusOfCustomExceptionMessagecovering the security-filter path.CustomExceptionMessageis at 100% line/instruction/branch/method coverage (mvn jacoco:reportaftermvn test -P static-code-analysis -Dtest=CustomExceptionMessageTest,BasicAuthenticatorEmailFailureTest); all three constructors are exercised. The SDKWebServiceExceptionlives inopenmetadata-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 newintconstructor andgetResponse()build-from-statusCodepath are exercised directly byCustomExceptionMessageTest.webServiceExceptionIntConstructorRendersNonEnumStatusand indirectly by everynew CustomExceptionMessage(...).getResponse()call in the suite.Backend integration tests
openmetadata-integration-tests/for new/changed API endpoints.bb1395fc72424 response the three endpoints already contractually returned. The existingLoginLockoutITexercises 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;LoginLockoutITwas not selected as impacted for this diff. Running the planner's recommendedmvn -B package -pl openmetadata-service -am -Dtest=...command gives 125 tests, 0 failures.Ingestion integration tests
Playwright (UI) tests
Visual regression baselines
Manual testing performed
WebServiceExceptionjar installed from the fix exposes the newWebServiceException(int, String, String)constructor viajavapon the installedopenmetadata-spec-2.0.0-SNAPSHOT.jar.CustomExceptionMessage(int, ...)coerced throughResponse.Status.fromStatusCode(424)(returnsnull), then confirmed the fix renders 424 with the typed body.LoginLockoutITend-to-end via the in-processTestSuiteBootstrap. The bootstrap fails to start the embedded OpenMetadata application on this environment withUnhandledServerException: App Scheduler is not Initialized(originating inEntity.initializeRepositoriesnot seedingentityRelationshipRepositoryduring 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 byBasicAuthenticatorEmailFailureTestandCatalogGenericExceptionMapperTest, which invoke the realBasicAuthenticatormethods (withEmailUtilmocked to throwTemplateException) and the realCatalogGenericExceptionMapper.toResponsewith aCustomExceptionMessage(424, FAILED_SEND_EMAIL, ...).docker/development/docker-compose.ymluses the publishedopenmetadata/server:latestimage (no fix).UI screen recording:
Not applicable — backend-only fix in the exception/SDK layer; no UI rendering change.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.REVIEW.md(thepr-checklistskill runs it) and fixed every 🔴 finding, or answered it on the line below.docs/decisions/(see itsREADME.md). — N/A, restores a pre-existing contract.BasicAuthenticatorEmailFailureTestcovers the three exactCustomExceptionMessage(424, FAILED_SEND_EMAIL, ...)throw sites inBasicAuthenticator;CatalogGenericExceptionMapperTest.aNonEnumStatusCodeIsRenderedWithItsTypedErrorBodycovers the mapper rendering surface where the bug manifested as a 500.Automatic Fixes PRs can be configured here.
The earlier testing requirement still needs to be satisfied before merging; the latest changes introduce no new findings.
Findings
Summary
This PR restores HTTP 424 with
FAILED_SEND_EMAILwhen an email template fails during signup or password reset.No new issues were found in the latest changes.
Reviews (2) · Last reviewed commit: "test(auth): assert persisted password on..." · Reviewed by Greptile