Create accounts automatically when authenticating from HTTP header (#2087)
* Create accounts automatically when authenticating from HTTP header * Disable password check when header auth is enabled * Formatting * Password change is valid when no password (old or new) is provided * Test suite runs with header auth disabled (mock config) Prevents nil pointer access (panic) while testing password validating logic * Use a constant prefix for autogenerated passwords (header auth case) * Add tests * Add context to log messages Co-authored-by: Deluan <deluan@navidrome.org>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -206,12 +207,16 @@ func validatePasswordChange(newUser *model.User, logged *model.User) error {
|
||||
if logged.IsAdmin && newUser.ID != logged.ID {
|
||||
return nil
|
||||
}
|
||||
if newUser.NewPassword != "" && newUser.CurrentPassword == "" {
|
||||
err.Errors["currentPassword"] = "ra.validation.required"
|
||||
if newUser.NewPassword == "" {
|
||||
if newUser.CurrentPassword == "" {
|
||||
return nil
|
||||
}
|
||||
err.Errors["password"] = "ra.validation.required"
|
||||
}
|
||||
if newUser.CurrentPassword != "" {
|
||||
if newUser.NewPassword == "" {
|
||||
err.Errors["password"] = "ra.validation.required"
|
||||
|
||||
if !strings.HasPrefix(logged.Password, consts.PasswordAutogenPrefix) {
|
||||
if newUser.CurrentPassword == "" {
|
||||
err.Errors["currentPassword"] = "ra.validation.required"
|
||||
}
|
||||
if newUser.CurrentPassword != logged.Password {
|
||||
err.Errors["currentPassword"] = "ra.validation.passwordDoesNotMatch"
|
||||
|
||||
Reference in New Issue
Block a user