feat: add SSO workspace, named shares and Debian release tooling
This commit is contained in:
1 parent
833d908884
commit
87bc33e675
106 files changed
+4160
-5637
No files matched your search
+1
-17
@@ -4,7 +4,6 @@ import (
|
||||
"github.com/asdine/storm/v3"
|
||||
|
||||
"github.com/filebrowser/filebrowser/v2/auth"
|
||||
fberrors "github.com/filebrowser/filebrowser/v2/errors"
|
||||
"github.com/filebrowser/filebrowser/v2/settings"
|
||||
)
|
||||
|
||||
@@ -13,22 +12,7 @@ type authBackend struct {
|
||||
}
|
||||
|
||||
func (s authBackend) Get(t settings.AuthMethod) (auth.Auther, error) {
|
||||
var auther auth.Auther
|
||||
|
||||
switch t {
|
||||
case auth.MethodJSONAuth:
|
||||
auther = &auth.JSONAuth{}
|
||||
case auth.MethodProxyAuth:
|
||||
auther = &auth.ProxyAuth{}
|
||||
case auth.MethodHookAuth:
|
||||
auther = &auth.HookAuth{}
|
||||
case auth.MethodNoAuth:
|
||||
auther = &auth.NoAuth{}
|
||||
default:
|
||||
return nil, fberrors.ErrInvalidAuthMethod
|
||||
}
|
||||
|
||||
return auther, get(s.db, "auther", auther)
|
||||
return &auth.SSOAuth{}, nil
|
||||
}
|
||||
|
||||
func (s authBackend) Save(a auth.Auther) error {
|
||||
|
||||
+17
-1
@@ -66,7 +66,23 @@ func (s shareBackend) Gets(path string, id uint) ([]*share.Link, error) {
|
||||
}
|
||||
|
||||
func (s shareBackend) Save(l *share.Link) error {
|
||||
return s.db.Save(l)
|
||||
// A public key is an identity, never an upsert target. Serialize lookup and
|
||||
// insert in one write transaction so concurrent creations cannot steal links.
|
||||
tx, err := s.db.Begin(true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
var existing share.Link
|
||||
if err = tx.One("Hash", l.Hash, &existing); err == nil {
|
||||
return storm.ErrAlreadyExists
|
||||
} else if !errors.Is(err, storm.ErrNotFound) {
|
||||
return err
|
||||
}
|
||||
if err = tx.Save(l); err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (s shareBackend) Delete(hash string) error {
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package bolt
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/asdine/storm/v3"
|
||||
"github.com/filebrowser/filebrowser/v2/share"
|
||||
)
|
||||
|
||||
func TestShareKeyConcurrentCreation(t *testing.T) {
|
||||
db, err := storm.Open(filepath.Join(t.TempDir(), "db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
s := shareBackend{db: db}
|
||||
var wg sync.WaitGroup
|
||||
results := make(chan error, 10)
|
||||
for i := 0; i < 10; i++ {
|
||||
wg.Add(1)
|
||||
go func() { defer wg.Done(); results <- s.Save(&share.Link{Hash: "same-key", Path: "/file", UserID: 1}) }()
|
||||
}
|
||||
wg.Wait()
|
||||
close(results)
|
||||
wins := 0
|
||||
for err := range results {
|
||||
if err == nil {
|
||||
wins++
|
||||
} else if !errors.Is(err, storm.ErrAlreadyExists) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if wins != 1 {
|
||||
t.Fatalf("got %d successful inserts, want one", wins)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpiredSharesFilteredWithoutSkipping(t *testing.T) {
|
||||
db, err := storm.Open(filepath.Join(t.TempDir(), "db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
s := share.NewStorage(shareBackend{db: db})
|
||||
for _, l := range []*share.Link{{Hash: "a", Path: "/f", UserID: 1, Expire: time.Now().Add(-time.Hour).Unix()}, {Hash: "b", Path: "/f", UserID: 1, Expire: time.Now().Add(-time.Hour).Unix()}, {Hash: "c", Path: "/f", UserID: 1}} {
|
||||
if err = s.Save(l); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
links, err := s.All()
|
||||
if err != nil || len(links) != 1 || links[0].Hash != "c" {
|
||||
t.Fatalf("unexpected links: %v %v", links, err)
|
||||
}
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func TestDeleteWithPathPrefixTrailingSlash(t *testing.T) {
|
||||
{Hash: "u1-a", Path: "/a", UserID: 1},
|
||||
{Hash: "u1-a-child", Path: "/a/child.txt", UserID: 1},
|
||||
{Hash: "u1-abc", Path: "/abc", UserID: 1}, // sibling sharing a byte prefix
|
||||
{Hash: "u2-a", Path: "/a", UserID: 2}, // other user, must remain
|
||||
{Hash: "u2-a", Path: "/a", UserID: 2}, // other user, must remain
|
||||
}
|
||||
for _, l := range links {
|
||||
if err := s.Save(l); err != nil {
|
||||
|
||||
Reference in new issue
Block a user