commit da2d9eee90cb2f7fab51da1204496f293a4f9c8c
parent beb19f986cd16abe04068c7e623920357ce9b0e2
Author: Matsuda Kenji <info@mtkn.jp>
Date: Wed, 20 Dec 2023 08:05:11 +0900
update TestHasPerm
Diffstat:
| M | uid_test.go | | | 46 | +++++++++++++++++++++++++++++++++++++++++----- |
1 file changed, 41 insertions(+), 5 deletions(-)
diff --git a/uid_test.go b/uid_test.go
@@ -6,6 +6,31 @@ import (
"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
@@ -23,6 +48,19 @@ func (f permFile) Close() error { return nil }
func (f permFile) Read(b []byte) (int, error) { return 0, io.EOF }
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
uid string
@@ -30,19 +68,17 @@ func TestHasPerm(t *testing.T) {
want bool
}{
{permFile{0777, "gotoh", "kessoku"}, "gotoh", 04, true},
- // TODO: user is assumed to be the leader of the group...
- {permFile{0770, "gotoh", "kessoku"}, "ijichi", 04, false},
+ {permFile{0770, "gotoh", "kessoku"}, "ijichi", 04, true},
{permFile{0000, "gotoh", "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(st, test.uid, test.perm); got != test.want {
- t.Errorf("hasPerm(file[%d], %s, 0%o) == %t\n",
+ if got := hasPerm(pfs, 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
}