11using System ;
22using System . Collections . Generic ;
33using System . Diagnostics . CodeAnalysis ;
4+ using System . Runtime . CompilerServices ;
45using System . Threading . Tasks ;
56using Moq ;
67using SharpHoundCommonLib ;
@@ -21,19 +22,70 @@ public DCLdapProcessorTest(ITestOutputHelper testOutputHelper) {
2122
2223 public void Dispose ( ) {
2324 }
25+
26+ [ Fact ]
27+ public async Task DCLdapProcessor_Scan ( ) {
28+ var mockProcessor = new Mock < DCLdapProcessor > ( It . IsAny < int > ( ) , "primary.testlab.local" , null ) ;
29+
30+ mockProcessor . Setup ( x => x . Authenticate ( It . IsAny < Uri > ( ) , It . IsAny < LdapAuthOptions > ( ) ) ) . ReturnsAsync ( false ) ;
31+
32+ mockProcessor . Setup ( x => x . TestLdapPort ( ) ) . ReturnsAsync ( true ) ;
33+ mockProcessor . Setup ( x => x . TestLdapsPort ( ) ) . ReturnsAsync ( true ) ;
34+
35+ var processor = mockProcessor . Object ;
36+ var receivedStatus = new List < CSVComputerStatus > ( ) ;
37+ processor . ComputerStatusEvent += async status => {
38+ receivedStatus . Add ( status ) ;
39+ } ;
40+ var results = await processor . Scan ( "primary.testlab.local" , TimeSpan . FromMinutes ( 2 ) ) ;
41+
42+ Assert . Equal ( 2 , receivedStatus . Count ) ;
43+ var status = receivedStatus [ 0 ] ;
44+ Assert . Equal ( CSVComputerStatus . StatusSuccess , status . Status ) ;
45+ status = receivedStatus [ 1 ] ;
46+ Assert . Equal ( CSVComputerStatus . StatusSuccess , status . Status ) ;
47+ Assert . True ( results . HasLdap ) ;
48+ Assert . True ( results . HasLdaps ) ;
49+ Assert . True ( results . IsSigningRequired . Result ) ;
50+ Assert . False ( results . IsChannelBindingDisabled . Result ) ;
51+ }
52+
53+ [ Fact ]
54+ public async Task DCLdapProcessor_Scan_Failed ( ) {
55+ var mockProcessor = new Mock < DCLdapProcessor > ( It . IsAny < int > ( ) , "primary.testlab.local" , null ) ;
56+
57+ mockProcessor . Setup ( x => x . Authenticate ( It . IsAny < Uri > ( ) , It . IsAny < LdapAuthOptions > ( ) ) ) . Throws ( new Exception ( "Error" ) ) ;
58+
59+ mockProcessor . Setup ( x => x . TestLdapPort ( ) ) . ReturnsAsync ( true ) ;
60+ mockProcessor . Setup ( x => x . TestLdapsPort ( ) ) . ReturnsAsync ( true ) ;
61+
62+ var processor = mockProcessor . Object ;
63+ var receivedStatus = new List < CSVComputerStatus > ( ) ;
64+ processor . ComputerStatusEvent += async status => {
65+ receivedStatus . Add ( status ) ;
66+ } ;
67+ var results = await processor . Scan ( "primary.testlab.local" , TimeSpan . FromMinutes ( 2 ) ) ;
68+
69+ Assert . Equal ( 2 , receivedStatus . Count ) ;
70+ var status = receivedStatus [ 0 ] ;
71+ Assert . Contains ( "CheckIsNtlmSigningRequired failed: System.Exception: Error" , status . Status ) ;
72+ status = receivedStatus [ 1 ] ;
73+ Assert . Contains ( "CheckIsNtlmSigningRequired failed: System.Exception: Error" , status . Status ) ;
74+ Assert . True ( results . HasLdap ) ;
75+ Assert . True ( results . HasLdaps ) ;
76+ Assert . False ( results . IsSigningRequired . Result ) ;
77+ Assert . False ( results . IsChannelBindingDisabled . Result ) ;
78+ Assert . False ( results . IsSigningRequired . Collected ) ;
79+ Assert . False ( results . IsChannelBindingDisabled . Collected ) ;
80+ }
2481
2582 [ Fact ]
2683 public async Task DCLdapProcessor_CheckScan_Timeout ( ) {
2784 var mockProcessor = new Mock < DCLdapProcessor > ( 2 , "primary.testlab.local" , null ) ;
2885
29- mockProcessor . Setup ( x => x . CheckIsNtlmSigningRequired ( ) ) . ReturnsAsync ( ( ) => {
86+ mockProcessor . Setup ( x => x . Authenticate ( It . IsAny < Uri > ( ) , It . IsAny < LdapAuthOptions > ( ) ) ) . ReturnsAsync ( ( ) => {
3087 Task . Delay ( 100 ) . Wait ( ) ;
31- return NtStatus . StatusAccessDenied ;
32- } ) ;
33-
34- mockProcessor . Setup ( x => x . CheckIsChannelBindingDisabled ( ) ) . ReturnsAsync ( ( ) => {
35- Task . Delay ( 100 ) . Wait ( ) ;
36- return NtStatus . StatusAccessDenied ;
88+ return false ;
3789 } ) ;
3890
3991 mockProcessor . Setup ( x => x . TestLdapPort ( ) ) . ReturnsAsync ( true ) ;
@@ -51,7 +103,30 @@ public async Task DCLdapProcessor_CheckScan_Timeout() {
51103 Assert . Equal ( "Timeout" , status . Status ) ;
52104 status = receivedStatus [ 1 ] ;
53105 Assert . Equal ( "Timeout" , status . Status ) ;
106+ Assert . Equal ( "Timeout" , results . IsSigningRequired . FailureReason ) ;
107+ Assert . Equal ( "Timeout" , results . IsChannelBindingDisabled . FailureReason ) ;
108+ }
109+
110+ [ Fact ]
111+ public async Task DCLdapProcessor_CheckIsNtlmSigningRequired ( )
112+ {
113+ var mockProcessor = new Mock < DCLdapProcessor > ( It . IsAny < int > ( ) , "primary.testlab.local" , null ) ;
114+ mockProcessor . Setup ( x => x . Authenticate ( It . IsAny < Uri > ( ) , It . IsAny < LdapAuthOptions > ( ) ) ) . ReturnsAsync ( false ) ;
115+ var processor = mockProcessor . Object ;
116+ var result = await processor . CheckIsNtlmSigningRequired ( ) ;
117+ Assert . True ( result . IsSuccess ) ;
118+ Assert . True ( result . Value ) ;
119+ }
120+
121+ [ Fact ]
122+ public async Task DCLdapProcessor_CheckIsNtlmSigningRequired_Exception ( )
123+ {
124+ var mockProcessor = new Mock < DCLdapProcessor > ( It . IsAny < int > ( ) , "primary.testlab.local" , null ) ;
125+ mockProcessor . Setup ( x => x . Authenticate ( It . IsAny < Uri > ( ) , It . IsAny < LdapAuthOptions > ( ) ) ) . Throws ( new Exception ( "Error" ) ) ;
126+ var processor = mockProcessor . Object ;
127+ var result = await processor . CheckIsNtlmSigningRequired ( ) ;
128+ Assert . True ( result . IsFailed ) ;
129+ Assert . Contains ( "CheckIsNtlmSigningRequired failed: System.Exception: Error" , result . Error ) ;
54130 }
55-
56131 }
57132}
0 commit comments