-
Notifications
You must be signed in to change notification settings - Fork 53
added tests for helpers and init common lib #265
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
Conversation
WalkthroughAdds multiple unit tests for helper functions (domain/SID/LDAP-time), new tests for CommonLib initialization and cache behavior, a test collection definition to disable parallelization, and cache-isolation wiring in an existing test class. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧠 Learnings (2)📚 Learning: 2025-07-24T21:38:13.462ZApplied to files:
📚 Learning: 2025-10-17T13:43:46.833ZApplied to files:
🧬 Code graph analysis (2)test/unit/UserRightsAssignmentProcessorTest.cs (2)
test/unit/CommonLibTests.cs (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (7)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
test/unit/CommonLibTests.cs (1)
74-88: Consider adding a test-only reset method to CommonLib.The reflection-based reset is necessary for test isolation but fragile—it depends on private implementation details and will break if the field name or visibility changes. Additionally, setting the cache to null could cause issues in concurrent test scenarios.
Consider adding a conditional compilation directive in the production code:
#if DEBUG || TESTING public static void ResetForTesting() { _initialized = false; Cache.SetCacheInstance(null); } #endifThis would make tests more maintainable while keeping the reset logic out of production builds.
test/unit/CommonLibHelperTests.cs (1)
299-304: Consider adding edge case coverage.The test correctly verifies the basic conversion, but consider adding test cases for edge cases:
- Single component domain (e.g., "local" → "DC=local")
- Multi-level domains (e.g., "sub.test.local" → "DC=sub,DC=test,DC=local")
- Empty or null input (if applicable)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
test/unit/CommonLibHelperTests.cs(2 hunks)test/unit/CommonLibTests.cs(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-26T16:37:09.005Z
Learnt from: definitelynotagoblin
Repo: SpecterOps/SharpHoundCommon PR: 217
File: src/CommonLib/Timeout.cs:21-21
Timestamp: 2025-06-26T16:37:09.005Z
Learning: In SharpHoundCommonLib's Timeout.cs, the team prefers to use TaskScheduler.Current instead of TaskScheduler.Default in Task.Factory.StartNew calls to maintain flexibility for custom schedulers, even though this requires awareness of potential deadlock risks in certain contexts.
Applied to files:
test/unit/CommonLibHelperTests.cs
🧬 Code graph analysis (2)
test/unit/CommonLibHelperTests.cs (1)
src/CommonLib/Helpers.cs (5)
Helpers(17-343)DomainNameToDistinguishedName(158-160)ConvertSidToHexSid(109-116)IsSidFiltered(248-259)ConvertLdapTimeToLong(226-232)
test/unit/CommonLibTests.cs (3)
src/CommonLib/Logging/Logging.cs (2)
Logging(7-20)ILogger(31-34)src/CommonLib/CommonLib.cs (2)
CommonLib(5-46)InitializeCommonLib(15-36)src/CommonLib/Cache.cs (1)
SetCacheInstance(151-155)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (8)
test/unit/CommonLibTests.cs (4)
13-16: LGTM!Constructor properly ensures test isolation by resetting state before each test.
18-32: LGTM!Test correctly verifies that
InitializeCommonLibcreates a new cache instance and populates all expected internal dictionaries when no cache is provided.
34-45: LGTM!Test correctly verifies that the provided cache instance is used (reference equality check with
Assert.Same).
47-72: LGTM!Test correctly verifies that a second initialization attempt logs a warning and does not replace the existing cache. The Moq verification pattern for
ILoggeris appropriate.test/unit/CommonLibHelperTests.cs (4)
2-2: LGTM!Import is necessary for the new
SecurityIdentifierusage in the SID conversion tests.
329-333: LGTM!Test correctly verifies that an invalid SID throws an
ArgumentException.
335-359: LGTM!The parameterized tests for
IsSidFilteredprovide good coverage:
- Case-insensitive matching for well-known SIDs
- Prefix-based filtering (S-1-5-80, S-1-5-82, S-1-5-90, S-1-5-96)
- Cases where filtering should return false
Good use of
[Theory]and[InlineData]for parameterized testing.
361-377: LGTM!The three tests provide complete coverage of
ConvertLdapTimeToLong:
- Null input handling (returns -1)
- Invalid format handling (throws
FormatException)- Valid parsing
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.
Actionable comments posted: 1
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
test/unit/CommonLibTests.cs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/unit/CommonLibTests.cs (3)
src/CommonLib/Logging/Logging.cs (2)
Logging(7-20)ILogger(31-34)src/CommonLib/CommonLib.cs (2)
CommonLib(5-46)InitializeCommonLib(15-36)src/CommonLib/Cache.cs (1)
SetCacheInstance(151-155)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (5)
test/unit/CommonLibTests.cs (5)
18-32: LGTM!The test correctly verifies that the first initialization without a provided cache creates and populates the Cache singleton with all expected dictionaries.
34-45: LGTM!The test correctly verifies that when a cache instance is provided, that exact instance becomes the active cache. Using
Assert.Sameis appropriate for reference equality.
63-71: LGTM!The mock verification correctly validates that the warning is logged when attempting to initialize CommonLib a second time. The use of
It.IsAnyTypepattern is appropriate for verifying structured logging withILogger.
74-88: LGTM!The helper method correctly uses reflection to reset CommonLib's private static state for test isolation. The error handling for the missing field is appropriate, and the cache reset is intentional.
13-16: Consider test isolation with static state.The constructor resets static CommonLib state before each test, which is good for isolation. However, since these tests manipulate shared static fields (_initialized and Cache singleton), parallel execution with other test classes that also test CommonLib could lead to race conditions or test interference.
Run the following script to check if there are other test classes that initialize CommonLib:
#!/bin/bash # Search for other test classes that call InitializeCommonLib rg -n -C3 'InitializeCommonLib' --type=cs -g '!CommonLibTests.cs'If other test classes exist, consider using xUnit's
[Collection]attribute to ensure these tests run sequentially.
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.
Actionable comments posted: 4
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
test/unit/CollectionDefinitions/CacheTestsCollectionDefinition.cs(1 hunks)test/unit/CommonLibTests.cs(1 hunks)test/unit/UserRightsAssignmentProcessorTest.cs(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- test/unit/CommonLibTests.cs
🧰 Additional context used
🧬 Code graph analysis (1)
test/unit/UserRightsAssignmentProcessorTest.cs (4)
src/CommonLib/Cache.cs (1)
SetCacheInstance(151-155)test/unit/Facades/MockLdapUtils.cs (2)
MockLdapUtils(27-30)Group(1099-1104)test/unit/Facades/Consts.cs (1)
Consts(3-8)src/CommonLib/OutputTypes/LocalGroup.cs (1)
LocalGroup(3-8)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (2)
test/unit/UserRightsAssignmentProcessorTest.cs (1)
20-20: Good cache isolation practice.The Collection attribute correctly wires this test class into the non-parallelizable collection, ensuring proper isolation for tests that manipulate the shared cache singleton.
test/unit/CollectionDefinitions/CacheTestsCollectionDefinition.cs (1)
8-9: Correct approach for cache test isolation.The collection definition with
DisableParallelization = trueis the correct approach for tests that manipulate shared cache state. The empty class body is standard for xUnit collection definitions.
Description
Added more UT
Motivation and Context
Increase test coverage
How Has This Been Tested?
Running locally
Types of changes
Checklist:
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.