Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions generator/wel/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (e *EventRecord) ToXML() string {

// RenderingInfo
if e.Message != "" || e.LevelName != "" || e.TaskName != "" {
b.WriteString(" <RenderingInfo>\n")
b.WriteString(" <RenderingInfo Culture=\"en-US\">\n")
if e.Message != "" {
fmt.Fprintf(&b, " <Message>%s</Message>\n", xmlEscape(e.Message))
}
Expand All @@ -91,8 +91,12 @@ func (e *EventRecord) ToXML() string {
if e.OpcodeName != "" {
fmt.Fprintf(&b, " <Opcode>%s</Opcode>\n", xmlEscape(e.OpcodeName))
}
for _, kw := range e.KeywordNames {
fmt.Fprintf(&b, " <Keyword>%s</Keyword>\n", xmlEscape(kw))
if len(e.KeywordNames) > 0 {
b.WriteString(" <Keywords>\n")
for _, kw := range e.KeywordNames {
fmt.Fprintf(&b, " <Keyword>%s</Keyword>\n", xmlEscape(kw))
}
b.WriteString(" </Keywords>\n")
}
b.WriteString(" </RenderingInfo>\n")
}
Expand Down
55 changes: 54 additions & 1 deletion generator/wel/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestEventRecordToXML(t *testing.T) {
`<Data Name="SubjectUserSid">S-1-5-18</Data>`,
`<Data Name="TargetUserName">jsmith</Data>`,
`<Data Name="LogonType">3</Data>`,
`<RenderingInfo>`,
`<RenderingInfo Culture="en-US">`,
`<Message>An account was successfully logged on.</Message>`,
`<Level>Information</Level>`,
`<Task>Logon</Task>`,
Expand All @@ -69,6 +69,59 @@ func TestEventRecordToXML(t *testing.T) {
}
}

func TestEventRecordToXMLRenderingInfoKeywordsWrapper(t *testing.T) {
rec := &EventRecord{
ProviderName: "Microsoft-Windows-Security-Auditing",
EventID: 4624,
Channel: "Security",
Computer: "WIN-SERVER01.contoso.com",
Keywords: 0x8020000000000000,
KeywordNames: []string{"Audit Success"},
Message: "An account was successfully logged on.",
LevelName: "Information",
TimeCreated: time.Date(2024, 3, 15, 10, 30, 0, 0, time.UTC),
EventRecordID: 12345,
}

xml := rec.ToXML()

// Per the WEL schema, <Keyword> elements inside <RenderingInfo> must be
// wrapped in a <Keywords> container. This is distinct from the System-level
// <Keywords>0x...</Keywords> hex bitmask.
wantBlock := " <Keywords>\n <Keyword>Audit Success</Keyword>\n </Keywords>\n"
if !strings.Contains(xml, wantBlock) {
t.Errorf("RenderingInfo keywords not wrapped in <Keywords> container.\nwant block:\n%s\nfull XML:\n%s", wantBlock, xml)
}

// A bare <Keyword> directly under <RenderingInfo> (4-space indent, no wrapper)
// is the non-conformant form and must not appear.
if strings.Contains(xml, " <RenderingInfo>\n <Keyword>") {
t.Errorf("found bare <Keyword> directly under <RenderingInfo> (missing <Keywords> wrapper)\n\nfull XML:\n%s", xml)
}
}

func TestEventRecordToXMLRenderingInfoCulture(t *testing.T) {
rec := &EventRecord{
ProviderName: "Microsoft-Windows-Security-Auditing",
EventID: 4624,
Channel: "Security",
Computer: "WIN-SERVER01.contoso.com",
KeywordNames: []string{"Audit Success"},
Message: "An account was successfully logged on.",
LevelName: "Information",
TimeCreated: time.Date(2024, 3, 15, 10, 30, 0, 0, time.UTC),
EventRecordID: 12345,
}

xml := rec.ToXML()

// Per the WEL schema, the RenderingInfo element carries a required Culture
// attribute, and real (WEC-forwarded, rendered-text) events always include it.
if !strings.Contains(xml, `<RenderingInfo Culture="en-US">`) {
t.Errorf("RenderingInfo missing required Culture attribute.\n\nfull XML:\n%s", xml)
}
}

func TestEventRecordToXMLNoGUID(t *testing.T) {
rec := &EventRecord{
ProviderName: "Service Control Manager",
Expand Down
Loading