@@ -14,12 +14,12 @@ namespace System.DirectoryServices.Protocols.Tests
1414{
1515 public partial class DirectoryServicesProtocolsTests
1616 {
17- internal static bool IsLdapConfigurationExist => LdapConfiguration . Configuration != null ;
18- internal static bool IsActiveDirectoryServer => IsLdapConfigurationExist && LdapConfiguration . Configuration . IsActiveDirectoryServer ;
17+ internal static bool LdapConfigurationExists => LdapConfiguration . Configuration != null ;
18+ internal static bool IsActiveDirectoryServer => LdapConfigurationExists && LdapConfiguration . Configuration . IsActiveDirectoryServer ;
1919
20- internal static bool IsServerSideSortSupported => IsLdapConfigurationExist && LdapConfiguration . Configuration . SupportsServerSideSort ;
20+ internal static bool IsServerSideSortSupported => LdapConfigurationExists && LdapConfiguration . Configuration . SupportsServerSideSort ;
2121
22- [ ConditionalFact ( nameof ( IsLdapConfigurationExist ) ) ]
22+ [ ConditionalFact ( nameof ( LdapConfigurationExists ) ) ]
2323 public void TestInvalidFilter ( )
2424 {
2525 using LdapConnection connection = GetConnection ( ) ;
@@ -33,7 +33,7 @@ public void TestInvalidFilter()
3333 Assert . Equal ( /* LdapError.FilterError */ 0x57 , ex . ErrorCode ) ;
3434 }
3535
36- [ ConditionalFact ( nameof ( IsLdapConfigurationExist ) ) ]
36+ [ ConditionalFact ( nameof ( LdapConfigurationExists ) ) ]
3737 public void TestInvalidSearchDn ( )
3838 {
3939 using LdapConnection connection = GetConnection ( ) ;
@@ -47,7 +47,7 @@ public void TestInvalidSearchDn()
4747 Assert . Equal ( ResultCode . InvalidDNSyntax , ex . Response . ResultCode ) ;
4848 }
4949
50- [ ConditionalFact ( nameof ( IsLdapConfigurationExist ) ) ]
50+ [ ConditionalFact ( nameof ( LdapConfigurationExists ) ) ]
5151 public void TestUnavailableCriticalExtension ( )
5252 {
5353 using LdapConnection connection = GetConnection ( ) ;
@@ -63,7 +63,7 @@ public void TestUnavailableCriticalExtension()
6363 Assert . Equal ( ResultCode . UnavailableCriticalExtension , ex . Response . ResultCode ) ;
6464 }
6565
66- [ ConditionalFact ( nameof ( IsLdapConfigurationExist ) ) ]
66+ [ ConditionalFact ( nameof ( LdapConfigurationExists ) ) ]
6767 public void TestUnavailableNonCriticalExtension ( )
6868 {
6969 using LdapConnection connection = GetConnection ( ) ;
@@ -74,10 +74,22 @@ public void TestUnavailableNonCriticalExtension()
7474 _ = ( SearchResponse ) connection . SendRequest ( searchRequest ) ;
7575 // Does not throw
7676 }
77+
78+ [ ConditionalFact ( nameof ( LdapConfigurationExists ) ) ]
79+ public void TestServerWithPortNumber ( )
80+ {
81+ using LdapConnection connection = GetConnection ( $ "{ LdapConfiguration . Configuration . ServerName } :{ LdapConfiguration . Configuration . Port } ") ;
82+
83+ var searchRequest = new SearchRequest ( LdapConfiguration . Configuration . SearchDn , "(objectClass=*)" , SearchScope . Subtree ) ;
84+
85+ _ = ( SearchResponse ) connection . SendRequest ( searchRequest ) ;
86+ // Shall succeed
87+ }
88+
7789 [ InlineData ( 60 ) ]
7890 [ InlineData ( 0 ) ]
7991 [ InlineData ( - 60 ) ]
80- [ ConditionalTheory ( nameof ( IsLdapConfigurationExist ) ) ]
92+ [ ConditionalTheory ( nameof ( LdapConfigurationExists ) ) ]
8193 public void TestSearchWithTimeLimit ( int timeLimit )
8294 {
8395 using LdapConnection connection = GetConnection ( ) ;
@@ -95,7 +107,7 @@ public void TestSearchWithTimeLimit(int timeLimit)
95107 }
96108 }
97109
98- [ ConditionalFact ( nameof ( IsLdapConfigurationExist ) ) ]
110+ [ ConditionalFact ( nameof ( LdapConfigurationExists ) ) ]
99111 public void TestAddingOU ( )
100112 {
101113 using ( LdapConnection connection = GetConnection ( ) )
@@ -117,7 +129,7 @@ public void TestAddingOU()
117129 }
118130 }
119131
120- [ ConditionalFact ( nameof ( IsLdapConfigurationExist ) ) ]
132+ [ ConditionalFact ( nameof ( LdapConfigurationExists ) ) ]
121133 public void TestDeleteOU ( )
122134 {
123135 using ( LdapConnection connection = GetConnection ( ) )
@@ -142,7 +154,7 @@ public void TestDeleteOU()
142154 }
143155 }
144156
145- [ ConditionalFact ( nameof ( IsLdapConfigurationExist ) ) ]
157+ [ ConditionalFact ( nameof ( LdapConfigurationExists ) ) ]
146158 public void TestAddAndModifyAttribute ( )
147159 {
148160 using ( LdapConnection connection = GetConnection ( ) )
@@ -177,7 +189,7 @@ public void TestAddAndModifyAttribute()
177189 }
178190 }
179191
180- [ ConditionalFact ( nameof ( IsLdapConfigurationExist ) ) ]
192+ [ ConditionalFact ( nameof ( LdapConfigurationExists ) ) ]
181193 public void TestNestedOUs ( )
182194 {
183195 using ( LdapConnection connection = GetConnection ( ) )
@@ -208,7 +220,7 @@ public void TestNestedOUs()
208220 }
209221 }
210222
211- [ ConditionalFact ( nameof ( IsLdapConfigurationExist ) ) ]
223+ [ ConditionalFact ( nameof ( LdapConfigurationExists ) ) ]
212224 public void TestAddUser ( )
213225 {
214226 using ( LdapConnection connection = GetConnection ( ) )
@@ -260,7 +272,7 @@ public void TestAddUser()
260272 }
261273 }
262274
263- [ ConditionalFact ( nameof ( IsLdapConfigurationExist ) ) ]
275+ [ ConditionalFact ( nameof ( LdapConfigurationExists ) ) ]
264276 public void TestAddingMultipleAttributes ( )
265277 {
266278 using ( LdapConnection connection = GetConnection ( ) )
@@ -343,7 +355,7 @@ public void TestAddingMultipleAttributes()
343355 }
344356 }
345357
346- [ ConditionalFact ( nameof ( IsLdapConfigurationExist ) ) ]
358+ [ ConditionalFact ( nameof ( LdapConfigurationExists ) ) ]
347359 public void TestMoveAndRenameUser ( )
348360 {
349361 using ( LdapConnection connection = GetConnection ( ) )
@@ -402,7 +414,7 @@ public void TestMoveAndRenameUser()
402414 }
403415 }
404416
405- [ ConditionalFact ( nameof ( IsLdapConfigurationExist ) ) ]
417+ [ ConditionalFact ( nameof ( LdapConfigurationExists ) ) ]
406418 public void TestAsyncSearch ( )
407419 {
408420 using ( LdapConnection connection = GetConnection ( ) )
@@ -513,7 +525,7 @@ public static IEnumerable<object[]> TestCompareRequestTheory_TestData()
513525 yield return new object [ ] { "http://example.com/" , "http://false/"u8 . ToArray ( ) , ResultCode . CompareFalse } ;
514526 }
515527
516- [ ConditionalTheory ( nameof ( IsLdapConfigurationExist ) ) ]
528+ [ ConditionalTheory ( nameof ( LdapConfigurationExists ) ) ]
517529 [ MemberData ( nameof ( TestCompareRequestTheory_TestData ) ) ]
518530 public void TestCompareRequestTheory ( object value , object assertion , ResultCode compareResult )
519531 {
@@ -546,7 +558,7 @@ public void TestCompareRequestTheory(object value, object assertion, ResultCode
546558 }
547559 }
548560
549- [ ConditionalFact ( nameof ( IsLdapConfigurationExist ) ) ]
561+ [ ConditionalFact ( nameof ( LdapConfigurationExists ) ) ]
550562 public void TestCompareRequest ( )
551563 {
552564 using ( LdapConnection connection = GetConnection ( ) )
@@ -670,7 +682,7 @@ public void TestSortedSearch()
670682 }
671683 }
672684
673- [ ConditionalFact ( nameof ( IsLdapConfigurationExist ) ) ]
685+ [ ConditionalFact ( nameof ( LdapConfigurationExists ) ) ]
674686 public void TestMultipleServerBind ( )
675687 {
676688 LdapDirectoryIdentifier directoryIdentifier = string . IsNullOrEmpty ( LdapConfiguration . Configuration . Port ) ?
@@ -774,13 +786,25 @@ private SearchResultEntry SearchUser(LdapConnection connection, string rootDn, s
774786 return null ;
775787 }
776788
789+ private LdapConnection GetConnection ( string server )
790+ {
791+ LdapDirectoryIdentifier directoryIdentifier = new LdapDirectoryIdentifier ( server , fullyQualifiedDnsHostName : true , connectionless : false ) ;
792+
793+ return GetConnection ( directoryIdentifier ) ;
794+ }
795+
777796 private LdapConnection GetConnection ( )
778797 {
779798 LdapDirectoryIdentifier directoryIdentifier = string . IsNullOrEmpty ( LdapConfiguration . Configuration . Port ) ?
780- new LdapDirectoryIdentifier ( LdapConfiguration . Configuration . ServerName , true , false ) :
799+ new LdapDirectoryIdentifier ( LdapConfiguration . Configuration . ServerName , fullyQualifiedDnsHostName : true , connectionless : false ) :
781800 new LdapDirectoryIdentifier ( LdapConfiguration . Configuration . ServerName ,
782801 int . Parse ( LdapConfiguration . Configuration . Port , NumberStyles . None , CultureInfo . InvariantCulture ) ,
783- true , false ) ;
802+ fullyQualifiedDnsHostName : true , connectionless : false ) ;
803+ return GetConnection ( directoryIdentifier ) ;
804+ }
805+
806+ private static LdapConnection GetConnection ( LdapDirectoryIdentifier directoryIdentifier )
807+ {
784808 NetworkCredential credential = new NetworkCredential ( LdapConfiguration . Configuration . UserName , LdapConfiguration . Configuration . Password ) ;
785809
786810 LdapConnection connection = new LdapConnection ( directoryIdentifier , credential )
0 commit comments