-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcredentials_test.go
More file actions
107 lines (88 loc) · 2.18 KB
/
credentials_test.go
File metadata and controls
107 lines (88 loc) · 2.18 KB
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
package adauth_test
import (
"context"
"net"
"testing"
"github.com/RedTeamPentesting/adauth"
)
func TestSetDC(t *testing.T) {
creds := adauth.Credential{
Username: testUser,
Domain: testDomain,
Resolver: &testResolver{},
}
_, err := creds.DC(context.Background(), "host")
if err == nil {
t.Fatalf("expected creds.DC() to fail initially")
}
dcHostname := "dc." + testDomain
creds.SetDC(dcHostname)
dc, err := creds.DC(context.Background(), "host")
if err != nil {
t.Fatalf("get DC: %v", err)
}
if dc.Address() != dcHostname {
t.Fatalf("DC address is %q instead of %q", dc.Address(), dcHostname)
}
}
func TestLookupDC(t *testing.T) {
dcHostname := "dc." + testDomain
creds := adauth.Credential{
Username: testUser,
Domain: testDomain,
Resolver: &testResolver{
SRV: map[string]map[string]map[string]struct {
Name string
SRV []*net.SRV
}{
"kerberos": {
"tcp": {
testDomain: {
Name: dcHostname,
SRV: []*net.SRV{
{Target: dcHostname, Port: 88},
},
},
},
},
},
},
}
dc, err := creds.DC(context.Background(), "host")
if err != nil {
t.Fatalf("get DC: %v", err)
}
if dc.AddressWithoutPort() != dcHostname {
t.Fatalf("DC address is %q instead of %q", dc.Address(), dcHostname)
}
}
func TestUPN(t *testing.T) {
t.Run("user and domain", func(t *testing.T) {
expcetedUPN := "foo@bar"
upn := (&adauth.Credential{Username: "foo", Domain: "bar"}).UPN()
if upn != expcetedUPN {
t.Errorf("UPN is %q insteaf of %q", upn, expcetedUPN)
}
})
t.Run("user without domain", func(t *testing.T) {
expcetedUPN := "foo"
upn := (&adauth.Credential{Username: "foo"}).UPN()
if upn != expcetedUPN {
t.Errorf("UPN is %q insteaf of %q", upn, expcetedUPN)
}
})
t.Run("domain without username", func(t *testing.T) {
expcetedUPN := "@bar"
upn := (&adauth.Credential{Domain: "bar"}).UPN()
if upn != expcetedUPN {
t.Errorf("UPN is %q insteaf of %q", upn, expcetedUPN)
}
})
t.Run("no username and no domain", func(t *testing.T) {
expcetedUPN := ""
upn := (&adauth.Credential{}).UPN()
if upn != expcetedUPN {
t.Errorf("UPN is %q insteaf of %q", upn, expcetedUPN)
}
})
}