Skip to content

Commit

Permalink
wip: ldap utils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rvazarkar committed Jul 9, 2024
1 parent 8496778 commit 1dcccde
Showing 1 changed file with 0 additions and 130 deletions.
130 changes: 0 additions & 130 deletions test/unit/LDAPUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ public void SanityCheck()
Assert.True(true);
}

#region Private Members

#endregion

#region Creation

/// <summary>
/// </summary>
[Fact]
Expand Down Expand Up @@ -147,136 +141,12 @@ public void DistinguishedNameToDomain_RegularObject_CorrectDomain()
Assert.Equal("TESTLAB.LOCAL", result);
}

[Fact]
public void GetDomainRangeSize_BadDomain_ReturnsDefault()
{
var mock = new Mock<LdapUtils>();
mock.Setup(x => x.GetDomain(It.IsAny<string>())).Returns((Domain)null);
var result = mock.Object.GetDomainRangeSize();
Assert.Equal(750, result);
}

[Fact]
public void GetDomainRangeSize_RespectsDefaultParam()
{
var mock = new Mock<LdapUtils>();
mock.Setup(x => x.GetDomain(It.IsAny<string>())).Returns((Domain)null);

var result = mock.Object.GetDomainRangeSize(null, 1000);
Assert.Equal(1000, result);
}

[WindowsOnlyFact]
public void GetDomainRangeSize_NoLdapEntry_ReturnsDefault()
{
var mock = new Mock<LdapUtils>();
var mockDomain = MockableDomain.Construct("testlab.local");
mock.Setup(x => x.GetDomain(It.IsAny<string>())).Returns(mockDomain);
mock.Setup(x => x.Query(It.IsAny<string>(), It.IsAny<SearchScope>(), It.IsAny<string[]>(),
It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<bool>(),
It.IsAny<bool>(), It.IsAny<bool>())).Returns(new List<ISearchResultEntry>());

var result = mock.Object.GetDomainRangeSize();
Assert.Equal(750, result);
}

[WindowsOnlyFact]
public void GetDomainRangeSize_ExpectedResults()
{
var mock = new Mock<LdapUtils>();
var mockDomain = MockableDomain.Construct("testlab.local");
mock.Setup(x => x.GetDomain(It.IsAny<string>())).Returns(mockDomain);
var searchResult = new MockSearchResultEntry("CN=Default Query Policy,CN=Query-Policies,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=testlab,DC=local", new Dictionary<string, object>
{
{"ldapadminlimits", new[]
{
"MaxPageSize=1250"
}},
}, "abc123", Label.Base);

mock.Setup(x => x.Query(It.IsAny<string>(), It.IsAny<SearchScope>(), null,
It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<bool>(),
It.IsAny<bool>(), It.IsAny<bool>())).Returns(new List<ISearchResultEntry> { searchResult });
var result = mock.Object.GetDomainRangeSize();
Assert.Equal(1250, result);
}

[Fact]
public void DistinguishedNameToDomain_DeletedObjects_CorrectDomain()
{
var result = SharpHoundCommonLib.Helpers.DistinguishedNameToDomain(
@"DC=..Deleted-_msdcs.testlab.local\0ADEL:af1f072f-28d7-4b86-9b87-a408bfc9cb0d,CN=Deleted Objects,DC=testlab,DC=local");
Assert.Equal("TESTLAB.LOCAL", result);
}

[Fact]
public void QueryLDAP_With_Exception()
{
var options = new LDAPQueryOptions
{
ThrowException = true
};

Assert.Throws<LDAPQueryException>(
async () =>
{
await foreach (var sre in _utils.Query(null, new SearchScope(), null, new CancellationToken(), null,
false, false, null, false, false, true))
{
// We shouldn't reach this anyway, and all we care about is if exceptions are bubbling
}
});

Assert.Throws<LDAPQueryException>(
async () =>
{
await foreach (var sre in _utils.Query(options))
{
// We shouldn't reach this anyway, and all we care about is if exceptions are bubbling
}
});
}

[Fact]
public void QueryLDAP_Without_Exception()
{
Exception exception;

var options = new LDAPQueryOptions
{
ThrowException = false
};

exception = Record.Exception(
async () =>
{
await foreach (var sre in _utils.Query(null, new SearchScope(), null, new CancellationToken()))
{
// We shouldn't reach this anyway, and all we care about is if exceptions are bubbling
}
});
Assert.Null(exception);

exception = Record.Exception(
async () =>
{
await foreach (var sre in _utils.Query(options))
{
// We shouldn't reach this anyway, and all we care about is if exceptions are bubbling
}
});
Assert.Null(exception);
}

#endregion

#region Structural

#endregion


#region Behavioral

#endregion
}
}

0 comments on commit 1dcccde

Please sign in to comment.