From 1dcccde21781cca090f8748c1a844ca742369bf3 Mon Sep 17 00:00:00 2001 From: rvazarkar Date: Tue, 9 Jul 2024 16:41:25 -0400 Subject: [PATCH] wip: ldap utils tests --- test/unit/LDAPUtilsTest.cs | 130 ------------------------------------- 1 file changed, 130 deletions(-) diff --git a/test/unit/LDAPUtilsTest.cs b/test/unit/LDAPUtilsTest.cs index 78b95a33..e6889d57 100644 --- a/test/unit/LDAPUtilsTest.cs +++ b/test/unit/LDAPUtilsTest.cs @@ -49,12 +49,6 @@ public void SanityCheck() Assert.True(true); } - #region Private Members - - #endregion - - #region Creation - /// /// [Fact] @@ -147,60 +141,6 @@ public void DistinguishedNameToDomain_RegularObject_CorrectDomain() Assert.Equal("TESTLAB.LOCAL", result); } - [Fact] - public void GetDomainRangeSize_BadDomain_ReturnsDefault() - { - var mock = new Mock(); - mock.Setup(x => x.GetDomain(It.IsAny())).Returns((Domain)null); - var result = mock.Object.GetDomainRangeSize(); - Assert.Equal(750, result); - } - - [Fact] - public void GetDomainRangeSize_RespectsDefaultParam() - { - var mock = new Mock(); - mock.Setup(x => x.GetDomain(It.IsAny())).Returns((Domain)null); - - var result = mock.Object.GetDomainRangeSize(null, 1000); - Assert.Equal(1000, result); - } - - [WindowsOnlyFact] - public void GetDomainRangeSize_NoLdapEntry_ReturnsDefault() - { - var mock = new Mock(); - var mockDomain = MockableDomain.Construct("testlab.local"); - mock.Setup(x => x.GetDomain(It.IsAny())).Returns(mockDomain); - mock.Setup(x => x.Query(It.IsAny(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny())).Returns(new List()); - - var result = mock.Object.GetDomainRangeSize(); - Assert.Equal(750, result); - } - - [WindowsOnlyFact] - public void GetDomainRangeSize_ExpectedResults() - { - var mock = new Mock(); - var mockDomain = MockableDomain.Construct("testlab.local"); - mock.Setup(x => x.GetDomain(It.IsAny())).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 - { - {"ldapadminlimits", new[] - { - "MaxPageSize=1250" - }}, - }, "abc123", Label.Base); - - mock.Setup(x => x.Query(It.IsAny(), It.IsAny(), null, - It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny())).Returns(new List { searchResult }); - var result = mock.Object.GetDomainRangeSize(); - Assert.Equal(1250, result); - } - [Fact] public void DistinguishedNameToDomain_DeletedObjects_CorrectDomain() { @@ -208,75 +148,5 @@ public void DistinguishedNameToDomain_DeletedObjects_CorrectDomain() @"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( - 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( - 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 } } \ No newline at end of file