test(eventviewerx): ✅ enforce subject/target helper usage#243
test(eventviewerx): ✅ enforce subject/target helper usage#243PrzemyslawKlys merged 1 commit intomasterfrom
Conversation
|
Claude finished @PrzemyslawKlys's task —— View job Code Review AnalysisTodo List:
Code Review FeedbackOverall Assessment ✅This PR adds an excellent architectural guard test that enforces the use of helper methods for Subject/Target account field pairs. The implementation is well-thought-out and follows established patterns in the codebase. 🟢 Code Quality & Best PracticesExcellent implementation with strong adherence to best practices:
🟢 Performance ConsiderationsWell-optimized implementation:
🟢 Security & MaintainabilityNo security concerns identified:
🟢 Test Coverage EnhancementSignificantly improves architectural enforcement:
💡 Minor Suggestions for Improvement
🔍 Technical AnalysisRegex Pattern Breakdown:
Integration Quality: ✅ Final VerdictThis is an exemplary addition to the test suite that:
The implementation demonstrates thoughtful API design enforcement and will help maintain code quality as the project evolves. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 45ffa230fa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| public void RuleSources_DoNotUseDirectSubjectTargetKnownFieldPairCalls() | ||
| { | ||
| Regex directSubjectTargetPairPattern = new( | ||
| @"\bGetValueFromDataDictionary\s*\(\s*KnownEventField\.SubjectUserName\s*,\s*KnownEventField\.SubjectDomainName|\bGetValueFromDataDictionary\s*\(\s*KnownEventField\.TargetUserName\s*,\s*KnownEventField\.TargetDomainName", |
There was a problem hiding this comment.
Match subject/target pair calls across line breaks
This guard only matches GetValueFromDataDictionary(KnownEventField..., KnownEventField...) when both enum arguments are on the same physical line, but FindRuleSourceOffenders checks each line independently, so a multiline invocation (a common style in this repo) will bypass the test entirely. That means the new test can report green while forbidden direct subject/target pair access still exists, weakening the policy it is meant to enforce.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
Adds a new test guard in the EventViewerX test suite to enforce that rule sources use the dedicated subject/target account helpers instead of manually combining Subject/Target known-field pairs.
Changes:
- Introduces a new xUnit
[Fact]that scans rule source files for directGetValueFromDataDictionary(KnownEventField.Subject*/Target*)pair usage. - Provides a clearer failure message directing contributors to
GetSubjectAccountOrEmpty()/GetTargetAccountOrEmpty().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public void RuleSources_DoNotUseDirectSubjectTargetKnownFieldPairCalls() | ||
| { | ||
| Regex directSubjectTargetPairPattern = new( | ||
| @"\bGetValueFromDataDictionary\s*\(\s*KnownEventField\.SubjectUserName\s*,\s*KnownEventField\.SubjectDomainName|\bGetValueFromDataDictionary\s*\(\s*KnownEventField\.TargetUserName\s*,\s*KnownEventField\.TargetDomainName", |
There was a problem hiding this comment.
The regex only matches GetValueFromDataDictionary(KnownEventField.SubjectUserName, KnownEventField.SubjectDomainName (and the Target equivalent) when both arguments are on the same line and in that specific order. Since FindRuleSourceOffenders tests one line at a time, a forbidden call split across multiple lines (or with the two KnownEventField arguments swapped + reverseOrder adjusted) would not be detected. Consider expanding the pattern to match both argument orders and/or changing the offender scan to run the regex over the full file text so multi-line invocations are caught.
| @"\bGetValueFromDataDictionary\s*\(\s*KnownEventField\.SubjectUserName\s*,\s*KnownEventField\.SubjectDomainName|\bGetValueFromDataDictionary\s*\(\s*KnownEventField\.TargetUserName\s*,\s*KnownEventField\.TargetDomainName", | |
| @"\bGetValueFromDataDictionary\s*\(\s*KnownEventField\.(?:SubjectUserName\s*,\s*KnownEventField\.SubjectDomainName|SubjectDomainName\s*,\s*KnownEventField\.SubjectUserName|TargetUserName\s*,\s*KnownEventField\.TargetDomainName|TargetDomainName\s*,\s*KnownEventField\.TargetUserName)", |
No description provided.