mirror of
https://github.com/filebrowser/filebrowser.git
synced 2026-07-25 08:54:13 +00:00
test(storage): cover case-insensitive GetByScope matching
Refs GHSA-576v-w77m-gr84
This commit is contained in:
parent
cd5749dff8
commit
7453c78c98
1 changed files with 50 additions and 0 deletions
50
storage/bolt/users_test.go
Normal file
50
storage/bolt/users_test.go
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
package bolt
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/asdine/storm/v3"
|
||||
|
||||
fberrors "github.com/filebrowser/filebrowser/v2/errors"
|
||||
"github.com/filebrowser/filebrowser/v2/users"
|
||||
)
|
||||
|
||||
// GetByScope must match case-insensitively: on a case-insensitive filesystem
|
||||
// two scopes that differ only in case resolve to the same home directory, so
|
||||
// the provisioning collision check has to treat them as the same scope.
|
||||
func TestGetByScopeCaseInsensitive(t *testing.T) {
|
||||
db, err := storm.Open(filepath.Join(t.TempDir(), "db"))
|
||||
if err != nil {
|
||||
t.Fatalf("open db: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { _ = db.Close() })
|
||||
|
||||
st, err := NewStorage(db)
|
||||
if err != nil {
|
||||
t.Fatalf("new storage: %v", err)
|
||||
}
|
||||
if err := st.Users.Save(&users.User{Username: "CaseVictim", Password: "pw", Scope: "/users/CaseVictim"}); err != nil {
|
||||
t.Fatalf("save: %v", err)
|
||||
}
|
||||
|
||||
for _, scope := range []string{"/users/CaseVictim", "/users/casevictim", "/USERS/CASEVICTIM"} {
|
||||
u, err := st.Users.GetByScope(scope)
|
||||
if err != nil {
|
||||
t.Errorf("GetByScope(%q) unexpected error: %v", scope, err)
|
||||
continue
|
||||
}
|
||||
if u.Username != "CaseVictim" {
|
||||
t.Errorf("GetByScope(%q) returned %q, want CaseVictim", scope, u.Username)
|
||||
}
|
||||
}
|
||||
|
||||
// A genuinely different scope must still miss (and the regex-escaped query
|
||||
// must not match a superstring).
|
||||
for _, scope := range []string{"/users/other", "/users/CaseVictimX"} {
|
||||
if _, err := st.Users.GetByScope(scope); !errors.Is(err, fberrors.ErrNotExist) {
|
||||
t.Errorf("GetByScope(%q) expected ErrNotExist, got %v", scope, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue