-
Notifications
You must be signed in to change notification settings - Fork 4
/
processData_test.go
155 lines (135 loc) · 30.9 KB
/
processData_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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package main
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func Test_buildComputerCyphers(t *testing.T) {
data, err := parseFile("test_data/computer.json")
if err != nil {
t.Error(err)
return
}
expected := map[string]*cypher{
"b32701af876d8bdeb5c2cdb6dec6b32ee50b2cc0": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.objectid}) SET n:Computer SET n += item.properties", list: []map[string]interface{}{{"objectid": "S-1-5-21-3130019616-2776909439-2417379446-1001", "properties": map[string]interface{}{"description": interface{}(nil), "distinguishedname": "CN=PRIMARY,OU=Domain Controllers,DC=testlab,DC=local", "domain": "TESTLAB.LOCAL", "enabled": true, "haslaps": false, "highvalue": false, "lastlogontimestamp": 1.583951963e+09, "name": "PRIMARY.TESTLAB.LOCAL", "objectid": "S-1-5-21-3130019616-2776909439-2417379446-1001", "operatingsystem": "Windows Server 2012 R2 Standard Evaluation", "pwdlastset": 1.583951963e+09, "serviceprincipalnames": []interface{}{"Dfsr-12F9A27C-BF97-4787-9364-D31B6C55EB04/PRIMARY.testlab.local", "ldap/PRIMARY.testlab.local/ForestDnsZones.testlab.local", "ldap/PRIMARY.testlab.local/DomainDnsZones.testlab.local", "DNS/PRIMARY.testlab.local", "GC/PRIMARY.testlab.local/testlab.local", "RestrictedKrbHost/PRIMARY.testlab.local", "RestrictedKrbHost/PRIMARY", "RPC/a052f434-0629-458a-bd51-48118140ae3c._msdcs.testlab.local", "HOST/PRIMARY/TESTLAB", "HOST/PRIMARY.testlab.local/TESTLAB", "HOST/PRIMARY", "HOST/PRIMARY.testlab.local", "HOST/PRIMARY.testlab.local/testlab.local", "E3514235-4B06-11D1-AB04-00C04FC2DCD2/a052f434-0629-458a-bd51-48118140ae3c/testlab.local", "ldap/PRIMARY/TESTLAB", "ldap/a052f434-0629-458a-bd51-48118140ae3c._msdcs.testlab.local", "ldap/PRIMARY.testlab.local/TESTLAB", "ldap/PRIMARY", "ldap/PRIMARY.testlab.local", "ldap/PRIMARY.testlab.local/testlab.local"}, "unconstraineddelegation": true}}}},
"870de9dbda3592d49c69ba9989103ee73c88a50c": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Computer MERGE (n)-[r:GenericAll {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "S-1-5-21-3130019616-2776909439-2417379446-1001"}, {"isinherited": true, "source": "S-1-5-21-3130019616-2776909439-2417379446-519", "target": "S-1-5-21-3130019616-2776909439-2417379446-1001"}}},
"9dec519eefffc68ef75a69fe865572138ce65949": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Computer MERGE (n)-[r:WriteDacl {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": true, "source": "TESTLAB.LOCAL-S-1-5-32-544", "target": "S-1-5-21-3130019616-2776909439-2417379446-1001"}}},
"dbc7fbcdf3e5e5fe3cf91469d7a7390fc2e7681f": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Computer MERGE (n)-[r:WriteOwner {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": true, "source": "TESTLAB.LOCAL-S-1-5-32-544", "target": "S-1-5-21-3130019616-2776909439-2417379446-1001"}}},
"82f1ef1b8190aff5963249d49f41e03e63f6728d": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Computer MERGE (n)-[r:GenericWrite {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": true, "source": "TESTLAB.LOCAL-S-1-5-32-544", "target": "S-1-5-21-3130019616-2776909439-2417379446-1001"}}},
"e1d26a785667f35d4774f47b921ef58dba9fc7d3": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Computer MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Group MERGE (n)-[r:MemberOf {isacl:false}]->(m)", list: []map[string]interface{}{{"source": "S-1-5-21-3130019616-2776909439-2417379446-1001", "target": "S-1-5-21-3130019616-2776909439-2417379446-516"}}},
"32a794b9e1eec6003b5ab0030069f876bfa904a6": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:User MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Computer MERGE (n)-[r:AdminTo {isacl:false, fromgpo: false}]->(m)", list: []map[string]interface{}{{"source": "S-1-5-21-3130019616-2776909439-2417379446-500", "target": "S-1-5-21-3130019616-2776909439-2417379446-1001"}}},
"74679e69f964fc050e1507ad0cebc05fbfad4e26": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Computer MERGE (n)-[r:Owns {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "S-1-5-21-3130019616-2776909439-2417379446-1001"}}},
"d929349fe1ec937337940a689a746a3cca44f152": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Computer MERGE (n)-[r:AdminTo {isacl:false, fromgpo: false}]->(m)", list: []map[string]interface{}{{"source": "S-1-5-21-3130019616-2776909439-2417379446-519", "target": "S-1-5-21-3130019616-2776909439-2417379446-1001"}, {"source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "S-1-5-21-3130019616-2776909439-2417379446-1001"}}},
"49640e0bfbf698ba13c4f53a3f7d6f30eded688b": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Computer MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Computer MERGE (n)-[r:AllowedToDelegate {isacl:false}]->(m)", list: []map[string]interface{}(nil)},
"11c7ed1567383cd506905486d192faedb4b83fad": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Computer MERGE (m:Base {objectid: item.target}) ON CREATE SET m:User MERGE (n)-[r:HasSession {isacl:false}]->(m)", list: []map[string]interface{}{{"source": "S-1-5-21-3130019616-2776909439-2417379446-1001", "target": "S-1-5-21-3130019616-2776909439-2417379446-500"}}},
}
got := buildComputerCyphers(data.Computers)
if diff := cmp.Diff(expected, got, cmp.AllowUnexported(cypher{})); diff != "" {
t.Errorf("TestComputer_buildTransactions() mismatch (-want got):\n%s", diff)
}
}
func Test_buildUserCyphers(t *testing.T) {
data, err := parseFile("test_data/user.json")
if err != nil {
t.Error(err)
return
}
expected := map[string]*cypher{
"d8145bd42cfe6167b17db6a07b809d1c32ea89f1": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.objectid}) SET n:User SET n += item.properties", list: []map[string]interface{}{{"objectid": "S-1-5-21-3130019616-2776909439-2417379446-500", "properties": map[string]interface{}{"admincount": true, "description": "Built-in account for administering the computer/domain", "displayname": interface{}(nil), "distinguishedname": "CN=Administrator,CN=Users,DC=testlab,DC=local", "domain": "TESTLAB.LOCAL", "dontreqpreauth": false, "email": interface{}(nil), "enabled": true, "hasspn": false, "highvalue": false, "homedirectory": interface{}(nil), "lastlogon": 1.579223741e+09, "lastlogontimestamp": 1.578330279e+09, "name": "[email protected]", "objectid": "S-1-5-21-3130019616-2776909439-2417379446-500", "passwordnotreqd": false, "pwdlastset": 1.568654366e+09, "pwdneverexpires": true, "sensitive": false, "serviceprincipalnames": []interface{}{}, "sidhistory": []interface{}{}, "title": interface{}(nil), "unconstraineddelegation": false, "userpassword": interface{}(nil)}}}},
"7e7f3fcb44510dde8ce0753ff1f44d3167029f36": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:User MERGE (n)-[r:WriteOwner {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "TESTLAB.LOCAL-S-1-5-32-544", "target": "S-1-5-21-3130019616-2776909439-2417379446-500"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "S-1-5-21-3130019616-2776909439-2417379446-500"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-519", "target": "S-1-5-21-3130019616-2776909439-2417379446-500"}}},
"540c575d12cb8ffdd8cf4813ade041c6181ed3cf": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:User MERGE (n)-[r:AllExtendedRights {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "TESTLAB.LOCAL-S-1-5-32-544", "target": "S-1-5-21-3130019616-2776909439-2417379446-500"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "S-1-5-21-3130019616-2776909439-2417379446-500"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-519", "target": "S-1-5-21-3130019616-2776909439-2417379446-500"}}},
"496e1fa086bb49f3f9960e76898d004b08f6a935": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:User MERGE (n)-[r:GenericWrite {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "TESTLAB.LOCAL-S-1-5-32-544", "target": "S-1-5-21-3130019616-2776909439-2417379446-500"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "S-1-5-21-3130019616-2776909439-2417379446-500"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-519", "target": "S-1-5-21-3130019616-2776909439-2417379446-500"}}},
"ada7d789b860d07d01d202da805aa87e7fe1771c": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:User MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Group MERGE (n)-[r:MemberOf {isacl:false}]->(m)", list: []map[string]interface{}{{"source": "S-1-5-21-3130019616-2776909439-2417379446-500", "target": "S-1-5-21-3130019616-2776909439-2417379446-513"}}},
"019c791de94b3108f2776c4f4d074f16a182a289": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:User MERGE (n)-[r:Owns {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "S-1-5-21-3130019616-2776909439-2417379446-500"}}},
"af25cf6b2279d5e07e76862e715d217cab589ac3": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:User MERGE (n)-[r:WriteDacl {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "TESTLAB.LOCAL-S-1-5-32-544", "target": "S-1-5-21-3130019616-2776909439-2417379446-500"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "S-1-5-21-3130019616-2776909439-2417379446-500"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-519", "target": "S-1-5-21-3130019616-2776909439-2417379446-500"}}},
}
got := buildUserCyphers(data.Users)
if diff := cmp.Diff(expected, got, cmp.AllowUnexported(cypher{})); diff != "" {
t.Errorf("TestComputer_buildTransactions() mismatch (-want got):\n%s", diff)
}
}
func Test_buildGroupCyphers(t *testing.T) {
data, err := parseFile("test_data/group.json")
if err != nil {
t.Error(err)
return
}
expected := map[string]*cypher{
"65a77b3d6f14fb5ef9bc8e3a156f5ddec92bc405": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.objectid}) SET n:Group SET n += item.properties", list: []map[string]interface{}{{"objectid": "TESTLAB.LOCAL-S-1-5-32-544", "properties": map[string]interface{}{"admincount": true, "description": "Administrators have complete and unrestricted access to the computer/domain", "distinguishedname": "CN=Administrators,CN=Builtin,DC=testlab,DC=local", "domain": "TESTLAB.LOCAL", "highvalue": true, "name": "[email protected]", "objectid": "TESTLAB.LOCAL-S-1-5-32-544"}}}},
"49a2f61f593a0be5cd26541c6e2b7f672183b9c2": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Group MERGE (n)-[r:Owns {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "TESTLAB.LOCAL-S-1-5-32-544"}}},
"3c651995846c17c3fcca54616a0f4c313f80ba78": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Group MERGE (n)-[r:WriteDacl {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "TESTLAB.LOCAL-S-1-5-32-544"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-519", "target": "TESTLAB.LOCAL-S-1-5-32-544"}}},
"766915ca675ec66780d9578cf8086433cfeca766": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Group MERGE (n)-[r:WriteOwner {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "TESTLAB.LOCAL-S-1-5-32-544"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-519", "target": "TESTLAB.LOCAL-S-1-5-32-544"}}},
"33ce44fd98f6676c272da305d412226b15328b9b": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Group MERGE (n)-[r:GenericWrite {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "TESTLAB.LOCAL-S-1-5-32-544"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-519", "target": "TESTLAB.LOCAL-S-1-5-32-544"}}},
"f2f23a35780eb9f954486243d6b439e0d7774e37": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Group MERGE (n)-[r:MemberOf {isacl:false}]->(m)", list: []map[string]interface{}{{"source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "TESTLAB.LOCAL-S-1-5-32-544"}, {"source": "S-1-5-21-3130019616-2776909439-2417379446-519", "target": "TESTLAB.LOCAL-S-1-5-32-544"}}},
"ada7d789b860d07d01d202da805aa87e7fe1771c": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:User MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Group MERGE (n)-[r:MemberOf {isacl:false}]->(m)", list: []map[string]interface{}{{"source": "S-1-5-21-3130019616-2776909439-2417379446-500", "target": "TESTLAB.LOCAL-S-1-5-32-544"}}},
}
got := buildGroupCyphers(data.Groups)
if diff := cmp.Diff(expected, got, cmp.AllowUnexported(cypher{})); diff != "" {
t.Errorf("TestComputer_buildTransactions() mismatch (-want got):\n%s", diff)
}
}
func Test_buildGPOCyphers(t *testing.T) {
data, err := parseFile("test_data/gpo.json")
if err != nil {
t.Error(err)
return
}
expected := map[string]*cypher{
"0df9a493119acfd61958e42785a491913c6e9318": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.objectid}) SET n:GPO SET n += item.properties", list: []map[string]interface{}{{"objectid": "BE91688F-1333-45DF-93E4-4D2E8A36DE2B", "properties": map[string]interface{}{"description": interface{}(nil), "distinguishedname": "CN={31B2F340-016D-11D2-945F-00C04FB984F9},CN=Policies,CN=System,DC=testlab,DC=local", "domain": "TESTLAB.LOCAL", "gpcpath": "\\\\testlab.local\\sysvol\\testlab.local\\Policies\\{31B2F340-016D-11D2-945F-00C04FB984F9}", "highvalue": false, "name": "DEFAULT DOMAIN [email protected]", "objectid": "BE91688F-1333-45DF-93E4-4D2E8A36DE2B"}}}},
"7ab950cb6ece95de8dd002b6e41c5b49d6fe0d70": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:GPO MERGE (n)-[r:Owns {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "BE91688F-1333-45DF-93E4-4D2E8A36DE2B"}}},
"2064cbe5c73f74de14517ad8cd0bae177fb01a7d": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:GPO MERGE (n)-[r:WriteDacl {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "BE91688F-1333-45DF-93E4-4D2E8A36DE2B"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "BE91688F-1333-45DF-93E4-4D2E8A36DE2B"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-519", "target": "BE91688F-1333-45DF-93E4-4D2E8A36DE2B"}}},
"efed6483857aeaa794c7904b3a7ae7dc7048ef07": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:GPO MERGE (n)-[r:WriteOwner {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "BE91688F-1333-45DF-93E4-4D2E8A36DE2B"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "BE91688F-1333-45DF-93E4-4D2E8A36DE2B"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-519", "target": "BE91688F-1333-45DF-93E4-4D2E8A36DE2B"}}},
"4542d268f566ca16e1abf4ab2e84390bd12e3af3": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:GPO MERGE (n)-[r:GenericWrite {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "BE91688F-1333-45DF-93E4-4D2E8A36DE2B"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "BE91688F-1333-45DF-93E4-4D2E8A36DE2B"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-519", "target": "BE91688F-1333-45DF-93E4-4D2E8A36DE2B"}}},
}
got := buildGPOCyphers(data.Gpos)
if diff := cmp.Diff(expected, got, cmp.AllowUnexported(cypher{})); diff != "" {
t.Errorf("TestComputer_buildTransactions() mismatch (-want got):\n%s", diff)
}
}
func Test_buildOUCyphers(t *testing.T) {
data, err := parseFile("test_data/ou.json")
if err != nil {
t.Error(err)
return
}
expected := map[string]*cypher{
"79eade76b65a656f307bb2115884da06022ecfe6": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:OU MERGE (m:Base {objectid: item.target}) ON CREATE SET m:User MERGE (n)-[r:Contains {isacl: false}]->(m)", list: []map[string]interface{}(nil)},
"d08c1de8977a543e997255f6cd7f843aad6e2537": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:OU MERGE (m:Base {objectid: item.target}) ON CREATE SET m:OU MERGE (n)-[r:Contains {isacl: false}]->(m)", list: []map[string]interface{}(nil)},
"0d914ab1eea05f8c23e2bf403b9aa1ad02f53601": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:GPO MERGE (m:Base {objectid: item.target}) ON CREATE SET m:OU MERGE (n)-[r:GpLink {isacl: false, enforced: item.enforced}]->(m)", list: []map[string]interface{}{{"enforced": false, "source": "F5BDDA03-0183-4F41-93A2-DCA253BE6450", "target": "0DE400CD-2FF3-46E0-8A26-2C917B403C65"}}},
"c8369da6cc3808631f0ce854e5e99596f8c9201a": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.objectid}) SET n:OU SET n += item.properties", list: []map[string]interface{}{{"objectid": "0DE400CD-2FF3-46E0-8A26-2C917B403C65", "properties": map[string]interface{}{"blocksinheritance": false, "description": "Default container for domain controllers", "distinguishedname": "OU=Domain Controllers,DC=testlab,DC=local", "domain": "TESTLAB.LOCAL", "highvalue": false, "name": "DOMAIN [email protected]", "objectid": "0DE400CD-2FF3-46E0-8A26-2C917B403C65"}}}},
"e23e3c14ffd2229a713bd00b94cf91848469234d": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:OU MERGE (n)-[r:Owns {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "0DE400CD-2FF3-46E0-8A26-2C917B403C65"}}},
"7a45216b07197b54956c297ceacd6c99f27d87af": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:OU MERGE (n)-[r:GenericAll {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": true, "source": "S-1-5-21-3130019616-2776909439-2417379446-519", "target": "0DE400CD-2FF3-46E0-8A26-2C917B403C65"}}},
"6cbef55f21bd4a4916774ffbb19a24c5ddbecfba": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:OU MERGE (n)-[r:WriteDacl {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "0DE400CD-2FF3-46E0-8A26-2C917B403C65"}, {"isinherited": true, "source": "TESTLAB.LOCAL-S-1-5-32-544", "target": "0DE400CD-2FF3-46E0-8A26-2C917B403C65"}}},
"16d615eacc89ce610f8cbd71c616e8c12d2352d5": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:OU MERGE (n)-[r:WriteOwner {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "0DE400CD-2FF3-46E0-8A26-2C917B403C65"}, {"isinherited": true, "source": "TESTLAB.LOCAL-S-1-5-32-544", "target": "0DE400CD-2FF3-46E0-8A26-2C917B403C65"}}},
"5d5a32c7e25778d58b7c2cf0716f31e6c9b017dd": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:OU MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Computer MERGE (n)-[r:Contains {isacl: false}]->(m)", list: []map[string]interface{}{{"source": "0DE400CD-2FF3-46E0-8A26-2C917B403C65", "target": "S-1-5-21-3130019616-2776909439-2417379446-1001"}}},
}
got := buildOUCyphers(data.OUs)
if diff := cmp.Diff(expected, got, cmp.AllowUnexported(cypher{})); diff != "" {
t.Errorf("TestComputer_buildTransactions() mismatch (-want got):\n%s", diff)
}
}
func Test_buildDomainCyphers(t *testing.T) {
data, err := parseFile("test_data/domain.json")
if err != nil {
t.Error(err)
return
}
expected := map[string]*cypher{
"20cd756687417b4114b68b9b3f64ecf044014935": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Domain MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Domain MERGE (n)-[r:TrustedBy {sidfiltering: item.sidfiltering, trusttype: item.trusttype, transitive: item.transitive, isacl: false}]->(m)", list: []map[string]interface{}{{"sidfiltering": true, "source": "S-1-5-21-3130019616-2776909439-2417379446", "target": "S-1-5-21-3084884204-958224920-2707782874", "transitive": true, "trusttype": "Unknown"}, {"sidfiltering": true, "source": "S-1-5-21-3084884204-958224920-2707782874", "target": "S-1-5-21-3130019616-2776909439-2417379446", "transitive": true, "trusttype": "Unknown"}}},
"f1bd34f29b69ecad2964af9dd6144dee3ef9905c": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Domain MERGE (n)-[r:Owns {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "TESTLAB.LOCAL-S-1-5-32-544", "target": "S-1-5-21-3130019616-2776909439-2417379446"}}},
"7a3e91a19490ddb368effe12cc6105b11f37fe3e": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Domain MERGE (n)-[r:WriteOwner {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "TESTLAB.LOCAL-S-1-5-32-544", "target": "S-1-5-21-3130019616-2776909439-2417379446"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "S-1-5-21-3130019616-2776909439-2417379446"}}},
"ce1e2bf6ac3d251a0a93391e04352f9e554d068d": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Domain MERGE (n)-[r:GenericAll {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-519", "target": "S-1-5-21-3130019616-2776909439-2417379446"}}},
"8f64d9e562ae30951eccdfee0a6ce41208190ec6": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Domain MERGE (n)-[r:GetChanges {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "TESTLAB.LOCAL-S-1-5-9", "target": "S-1-5-21-3130019616-2776909439-2417379446"}, {"isinherited": false, "source": "TESTLAB.LOCAL-S-1-5-32-544", "target": "S-1-5-21-3130019616-2776909439-2417379446"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-498", "target": "S-1-5-21-3130019616-2776909439-2417379446"}}},
"27c856b9767607226ac65b27d14618e5b6cc1b48": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Domain MERGE (n)-[r:GetChangesAll {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "TESTLAB.LOCAL-S-1-5-32-544", "target": "S-1-5-21-3130019616-2776909439-2417379446"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-516", "target": "S-1-5-21-3130019616-2776909439-2417379446"}}},
"b69dd57a0b00a63160cb394b5147f7695a445219": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Domain MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Computer MERGE (n)-[r:Contains {isacl: false}]->(m)", list: []map[string]interface{}{{"source": "S-1-5-21-3130019616-2776909439-2417379446", "target": "S-1-5-21-3130019616-2776909439-2417379446-2105"}}},
"84d5de34d0ebd2493decbeef52a206ad8c9bab57": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.objectid}) SET n:Domain SET n += item.properties", list: []map[string]interface{}{{"objectid": "S-1-5-21-3130019616-2776909439-2417379446", "properties": map[string]interface{}{"description": interface{}(nil), "distinguishedname": "DC=testlab,DC=local", "domain": "TESTLAB.LOCAL", "functionallevel": "2012 R2", "highvalue": true, "name": "TESTLAB.LOCAL", "objectid": "S-1-5-21-3130019616-2776909439-2417379446"}}, {"objectid": "S-1-5-21-3084884204-958224920-2707782874", "properties": map[string]interface{}{"name": "EXTERNAL.LOCAL"}}}},
"4a6ea123ab8853eeac8266345ae901ecdc805bb5": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Domain MERGE (n)-[r:WriteDacl {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "TESTLAB.LOCAL-S-1-5-32-544", "target": "S-1-5-21-3130019616-2776909439-2417379446"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "S-1-5-21-3130019616-2776909439-2417379446"}}},
"966c6b5b864b80b5f7cb1dfd056e4b4aed26dc80": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Group MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Domain MERGE (n)-[r:AllExtendedRights {isacl: true, isinherited: item.isinherited}]->(m)", list: []map[string]interface{}{{"isinherited": false, "source": "TESTLAB.LOCAL-S-1-5-32-544", "target": "S-1-5-21-3130019616-2776909439-2417379446"}, {"isinherited": false, "source": "S-1-5-21-3130019616-2776909439-2417379446-512", "target": "S-1-5-21-3130019616-2776909439-2417379446"}}},
"585b50e8368829a33a40c44d9999c56a9a99e0cd": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Domain MERGE (m:Base {objectid: item.target}) ON CREATE SET m:User MERGE (n)-[r:Contains {isacl: false}]->(m)", list: []map[string]interface{}{{"source": "S-1-5-21-3130019616-2776909439-2417379446", "target": "S-1-5-21-3130019616-2776909439-2417379446-2103"}, {"source": "S-1-5-21-3130019616-2776909439-2417379446", "target": "S-1-5-21-3130019616-2776909439-2417379446-500"}, {"source": "S-1-5-21-3130019616-2776909439-2417379446", "target": "S-1-5-21-3130019616-2776909439-2417379446-501"}, {"source": "S-1-5-21-3130019616-2776909439-2417379446", "target": "S-1-5-21-3130019616-2776909439-2417379446-502"}, {"source": "S-1-5-21-3130019616-2776909439-2417379446", "target": "S-1-5-21-3130019616-2776909439-2417379446-1105"}, {"source": "S-1-5-21-3130019616-2776909439-2417379446", "target": "S-1-5-21-3130019616-2776909439-2417379446-2106"}, {"source": "S-1-5-21-3130019616-2776909439-2417379446", "target": "S-1-5-21-3130019616-2776909439-2417379446-2107"}}},
"409c1e1ae686d0627d92326f4e478d511d3ac845": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:Domain MERGE (m:Base {objectid: item.target}) ON CREATE SET m:OU MERGE (n)-[r:Contains {isacl: false}]->(m)", list: []map[string]interface{}{{"source": "S-1-5-21-3130019616-2776909439-2417379446", "target": "0DE400CD-2FF3-46E0-8A26-2C917B403C65"}, {"source": "S-1-5-21-3130019616-2776909439-2417379446", "target": "2A374493-816A-4193-BEFD-D2F4132C6DCA"}}},
"77eda3e8c3b4aae73dc76afc5755beeab35eae89": {statement: "UNWIND $list AS item MERGE (n:Base {objectid: item.source}) ON CREATE SET n:GPO MERGE (m:Base {objectid: item.target}) ON CREATE SET m:Domain MERGE (n)-[r:GpLink {isacl: false, enforced: item.enforced}]->(m)", list: []map[string]interface{}{{"enforced": false, "source": "BE91688F-1333-45DF-93E4-4D2E8A36DE2B", "target": "S-1-5-21-3130019616-2776909439-2417379446"}}},
}
got := buildDomainCyphers(data.Domains)
if diff := cmp.Diff(expected, got, cmp.AllowUnexported(cypher{})); diff != "" {
t.Errorf("TestComputer_buildTransactions() mismatch (-want got):\n%s", diff)
}
}