/usr/share/gocode/src/github.com/hanwen/go-fuse/fuse/pathfs/owner_test.go is in golang-github-hanwen-go-fuse-dev 0.0~git20171124.0.14c3015-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | // Copyright 2016 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package pathfs
import (
"os"
"syscall"
"testing"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/internal/testutil"
)
type ownerFs struct {
FileSystem
}
const _RANDOM_OWNER = 31415265
func (fs *ownerFs) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
if name == "" {
return &fuse.Attr{
Mode: fuse.S_IFDIR | 0755,
}, fuse.OK
}
a := &fuse.Attr{
Mode: fuse.S_IFREG | 0644,
}
a.Uid = _RANDOM_OWNER
a.Gid = _RANDOM_OWNER
return a, fuse.OK
}
func setupOwnerTest(t *testing.T, opts *nodefs.Options) (workdir string, cleanup func()) {
wd := testutil.TempDir()
opts.Debug = testutil.VerboseTest()
fs := &ownerFs{NewDefaultFileSystem()}
nfs := NewPathNodeFs(fs, nil)
state, _, err := nodefs.MountRoot(wd, nfs.Root(), opts)
if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
go state.Serve()
if err := state.WaitMount(); err != nil {
t.Fatalf("WaitMount: %v", err)
}
return wd, func() {
state.Unmount()
os.RemoveAll(wd)
}
}
func TestOwnerDefault(t *testing.T) {
wd, cleanup := setupOwnerTest(t, nodefs.NewOptions())
defer cleanup()
var stat syscall.Stat_t
err := syscall.Lstat(wd+"/foo", &stat)
if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
if int(stat.Uid) != os.Getuid() || int(stat.Gid) != os.Getgid() {
t.Fatal("Should use current uid for mount")
}
}
func TestOwnerRoot(t *testing.T) {
wd, cleanup := setupOwnerTest(t, &nodefs.Options{})
defer cleanup()
var st syscall.Stat_t
err := syscall.Lstat(wd+"/foo", &st)
if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
if st.Uid != _RANDOM_OWNER || st.Gid != _RANDOM_OWNER {
t.Fatal("Should use FS owner uid")
}
}
func TestOwnerOverride(t *testing.T) {
wd, cleanup := setupOwnerTest(t, &nodefs.Options{Owner: &fuse.Owner{Uid: 42, Gid: 43}})
defer cleanup()
var stat syscall.Stat_t
err := syscall.Lstat(wd+"/foo", &stat)
if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
if stat.Uid != 42 || stat.Gid != 43 {
t.Fatal("Should use current uid for mount")
}
}
|