-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathapply_test.go
53 lines (47 loc) · 975 Bytes
/
apply_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
//+build windows
package acl
import (
"golang.org/x/sys/windows"
"errors"
"io/ioutil"
"os"
"testing"
)
func TestApply(t *testing.T) {
f, err := ioutil.TempFile(os.TempDir(), "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(f.Name())
if err := Apply(
f.Name(),
true,
true,
DenyName(windows.GENERIC_ALL, "CREATOR OWNER"),
); err != nil {
t.Fatal(err)
}
r, err := os.Open(f.Name())
if err == nil {
r.Close()
t.Fatal("owner able to access file")
}
}
func TestError(t *testing.T) {
if _, err := os.Stat(`C:\Folder\That\Doesnt\Exist`); !os.IsNotExist(err) {
t.Skip(`Oh come on - C:\Folder\That\Doesnt\Exist exists`)
}
err := Apply(
`C:\Folder\That\Doesnt\Exist`,
true,
true,
DenyName(windows.GENERIC_ALL, "CREATOR OWNER"),
)
if err == nil {
t.Fatal("Error expected, none received")
}
t.Log(err)
if !errors.Is(err, os.ErrNotExist) {
t.Fatalf("Expected to receive an error that \"Is\" ErrNotExist, received %s", err)
}
}