fix: login must be case-insensitive
This commit is contained in:
@@ -22,6 +22,7 @@ type UserRepository interface {
|
|||||||
CountAll(...QueryOptions) (int64, error)
|
CountAll(...QueryOptions) (int64, error)
|
||||||
Get(id string) (*User, error)
|
Get(id string) (*User, error)
|
||||||
Put(*User) error
|
Put(*User) error
|
||||||
|
// FindByUsername must be case-insensitive
|
||||||
FindByUsername(username string) (*User, error)
|
FindByUsername(username string) (*User, error)
|
||||||
UpdateLastLoginAt(id string) error
|
UpdateLastLoginAt(id string) error
|
||||||
UpdateLastAccessAt(id string) error
|
UpdateLastAccessAt(id string) error
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ func (r *userRepository) Put(u *model.User) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *userRepository) FindByUsername(username string) (*model.User, error) {
|
func (r *userRepository) FindByUsername(username string) (*model.User, error) {
|
||||||
|
username = strings.ToLower(username)
|
||||||
sel := r.newSelect().Columns("*").Where(Eq{"user_name": username})
|
sel := r.newSelect().Columns("*").Where(Eq{"user_name": username})
|
||||||
var usr model.User
|
var usr model.User
|
||||||
err := r.queryOne(sel, &usr)
|
err := r.queryOne(sel, &usr)
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package persistence
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/astaxie/beego/orm"
|
||||||
|
"github.com/deluan/navidrome/log"
|
||||||
|
"github.com/deluan/navidrome/model"
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("UserRepository", func() {
|
||||||
|
var repo model.UserRepository
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
repo = NewUserRepository(log.NewContext(nil), orm.NewOrm())
|
||||||
|
})
|
||||||
|
|
||||||
|
Describe("Put/Get/FindByUsername", func() {
|
||||||
|
usr := model.User{
|
||||||
|
ID: "123",
|
||||||
|
UserName: "AdMiN",
|
||||||
|
Name: "Admin",
|
||||||
|
Email: "admin@admin.com",
|
||||||
|
Password: "wordpass",
|
||||||
|
IsAdmin: true,
|
||||||
|
}
|
||||||
|
It("saves the user to the DB", func() {
|
||||||
|
Expect(repo.Put(&usr)).To(BeNil())
|
||||||
|
})
|
||||||
|
It("returns the newly created user", func() {
|
||||||
|
actual, err := repo.Get("123")
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(actual.Name).To(Equal("Admin"))
|
||||||
|
})
|
||||||
|
It("find the user by case-insensitive username", func() {
|
||||||
|
actual, err := repo.FindByUsername("aDmIn")
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(actual.Name).To(Equal("Admin"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user