fix: preserve WebDAV MOVE destination precedence

This commit is contained in:
OpenClaw Agent
2026-09-21 22:34:16 +08:00
parent 52f0a1218b
commit bf526cac2a
2 changed files with 42 additions and 7 deletions
+23 -4
View File
@@ -24,11 +24,11 @@ func TestWebDAVAuthFSCheckTree(t *testing.T) {
t.Fatal(err)
}
account := &auth.Account{Mask: auth.Delete, Rules: []auth.PathRule{
{Dir: "test", Mask: auth.Delete},
account := &auth.Account{Mask: auth.Read | auth.Write | auth.Delete, Rules: []auth.PathRule{
{Dir: "test", Mask: auth.Read | auth.Write | auth.Delete},
{Dir: "test/private", Mask: auth.None},
}}
fs := &webdavAuthFS{inner: webdav.LocalFileSystem(root), account: account}
fs := &webdavAuthFS{inner: &webdavStorageFS{store: storage.Local{Root: root}}, account: account}
if err := fs.checkTree(context.Background(), "/test", auth.Delete); err == nil {
t.Fatal("expected recursive delete permission check to reject inaccessible descendant")
@@ -47,7 +47,7 @@ func TestWebDAVAuthFSOverwriteRequiresDelete(t *testing.T) {
t.Fatal(err)
}
account := &auth.Account{Mask: auth.Write}
fs := &webdavAuthFS{inner: webdav.LocalFileSystem(root), account: account}
fs := &webdavAuthFS{inner: &webdavStorageFS{store: storage.Local{Root: root}}, account: account}
if err := fs.authorizeOverwrite(context.Background(), "/dst.txt"); err == nil {
t.Fatal("expected overwrite authorization to require delete permission")
}
@@ -94,6 +94,25 @@ func TestWebDAVStorageFSRejectsDestinationInsideSource(t *testing.T) {
}
}
func TestWebDAVAuthFSMoveMissingSourcePrecedence(t *testing.T) {
root := t.TempDir()
if err := os.WriteFile(filepath.Join(root, "existing.txt"), []byte("existing"), 0o644); err != nil {
t.Fatal(err)
}
account := &auth.Account{Mask: auth.Read | auth.Write | auth.Delete}
fs := &webdavAuthFS{inner: &webdavStorageFS{store: storage.Local{Root: root}}, account: account}
_, err := fs.Move(context.Background(), "/missing.txt", "/new.txt", &webdav.MoveOptions{})
if err == nil || err.Error() != "403 Forbidden: source not found" {
t.Fatalf("missing source to free destination: got %v", err)
}
_, err = fs.Move(context.Background(), "/missing.txt", "/existing.txt", &webdav.MoveOptions{})
if err == nil || err.Error() != "412 Precondition Failed: destination exists" {
t.Fatalf("missing source to occupied destination: got %v", err)
}
}
func TestWebDAVStorageFSCopyAndMove(t *testing.T) {
root1 := t.TempDir()
root2 := t.TempDir()