@@ -116,6 +116,162 @@ func TestParseBody(t *testing.T) {
116
116
require .Equal (t , expected , xml .parseBody ())
117
117
}
118
118
119
+ func TestParseBodySecurityExecution (t * testing.T ) {
120
+ xml := EventXML {
121
+ EventID : EventID {
122
+ ID : 1 ,
123
+ Qualifiers : 2 ,
124
+ },
125
+ Provider : Provider {
126
+ Name : "provider" ,
127
+ GUID : "guid" ,
128
+ EventSourceName : "event source" ,
129
+ },
130
+ TimeCreated : TimeCreated {
131
+ SystemTime : "2020-07-30T01:01:01.123456789Z" ,
132
+ },
133
+ Computer : "computer" ,
134
+ Channel : "application" ,
135
+ RecordID : 1 ,
136
+ Level : "Information" ,
137
+ Message : "message" ,
138
+ Task : "task" ,
139
+ Opcode : "opcode" ,
140
+ Keywords : []string {"keyword" },
141
+ EventData : []EventDataEntry {
142
+ {Name : "name" , Value : "value" }, {Name : "another_name" , Value : "another_value" },
143
+ },
144
+ Execution : & Execution {
145
+ ProcessID : 13 ,
146
+ ThreadID : 102 ,
147
+ },
148
+ Security : & Security {
149
+ UserID : "my-user-id" ,
150
+ },
151
+ RenderedLevel : "rendered_level" ,
152
+ RenderedTask : "rendered_task" ,
153
+ RenderedOpcode : "rendered_opcode" ,
154
+ RenderedKeywords : []string {"RenderedKeywords" },
155
+ }
156
+
157
+ expected := map [string ]interface {}{
158
+ "event_id" : map [string ]interface {}{
159
+ "id" : uint32 (1 ),
160
+ "qualifiers" : uint16 (2 ),
161
+ },
162
+ "provider" : map [string ]interface {}{
163
+ "name" : "provider" ,
164
+ "guid" : "guid" ,
165
+ "event_source" : "event source" ,
166
+ },
167
+ "system_time" : "2020-07-30T01:01:01.123456789Z" ,
168
+ "computer" : "computer" ,
169
+ "channel" : "application" ,
170
+ "record_id" : uint64 (1 ),
171
+ "level" : "rendered_level" ,
172
+ "message" : "message" ,
173
+ "task" : "rendered_task" ,
174
+ "opcode" : "rendered_opcode" ,
175
+ "keywords" : []string {"RenderedKeywords" },
176
+ "execution" : map [string ]any {
177
+ "process_id" : uint (13 ),
178
+ "thread_id" : uint (102 ),
179
+ },
180
+ "security" : map [string ]any {
181
+ "user_id" : "my-user-id" ,
182
+ },
183
+ "event_data" : map [string ]interface {}{"name" : "value" , "another_name" : "another_value" },
184
+ }
185
+
186
+ require .Equal (t , expected , xml .parseBody ())
187
+ }
188
+
189
+ func TestParseBodyFullExecution (t * testing.T ) {
190
+ processorID := uint (3 )
191
+ sessionID := uint (2 )
192
+ kernelTime := uint (3 )
193
+ userTime := uint (100 )
194
+ processorTime := uint (200 )
195
+
196
+ xml := EventXML {
197
+ EventID : EventID {
198
+ ID : 1 ,
199
+ Qualifiers : 2 ,
200
+ },
201
+ Provider : Provider {
202
+ Name : "provider" ,
203
+ GUID : "guid" ,
204
+ EventSourceName : "event source" ,
205
+ },
206
+ TimeCreated : TimeCreated {
207
+ SystemTime : "2020-07-30T01:01:01.123456789Z" ,
208
+ },
209
+ Computer : "computer" ,
210
+ Channel : "application" ,
211
+ RecordID : 1 ,
212
+ Level : "Information" ,
213
+ Message : "message" ,
214
+ Task : "task" ,
215
+ Opcode : "opcode" ,
216
+ Keywords : []string {"keyword" },
217
+ EventData : []EventDataEntry {
218
+ {Name : "name" , Value : "value" }, {Name : "another_name" , Value : "another_value" },
219
+ },
220
+ Execution : & Execution {
221
+ ProcessID : 13 ,
222
+ ThreadID : 102 ,
223
+ ProcessorID : & processorID ,
224
+ SessionID : & sessionID ,
225
+ KernelTime : & kernelTime ,
226
+ UserTime : & userTime ,
227
+ ProcessorTime : & processorTime ,
228
+ },
229
+ Security : & Security {
230
+ UserID : "my-user-id" ,
231
+ },
232
+ RenderedLevel : "rendered_level" ,
233
+ RenderedTask : "rendered_task" ,
234
+ RenderedOpcode : "rendered_opcode" ,
235
+ RenderedKeywords : []string {"RenderedKeywords" },
236
+ }
237
+
238
+ expected := map [string ]interface {}{
239
+ "event_id" : map [string ]interface {}{
240
+ "id" : uint32 (1 ),
241
+ "qualifiers" : uint16 (2 ),
242
+ },
243
+ "provider" : map [string ]interface {}{
244
+ "name" : "provider" ,
245
+ "guid" : "guid" ,
246
+ "event_source" : "event source" ,
247
+ },
248
+ "system_time" : "2020-07-30T01:01:01.123456789Z" ,
249
+ "computer" : "computer" ,
250
+ "channel" : "application" ,
251
+ "record_id" : uint64 (1 ),
252
+ "level" : "rendered_level" ,
253
+ "message" : "message" ,
254
+ "task" : "rendered_task" ,
255
+ "opcode" : "rendered_opcode" ,
256
+ "keywords" : []string {"RenderedKeywords" },
257
+ "execution" : map [string ]any {
258
+ "process_id" : uint (13 ),
259
+ "thread_id" : uint (102 ),
260
+ "processor_id" : processorID ,
261
+ "session_id" : sessionID ,
262
+ "kernel_time" : kernelTime ,
263
+ "user_time" : userTime ,
264
+ "processor_time" : processorTime ,
265
+ },
266
+ "security" : map [string ]any {
267
+ "user_id" : "my-user-id" ,
268
+ },
269
+ "event_data" : map [string ]interface {}{"name" : "value" , "another_name" : "another_value" },
270
+ }
271
+
272
+ require .Equal (t , expected , xml .parseBody ())
273
+ }
274
+
119
275
func TestParseNoRendered (t * testing.T ) {
120
276
xml := EventXML {
121
277
EventID : EventID {
@@ -252,7 +408,7 @@ func TestInvalidUnmarshal(t *testing.T) {
252
408
require .Error (t , err )
253
409
254
410
}
255
- func TestUnmarshal (t * testing.T ) {
411
+ func TestUnmarshalWithEventData (t * testing.T ) {
256
412
data , err := os .ReadFile (filepath .Join ("testdata" , "xmlSample.xml" ))
257
413
require .NoError (t , err )
258
414
@@ -283,7 +439,47 @@ func TestUnmarshal(t *testing.T) {
283
439
{Name : "Time" , Value : "2022-04-28T19:48:52Z" },
284
440
{Name : "Source" , Value : "RulesEngine" },
285
441
},
286
- Keywords : []string {"0x80000000000000" },
442
+ Keywords : []string {"0x80000000000000" },
443
+ Security : & Security {},
444
+ Execution : & Execution {},
445
+ }
446
+
447
+ require .Equal (t , xml , event )
448
+ }
449
+
450
+ func TestUnmarshalWithUserData (t * testing.T ) {
451
+ data , err := os .ReadFile (filepath .Join ("testdata" , "xmlSampleUserData.xml" ))
452
+ require .NoError (t , err )
453
+
454
+ event , err := unmarshalEventXML (data )
455
+ require .NoError (t , err )
456
+
457
+ xml := EventXML {
458
+ EventID : EventID {
459
+ ID : 1102 ,
460
+ },
461
+ Provider : Provider {
462
+ Name : "Microsoft-Windows-Eventlog" ,
463
+ GUID : "{fc65ddd8-d6ef-4962-83d5-6e5cfe9ce148}" ,
464
+ },
465
+ TimeCreated : TimeCreated {
466
+ SystemTime : "2023-10-12T10:38:24.543506200Z" ,
467
+ },
468
+ Computer : "test.example.com" ,
469
+ Channel : "Security" ,
470
+ RecordID : 2590526 ,
471
+ Level : "4" ,
472
+ Message : "" ,
473
+ Task : "104" ,
474
+ Opcode : "0" ,
475
+ Keywords : []string {"0x4020000000000000" },
476
+ Security : & Security {
477
+ UserID : "S-1-5-18" ,
478
+ },
479
+ Execution : & Execution {
480
+ ProcessID : 1472 ,
481
+ ThreadID : 7784 ,
482
+ },
287
483
}
288
484
289
485
require .Equal (t , xml , event )
0 commit comments