-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathchecks_windows_test.go
50 lines (41 loc) · 1.35 KB
/
checks_windows_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
package main
import (
"io/ioutil"
"os"
"testing"
"github.com/hectane/go-acl"
"github.com/stretchr/testify/assert"
"golang.org/x/sys/windows"
)
func TestPermissionIs(t *testing.T) {
filePath := "misc/tests/permTest.txt"
ioutil.WriteFile(filePath, []byte("testContent"), os.ModePerm)
defer os.Remove(filePath)
c := cond{
Path: filePath,
Name: "BUILTIN\\Users",
Value: "Read",
}
// users deny read access
acl.Apply(filePath, true, false, acl.DenyName(windows.GENERIC_READ, "BUILTIN\\Users"))
ok, err := c.PermissionIs()
assert.Nil(t, err, "Should not have error")
assert.NotEqual(t, ok, true, "must be Read")
// users read access
acl.Apply(filePath, true, false, acl.GrantName(windows.GENERIC_READ, "BUILTIN\\Users"))
ok, err = c.PermissionIs()
assert.Nil(t, err, "Should not have error")
assert.Equal(t, ok, true, "must be Read")
c.Name = "everyone"
c.Value = "FullControl"
// everyone deny full access
acl.Apply(filePath, true, false, acl.DenyName(windows.GENERIC_ALL, "everyone"))
ok, err = c.PermissionIs()
assert.Nil(t, err, "Should not have error")
assert.NotEqual(t, ok, true, "Must be FullControl")
// everyone full access
acl.Apply(filePath, true, false, acl.GrantName(windows.GENERIC_ALL, "everyone"))
ok, err = c.PermissionIs()
assert.Nil(t, err, "Should not have error")
assert.Equal(t, ok, true, "Must be FullControl")
}