commit bb0460e6d21034eb5b0f3bba35851e4a7261603e
parent 2b9eb28563897f60948af9e606f8786cafc6555c
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sat, 23 Dec 2023 09:29:34 +0900
delete permFS and use testfs
Diffstat:
3 files changed, 21 insertions(+), 68 deletions(-)
diff --git a/export_test.go b/export_test.go
@@ -75,4 +75,6 @@ func (rp *ReqPool) Add(tag uint16) (*Req, error) { return rp.add(tag) }
func (fp *FidPool) Lookup(fid uint32) (*Fid, bool) { return fp.lookup(fid) }
-func MarshalMsg(m Msg) []byte { return m.marshal() }
-\ No newline at end of file
+func MarshalMsg(m Msg) []byte { return m.marshal() }
+
+var HasPerm = hasPerm
diff --git a/testfs/fs.go b/testfs/fs.go
@@ -200,6 +200,15 @@ func init() {
"rob": true,
},
},
+ "kessoku": testGroup{
+ leader: "ijichi",
+ members: map[string]bool{
+ "ijichi": true,
+ "yamada": true,
+ "gotoh": true,
+ "kita": true,
+ },
+ },
},
}
SetFsysAndParent(FS, nil)
diff --git a/uid_test.go b/uid_test.go
@@ -1,83 +1,26 @@
-package lib9p
+package lib9p_test
import (
- "io"
"io/fs"
"testing"
-)
-
-type permFS struct {
- groups map[string]permGroup
-}
-
-type permGroup struct {
- leader string
- members map[string]bool
-}
-func (fsys permFS) OpenFile(string, OpenMode) (File, error) { return nil, nil }
-func (fsys permFS) IsGroupLeader(group, uid string) bool {
- pg, ok := fsys.groups[group]
- if !ok {
- return false
- }
- return pg.leader == uid
-}
-func (fsys permFS) IsGroupMember(group, uid string) bool {
- pg, ok := fsys.groups[group]
- if !ok {
- return false
- }
- return pg.members[uid]
-}
-
-type permFile struct {
- mode FileMode
- uid string
- gid string
-}
-
-func (f permFile) Parent() (File, error) { return nil, nil }
-func (f permFile) Child() ([]File, error) { return nil, nil }
-func (f permFile) Stat() (fs.FileInfo, error) {
- return &FileInfo{Stat: Stat{Mode: f.mode, Uid: f.uid, Gid: f.gid}}, nil
-}
-func (f permFile) Qid() Qid { return Qid{} }
-func (f permFile) Open(mode OpenMode) error { return nil }
-func (f permFile) Close() error { return nil }
-func (f permFile) Read(b []byte) (int, error) { return 0, io.EOF }
+ "git.mtkn.jp/lib9p"
+ "git.mtkn.jp/lib9p/testfs"
+)
func TestHasPerm(t *testing.T) {
- pfs := permFS{
- groups: map[string]permGroup{
- "kessoku": permGroup{
- leader: "ijichi",
- members: map[string]bool{
- "ijichi": true,
- "yamada": true,
- "gotoh": true,
- "kita": true,
- },
- },
- },
- }
tests := []struct {
- file permFile
+ st lib9p.Stat
uid string
perm fs.FileMode
want bool
}{
- {permFile{0777, "gotoh", "kessoku"}, "gotoh", 04, true},
- {permFile{0770, "gotoh", "kessoku"}, "ijichi", 04, true},
- {permFile{0000, "gotoh", "kessoku"}, "gotoh", 04, false},
+ {lib9p.Stat{Mode: 0777, Uid: "gotoh", Gid: "kessoku"}, "gotoh", 04, true},
+ {lib9p.Stat{Mode: 0770, Uid: "gotoh", Gid: "kessoku"}, "ijichi", 04, true},
+ {lib9p.Stat{Mode: 0000, Uid: "gotoh", Gid: "kessoku"}, "gotoh", 04, false},
}
for i, test := range tests {
- st, err := test.file.Stat()
- if err != nil {
- t.Errorf("file[%d].Stat(): %v", i, err)
- continue
- }
- if got := hasPerm(pfs, st, test.uid, test.perm); got != test.want {
+ if got := lib9p.HasPerm(testfs.FS, &lib9p.FileInfo{test.st}, test.uid, test.perm); got != test.want {
t.Errorf("hasPerm(pfs, file[%d], %s, 0%o) == %t\n",
i, test.uid, test.perm, got)
continue