mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 04:27:37 +03:00
Only encrypts NewPassword if it is not empty, when updating the user details. Fixes #1222
This commit is contained in:
parent
ed286c7103
commit
fb183e58e9
2 changed files with 21 additions and 1 deletions
|
@ -63,7 +63,9 @@ func (r *userRepository) Put(u *model.User) error {
|
|||
u.ID = uuid.NewString()
|
||||
}
|
||||
u.UpdatedAt = time.Now()
|
||||
_ = r.encryptPassword(u)
|
||||
if u.NewPassword != "" {
|
||||
_ = r.encryptPassword(u)
|
||||
}
|
||||
values, _ := toSqlArgs(*u)
|
||||
delete(values, "current_password")
|
||||
update := Update(r.tableName).Where(Eq{"id": u.ID}).SetMap(values)
|
||||
|
|
|
@ -48,6 +48,24 @@ var _ = Describe("UserRepository", func() {
|
|||
Expect(actual.Name).To(Equal("Admin"))
|
||||
Expect(actual.Password).To(Equal("wordpass"))
|
||||
})
|
||||
It("updates the name and keep the same password", func() {
|
||||
usr.Name = "Jane Doe"
|
||||
usr.NewPassword = ""
|
||||
Expect(repo.Put(&usr)).To(BeNil())
|
||||
|
||||
actual, err := repo.FindByUsernameWithPassword("admin")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(actual.Name).To(Equal("Jane Doe"))
|
||||
Expect(actual.Password).To(Equal("wordpass"))
|
||||
})
|
||||
It("updates password if specified", func() {
|
||||
usr.NewPassword = "newpass"
|
||||
Expect(repo.Put(&usr)).To(BeNil())
|
||||
|
||||
actual, err := repo.FindByUsernameWithPassword("admin")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(actual.Password).To(Equal("newpass"))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("validatePasswordChange", func() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue