Repository navigation
fix(api): store is_non_default_password when a user chooses a password - #12
Merged
Merged
Conversation
The flag says whether a password is one the user chose. POST /user/change-password asks for the current password only when it is set, and GET /user/auth-info reports it so that Web can ask for one. Since the port to appflowy2 (2025-11) nothing stored it. The appflowy branch wrote the column in UpdatePassword's column list; the port kept the assignments in memory and dropped the column. The endpoint therefore never asked for a current password that was set after the port, and auth-info kept reporting such passwords as not chosen. - User.SetIsNonDefaultPassword stores the flag. Each place that decides it calls this in the transaction of the change it belongs to, so the flag no longer depends on an upstream column list. - POST /user/change-password and PUT /user with a password set it. Web and Desktop use PUT /user after a recovery, and Desktop for a first password. - A verified password recovery resets it. The appflowy branch reset it when a recovery was requested, which let anyone reset it for any address; the port left that as an assignment that was never saved. A magic-link sign-in and an email change do not reset it. Tests. The five that failed on appflowy4: - TestUserChangePasswordNoCurrentPasswordForDefaultPassword failed on the missing write and passes unchanged. - TestUserUpdatePasswordReauthentication and TestUserUpdatePasswordLogoutOtherSessions passed alone and failed in the suite: TestUserChangePasswordWeakPassword left the shared minimum length at 10, which refused their seven-character password. It restores it now. - TestPasswordRecoveryResetsIsNonDefaultPassword also required the recovery to delete the password, which no version of the fork did. It now requires the reset on verification only, and that the password still signs the user in. - TestEmailChangeResetsIsNonDefaultPassword required an email change to reset the flag and delete the password, and expected the change to complete after one of its two confirmations. It is replaced by a test that a completed change keeps both. New tests read the flag back through each endpoint that sets it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…no test The testing guide ran suite methods by their own name, for example `-run TestUserChangePassword`. Those tests are methods of the TestUser and TestVerify suites, so the pattern matched nothing and `go test` printed `ok ... [no tests to run]`. The migration notes recorded that as passing, for tests that could not pass. The commands now name the suite first. The notes also said the flag is reset on an email change, which the code never did and should not do, and did not say where the flag is stored. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Five tests in
internal/apifail onappflowy4, soTestis red on the branch and on every pull request against it, #10 included. Nobody saw them fail before 2026-11-25 because the fork's checks never ran (#11). They have three causes, and one of them is a real defect in the password feature.The feature
auth.users.is_non_default_passwordsays whether a password is one the user chose. A password generated for a passwordless sign-up, or set by an administrator, is not: its owner may never have seen it.POST /user/change-passwordasks forcurrent_passwordonly when the flag is set.GET /user/auth-inforeports the flag, and Web uses it to decide whether to show a current-password field.What was wrong
1. Nothing stored the flag. The
appflowybranch (2025-04) wrote the column inUpdatePassword's column list. The port toappflowy2(2025-11) kept the assignments in memory and dropped the column from that list. Since then:/user/change-passworddid not set the flag, so the endpoint never asked for it on the next change;auth-infokept reporting such passwords as not chosen;recover.gothat was never saved.Rows written by the
appflowybranch before the port kept their value.2. One test changed shared configuration and did not restore it.
TestUserChangePasswordWeakPasswordset the minimum password length to 10. The tests of a suite share one configuration and run in name order, so two later tests that set the seven-character passwordnewpasswere refused. They pass when run alone.3. Two tests required behaviour that no version of the fork had. Both required the password to be deleted: one when a recovery is verified, one when an email change is verified. The second also required the email change to reset the flag, and expected the change to be complete after one of its two confirmations.
Why the fork's notes said these passed.
appflowy/TESTING_GUIDE.mdran them asgo test -run TestUserChangePassword. They are methods of theTestUserandTestVerifysuites, so that pattern matches no test andgo testprintsok ... [no tests to run].What changes
internal/models/user.goUser.SetIsNonDefaultPasswordstores the flag.UpdatePasswordis untouched.POST /user/change-passwordPUT /userwith a passwordGETandPOST /verify, typerecoveryPOST /recoverappflowy/notesWhat users see
PUT /user, which does not ask for the current password unless the operator turned that on.auth-infoand shows the current-password field; if the server asks for it unexpectedly it handlesincorrect_current_passwordby asking. Desktop always sendscurrent_passwordfrom its change form. The Admin console sets passwords through the admin API, which this change does not touch.Decisions
UpdatePassword's column list. That list is an upstream line that changes when upstream adds a column, and a fork edit inside it is how the write was lost once already. The flag is now written by fork code that says so.appflowybranch reset it onPOST /recover, which anyone can send for any address. Verification proves control of the mailbox, the same proof that already lets a user set a new password.appflowybranch also set the flag for users created through the admin API with a password hash. Nothing in AppFlowy creates users that way; the backup restore sets the column itself.Tests
The five that failed:
TestUserChangePasswordNoCurrentPasswordForDefaultPasswordTestUserUpdatePasswordReauthentication,TestUserUpdatePasswordLogoutOtherSessionsTestPasswordRecoveryResetsIsNonDefaultPasswordTestEmailChangeResetsIsNonDefaultPasswordTestEmailChangeKeepsThePasswordAndIsNonDefaultPassword: a completed change keeps the flag and the passwordNew:
TestUserChangePasswordAsksForAChosenPasswordNextTimeandTestUserUpdatePasswordIsAChosenPasswordread the flag back through each endpoint that sets it.Run in a
golang:1.25container against PostgreSQL 15, with the tool versions CI installs:make vet static sec vulncheckmake test(every package,-race)go test -run "TestPasswordRecoveryResets|TestEmailChangeResets" ./internal/apiok ... [no tests to run]In CI on
28edc01:Testpassed, with 30 packages and 1,742 tests and no failure, the first greenTestin this fork.Against a built image. GoTrue was built with AppFlowy Cloud's Dockerfile from
03a4a52, the head of #10 with this branch merged in, and driven over HTTP with PostgreSQL 15. All 21 checks passed:auth-infothen reports a chosen password and the column is stored.incorrect_current_password) and with a wrong one, and accepted with the right one.Each part of the fix was removed in turn to see which test notices:
/user/change-password…AsksForAChosenPasswordNextTime,…NoCurrentPasswordForDefaultPasswordPUT /userTestUserUpdatePasswordIsAChosenPasswordTestPasswordRecoveryResetsIsNonDefaultPasswordTestUserUpdatePasswordReauthentication,TestUserUpdatePasswordLogoutOtherSessionsNot verified
Related PRs
Testwas red only because of these five tests. This branch is merged into it, so #10 passes now and the two can merge in either order🤖 Generated with Claude Code