-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathentity_test.go
98 lines (83 loc) · 2.45 KB
/
entity_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
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
package ldsview
import (
"strings"
"testing"
)
var EntityStr = `
# MYUSR, ContosoUsers, contoso.com
dn: CN=MYUSR,OU=ContosoUsers,DC=contoso,DC=com
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
cn: MYUSR
givenName: MYUSR
distinguishedName: CN=MYUSR,OU=ContosoUsers,DC=contoso,DC=com
instanceType: 4
whenCreated: 20120423175240.0Z
whenChanged: 20190225044802.0Z
displayName: MYUSR
uSNCreated: 793245
memberOf: CN=vault_users,OU=Global,OU=Security,OU=Groups,DC=contoso,DC=com
memberOf: CN=PWD Complexity,OU=Security,OU=Groups,DC=contoso,DC=com
uSNChanged: 1076364863
name: MYUSR
objectGUID:: 7OBfD10nQkSVYY8UHCV2aQ==
userAccountControl: 66048
codePage: 0
countryCode: 0
pwdLastSet: 129857191591306845
primaryGroupID: 805306368
objectSid:: AQUAAAAAAAUVAAAAa9ZiBBbA6jKDPStVYiIMAA==
accountExpires: 9223372036854775807
sAMAccountName: MYUSR
sAMAccountType: 805306368
userPrincipalName: MYUSR@contoso.com
lockoutTime: 0
objectCategory: CN=Person,CN=Schema,CN=Configuration,DC=contoso,DC=com
dSCorePropagationData: 20190827201429.0Z
dSCorePropagationData: 20190529140155.0Z
dSCorePropagationData: 20190407190910.0Z
dSCorePropagationData: 20190311163932.0Z
dSCorePropagationData: 16010714223649.0Z
lastLogonTimestamp: 130674899604502606
`
func TestEntity_BuildEntity(t *testing.T) {
entityLines := strings.Split(EntityStr, "\n")[1:]
entity := BuildEntity(entityLines)
if entity.IsEmpty() {
t.Fatalf("failed to parse entity")
}
dn, _ := entity.GetDN()
if dn.Value.GetSingleValue() != "CN=MYUSR,OU=ContosoUsers,DC=contoso,DC=com" {
t.Errorf("Failed to parse entity DN")
}
if len(entity.Groups()) != 2 {
t.Errorf("failed to parse entity groups")
}
}
func TestEntity_BuildEntityWithAttrFilter(t *testing.T) {
entityLines := strings.Split(EntityStr, "\n")[1:]
attrsList := []string{
"samaccountname",
"userPrincipalName",
"objectClass",
}
attrFilter := BuildAttributeFilter(attrsList)
entity := BuildEntityFromAttrList(entityLines, &attrFilter)
if entity.IsEmpty() {
t.Fatalf("failed to parse entity")
}
dn, _ := entity.GetDN()
if dn.Value.GetSingleValue() != "CN=MYUSR,OU=ContosoUsers,DC=contoso,DC=com" {
t.Fatalf("Failed to parse entity DN")
}
// 3 user specified, plus the 2 dn attributes
if entity.Size() != 5 {
t.Fatalf("Failed to parse all attributes")
}
objClassAttr, found := entity.GetAttribute("objectClass")
if !found || objClassAttr.Value.Size() != 4 {
t.Fatalf("failed to parse multi-valued attribute")
}
}