...
1
2
3
4 package winio
5
6 import (
7 "errors"
8 "testing"
9
10 "golang.org/x/sys/windows"
11 )
12
13 func TestLookupInvalidSid(t *testing.T) {
14 _, err := LookupSidByName(".\\weoifjdsklfj")
15 var aerr *AccountLookupError
16 if !errors.As(err, &aerr) || !errors.Is(err, windows.ERROR_NONE_MAPPED) {
17 t.Fatalf("expected AccountLookupError with ERROR_NONE_MAPPED, got %s", err)
18 }
19 }
20
21 func TestLookupInvalidName(t *testing.T) {
22 _, err := LookupNameBySid("notasid")
23 var aerr *AccountLookupError
24 if !errors.As(err, &aerr) || !errors.Is(aerr.Err, windows.ERROR_INVALID_SID) {
25 t.Fatalf("expected AccountLookupError with ERROR_INVALID_SID got %s", err)
26 }
27 }
28
29 func TestLookupValidSid(t *testing.T) {
30 everyone := "S-1-1-0"
31 name, err := LookupNameBySid(everyone)
32 if err != nil {
33 t.Fatalf("expected a valid account name, got %v", err)
34 }
35
36 sid, err := LookupSidByName(name)
37 if err != nil || sid != everyone {
38 t.Fatalf("expected %s, got %s, %s", everyone, sid, err)
39 }
40 }
41
42 func TestLookupEmptyNameFails(t *testing.T) {
43 _, err := LookupSidByName("")
44 var aerr *AccountLookupError
45 if !errors.As(err, &aerr) || !errors.Is(aerr.Err, windows.ERROR_NONE_MAPPED) {
46 t.Fatalf("expected AccountLookupError with ERROR_NONE_MAPPED, got %s", err)
47 }
48 }
49
View as plain text