forked from microsoft/go-winio
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sd_test.go
48 lines (40 loc) · 1.22 KB
/
sd_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
//go:build windows
// +build windows
package winio
import (
"errors"
"testing"
"golang.org/x/sys/windows"
)
func TestLookupInvalidSid(t *testing.T) {
_, err := LookupSidByName(".\\weoifjdsklfj")
var aerr *AccountLookupError
if !errors.As(err, &aerr) || !errors.Is(err, windows.ERROR_NONE_MAPPED) {
t.Fatalf("expected AccountLookupError with ERROR_NONE_MAPPED, got %s", err)
}
}
func TestLookupInvalidName(t *testing.T) {
_, err := LookupNameBySid("notasid")
var aerr *AccountLookupError
if !errors.As(err, &aerr) || !errors.Is(aerr.Err, windows.ERROR_INVALID_SID) {
t.Fatalf("expected AccountLookupError with ERROR_INVALID_SID got %s", err)
}
}
func TestLookupValidSid(t *testing.T) {
everyone := "S-1-1-0"
name, err := LookupNameBySid(everyone)
if err != nil {
t.Fatalf("expected a valid account name, got %v", err)
}
sid, err := LookupSidByName(name)
if err != nil || sid != everyone {
t.Fatalf("expected %s, got %s, %s", everyone, sid, err)
}
}
func TestLookupEmptyNameFails(t *testing.T) {
_, err := LookupSidByName("")
var aerr *AccountLookupError
if !errors.As(err, &aerr) || !errors.Is(aerr.Err, windows.ERROR_NONE_MAPPED) {
t.Fatalf("expected AccountLookupError with ERROR_NONE_MAPPED, got %s", err)
}
}