-
-
Notifications
You must be signed in to change notification settings - Fork 22
test(eventviewerx): ✅ guard known-field string literals in rules #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,13 +1,41 @@ | ||||||
| using System; | ||||||
| using System.Collections.Generic; | ||||||
| using System.IO; | ||||||
| using System.Linq; | ||||||
| using System.Text.RegularExpressions; | ||||||
| using Xunit; | ||||||
|
|
||||||
| namespace EventViewerX.Tests; | ||||||
|
|
||||||
| public class TestRuleSourceGuards | ||||||
| { | ||||||
| private static readonly IReadOnlyList<string> KnownFieldKeys = new[] | ||||||
| { | ||||||
| "SubjectUserName", | ||||||
| "SubjectDomainName", | ||||||
| "SubjectLogonId", | ||||||
| "TargetUserName", | ||||||
| "TargetDomainName", | ||||||
| "TargetSid", | ||||||
| "WorkstationName", | ||||||
| "IpAddress", | ||||||
| "IpPort", | ||||||
| "LogonType", | ||||||
| "Status", | ||||||
| "SubStatus", | ||||||
| "FailureReason", | ||||||
| "AuthenticationPackageName", | ||||||
| "LogonProcessName", | ||||||
| "LmPackageName", | ||||||
| "KeyLength", | ||||||
| "ProcessId", | ||||||
| "ProcessName", | ||||||
| "TransmittedServices", | ||||||
| "TicketOptions", | ||||||
| "TicketEncryptionType", | ||||||
| "PreAuthType" | ||||||
| }; | ||||||
|
Comment on lines
+12
to
+37
|
||||||
|
|
||||||
| [Fact] | ||||||
| public void RuleSources_DoNotUseDirectEventObjectDataIndexer() | ||||||
| { | ||||||
|
|
@@ -34,6 +62,23 @@ public void RuleSources_DoNotUseDirectDataTryGetValueCalls() | |||||
| string.Join(Environment.NewLine, offenders)); | ||||||
| } | ||||||
|
|
||||||
| [Fact] | ||||||
| public void RuleSources_DoNotUseKnownFieldStringLiteralsInAccessors() | ||||||
| { | ||||||
| string knownKeysPattern = string.Join("|", KnownFieldKeys.Select(Regex.Escape)); | ||||||
| Regex knownFieldLiteralPattern = new( | ||||||
| $@"\b(?:GetValueFromDataDictionary|GetDataValueOrEmpty|TryGetDataValue|TryGetDataEnum)\s*\([^)]*""(?:{knownKeysPattern})""", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The pattern Useful? React with 👍 / 👎.
|
||||||
| $@"\b(?:GetValueFromDataDictionary|GetDataValueOrEmpty|TryGetDataValue|TryGetDataEnum)\s*\([^)]*""(?:{knownKeysPattern})""", | |
| $@"""(?:{knownKeysPattern})""", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new guard hard-codes
KnownFieldKeysbut omits existingKnownEventFieldmembers (Message,NoNameA0,NoNameA1, andTextPayloadfromSources/EventViewerX/Definitions/KnownEventField.cs), so string-literal access to those canonical fields is not detected. I verified this gap by searching current rules, which already contain calls likeGetValueFromDataDictionary("NoNameA0")andGetValueFromDataDictionary("#text"); this test still passes despite those known-field literals.Useful? React with 👍 / 👎.