fix(auth): a password reset signs out Subsonic apps too, and a change can (#8107)
A reset ended every session but left the API key and Subsonic password working, and anyone signed in to the account can make either. So whoever had the account kept it through a Subsonic app after the owner reset the password. The forgotten-password reset and an admin's reset now replace the API key with one nobody holds and clear the Subsonic password. A self-service change keeps Subsonic apps signed in by default, since it would sign out the owner's own apps too. The web and Android password forms gain "Sign out Subsonic apps too", sent as sign_out_subsonic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -81,3 +81,33 @@ func TestChangePassword_TooShort_400(t *testing.T) {
|
||||
t.Errorf("status = %d, want 400 (password_too_short)", rec.Code)
|
||||
}
|
||||
}
|
||||
|
||||
// A change keeps Subsonic apps signed in unless the person asks for them to
|
||||
// be signed out as well.
|
||||
func TestChangePassword_SignsOutSubsonicAppsOnlyWhenAsked(t *testing.T) {
|
||||
if os.Getenv("MINSTREL_TEST_DATABASE_URL") == "" {
|
||||
t.Skip("MINSTREL_TEST_DATABASE_URL not set")
|
||||
}
|
||||
h, pool := testHandlers(t)
|
||||
user := seedUser(t, pool, "chpwsub", "oldpassword1", false)
|
||||
giveSubsonicPassword(t, h, user)
|
||||
before, _ := subsonicCredentials(t, h, user)
|
||||
|
||||
change := func(body string) {
|
||||
t.Helper()
|
||||
req := httptest.NewRequest(http.MethodPut, "/api/me/password", bytes.NewReader([]byte(body)))
|
||||
rec := httptest.NewRecorder()
|
||||
newMePasswordRouter(h).ServeHTTP(rec, withUser(req, user))
|
||||
if rec.Code != http.StatusNoContent {
|
||||
t.Fatalf("status = %d, want 204; body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
change(`{"current_password":"oldpassword1","new_password":"newpassword1"}`)
|
||||
if after, hasPassword := subsonicCredentials(t, h, user); after != before || !hasPassword {
|
||||
t.Fatal("a plain password change signed out Subsonic apps")
|
||||
}
|
||||
|
||||
change(`{"current_password":"newpassword1","new_password":"newpassword2","sign_out_subsonic":true}`)
|
||||
assertSubsonicSignedOut(t, h, user, before)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user