forked from ipfs/kubo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwritable_test.go
More file actions
82 lines (72 loc) · 2.71 KB
/
writable_test.go
File metadata and controls
82 lines (72 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//go:build (linux || darwin || freebsd) && !nofuse
package writable
import (
"syscall"
"testing"
"github.com/hanwen/go-fuse/v2/fuse"
)
// TestSymlinkSetattrChmodNoError verifies that Setattr on a symlink
// with only a mode change is silently accepted. POSIX symlinks have no
// meaningful permission bits (access control uses the target's mode),
// so handlers must not return an error when the kernel forwards a
// chmod-on-symlink request (e.g. via BSD lchmod or fchmodat with
// AT_SYMLINK_NOFOLLOW). Tools like rsync depend on this contract.
//
// This is a unit test rather than an integration test because Linux
// usually rejects fchmodat(AT_SYMLINK_NOFOLLOW) at the VFS layer with
// EOPNOTSUPP and never forwards it to the FUSE filesystem, so a
// userspace test would not actually exercise this code path.
func TestSymlinkSetattrChmodNoError(t *testing.T) {
// MFSFile is nil: Setattr must still succeed without dereferencing
// it. StoreMode is true to confirm that even when persistence is
// enabled, mode changes on symlinks are silently dropped.
s := &Symlink{
Target: "/some/target",
Cfg: &Config{StoreMode: true},
}
in := &fuse.SetAttrIn{}
in.Valid = fuse.FATTR_MODE
in.Mode = 0o600
out := &fuse.AttrOut{}
if errno := s.Setattr(t.Context(), nil, in, out); errno != 0 {
t.Fatalf("Symlink.Setattr returned errno %v, want 0", errno)
}
// fillAttr must report the POSIX symlink mode (0o777), not the
// caller-supplied value, because the request is not stored.
if got := out.Attr.Mode & 0o777; got != 0o777 {
t.Fatalf("Symlink mode = 0o%o, want 0o777", got)
}
}
// TestStatfsReportsSpace verifies that Dir.Statfs proxies the
// disk-space statistics of the repo's backing filesystem, and that an
// empty RepoPath produces zeroed (but successful) results.
func TestStatfsReportsSpace(t *testing.T) {
t.Run("matches repo filesystem", func(t *testing.T) {
dir := t.TempDir()
d := &Dir{Cfg: &Config{RepoPath: dir}}
out := &fuse.StatfsOut{}
if errno := d.Statfs(t.Context(), out); errno != 0 {
t.Fatalf("Statfs returned errno %v, want 0", errno)
}
var want syscall.Statfs_t
if err := syscall.Statfs(dir, &want); err != nil {
t.Fatal(err)
}
if out.Blocks != want.Blocks {
t.Fatalf("Blocks = %d, want %d (from repo path)", out.Blocks, want.Blocks)
}
if out.Bfree != want.Bfree {
t.Fatalf("Bfree = %d, want %d (from repo path)", out.Bfree, want.Bfree)
}
})
t.Run("empty repo path", func(t *testing.T) {
d := &Dir{Cfg: &Config{}}
out := &fuse.StatfsOut{}
if errno := d.Statfs(t.Context(), out); errno != 0 {
t.Fatalf("Statfs returned errno %v, want 0", errno)
}
if out.Blocks != 0 {
t.Fatalf("expected zeroed Blocks when RepoPath is empty, got %d", out.Blocks)
}
})
}