-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test coverage for LdapConnectionPool excluded domains; fix previe…
…w feature use on LdapUtils
- Loading branch information
1 parent
990136a
commit 423dad7
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using SharpHoundCommonLib; | ||
using Xunit; | ||
|
||
public class LdapConnectionPoolTest | ||
{ | ||
private static void AddExclusionDomain(string identifier) { | ||
var excludedDomainsField = typeof(LdapConnectionPool) | ||
.GetField("_excludedDomains", BindingFlags.Static | BindingFlags.NonPublic); | ||
|
||
var excludedDomains = (ConcurrentHashSet)excludedDomainsField.GetValue(null); | ||
|
||
excludedDomains.Add(identifier); | ||
} | ||
|
||
[Fact] | ||
public async Task LdapConnectionPool_ExcludedDomains_ShouldExitEarly() | ||
{ | ||
var mockLogger = new Mock<ILogger>(); | ||
var ldapConfig = new LdapConfig(); | ||
var connectionPool = new ConnectionPoolManager(ldapConfig, mockLogger.Object); | ||
|
||
AddExclusionDomain("excludedDomain.com"); | ||
var connectAttempt = await connectionPool.TestDomainConnection("excludedDomain.com", false); | ||
|
||
Assert.False(connectAttempt.Success); | ||
Assert.Contains("excluded for connection attempt", connectAttempt.Message); | ||
} | ||
|
||
[Fact] | ||
public async Task LdapConnectionPool_ExcludedDomains_NonExcludedShouldntExit() | ||
{ | ||
var mockLogger = new Mock<ILogger>(); | ||
var ldapConfig = new LdapConfig(); | ||
var connectionPool = new ConnectionPoolManager(ldapConfig, mockLogger.Object); | ||
|
||
AddExclusionDomain("excludedDomain.com"); | ||
var connectAttempt = await connectionPool.TestDomainConnection("perfectlyValidDomain.com", false); | ||
|
||
Assert.DoesNotContain("excluded for connection attempt", connectAttempt.Message); | ||
} | ||
} |