-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathacl_test.go
107 lines (92 loc) · 1.81 KB
/
acl_test.go
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
101
102
103
104
105
106
107
// Copyright (c) 2015 Joseph Naegele. See LICENSE file.
package acl
import (
"os"
"testing"
)
const (
tmpfile = "acl-tmp-test-file"
tmpdir = "acl-tmp-test-dir"
)
func getACLFromTmpFile(t *testing.T) *ACL {
f, err := os.Create(tmpfile)
if err != nil {
t.Fatal(err)
}
f.Close()
defer os.Remove(tmpfile)
acl, err := GetFileAccess(tmpfile)
if err != nil {
t.Fatal("Failed to get ACL from file: ", err)
}
return acl
}
func checkForBaseEntries(t *testing.T, acl *ACL) {
// the base access entries on a normal file should have
// a USER_OBJ, GROUP_OBJ, and OTHER entry
var u, g, o bool
for e := acl.FirstEntry(); e != nil; e = acl.NextEntry() {
tag, err := e.GetTag()
if err != nil {
t.Fatal(err)
}
switch tag {
case TagUserObj:
u = true
case TagGroupObj:
g = true
case TagOther:
o = true
}
}
if !u || !g || !o {
t.Fail()
}
}
func TestGetFile(t *testing.T) {
acl := getACLFromTmpFile(t)
acl.Free()
}
func TestSetFile(t *testing.T) {
acl := New()
if acl == nil {
t.Fatal("unable to create new ACL")
}
f, err := os.Create(tmpfile)
if err != nil {
t.Fatal(err)
}
f.Close()
defer os.Remove(tmpfile)
if err := acl.SetFileAccess(tmpfile); err != nil {
t.Fatal(err)
}
}
func TestGetEntries(t *testing.T) {
acl := getACLFromTmpFile(t)
defer acl.Free()
checkForBaseEntries(t, acl)
}
func TestAddEntry(t *testing.T) {
f, err := os.Create(tmpfile)
if err != nil {
t.Fatal(err)
}
f.Close()
defer os.Remove(tmpfile)
acl, err := GetFileAccess(tmpfile)
if err != nil {
t.Fatal("Failed to get ACL from file: ", err)
}
defer acl.Free()
empty := New()
if empty == nil {
t.Fatal("unable to create new ACL")
}
for e := acl.FirstEntry(); e != nil; e = acl.NextEntry() {
if err := empty.AddEntry(e); err != nil {
t.Fatal(err)
}
}
checkForBaseEntries(t, empty)
}