Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 295af99

Browse files
authored
Fix Outloop Directory Services Tests (#26227)
1 parent 36e3dd4 commit 295af99

File tree

6 files changed

+31
-18
lines changed

6 files changed

+31
-18
lines changed

src/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public static partial class PlatformDetection
105105
public static int WindowsVersion { get { throw null; } }
106106
public static string GetDistroVersionString() { throw null; }
107107
public static bool TargetsNetFx452OrLower { get { throw null; } }
108+
public static bool IsDomainJoinedMachine { get { throw null; } }
108109
}
109110
public static partial class TheoryExtensions
110111
{

src/CoreFx.Private.TestUtilities/src/System/PlatformDetection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public static partial class PlatformDetection
3939
public static bool IsNotWinRTSupported => !IsWinRTSupported;
4040
public static bool IsNotMacOsHighSierraOrHigher => !IsMacOsHighSierraOrHigher;
4141

42-
// Officially, .Net Native only supports processes running in an AppContainer. However, the majority of tests still work fine
42+
public static bool IsDomainJoinedMachine => !Environment.MachineName.Equals(Environment.UserDomainName, StringComparison.OrdinalIgnoreCase);
43+
44+
// Officially, .Net Native only supports processes running in an AppContainer. However, the majority of tests still work fine
4345
// in a normal Win32 process and we often do so as running in an AppContainer imposes a substantial tax in debuggability
4446
// and investigatability. This predicate is used in ConditionalFacts to disable the specific tests that really need to be
4547
// running in AppContainer when running on .NetNative.

src/System.DirectoryServices.AccountManagement/tests/PrincipalContextTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace System.DirectoryServices.AccountManagement.Tests
1010
{
1111
public class PrincipalContextTests
1212
{
13-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
13+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
1414
public void Ctor_ContextType()
1515
{
1616
var context = new PrincipalContext(ContextType.Machine);
@@ -170,7 +170,7 @@ public void Ctor_InvalidContexType_ThrowsInvalidEnumArgumentException(ContextTyp
170170
[Fact]
171171
public void Ctor_DomainContextType_ThrowsPrincipalServerDownException()
172172
{
173-
if (Environment.MachineName.Equals(Environment.UserDomainName, StringComparison.OrdinalIgnoreCase))
173+
if (!PlatformDetection.IsDomainJoinedMachine)
174174
{
175175
// The machine is not connected to a domain. we expect PrincipalContext(ContextType.Domain) to throw
176176
Assert.Throws<PrincipalServerDownException>(() => new PrincipalContext(ContextType.Domain));
@@ -299,7 +299,7 @@ public void ValidateCredentials_Invoke_ReturnsExpected(string userName, string p
299299
}
300300

301301
[ActiveIssue(23800)]
302-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
302+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
303303
[OuterLoop("Takes too long on domain joined machines")]
304304
public void ValidateCredentials_InvalidUserName_ThrowsException()
305305
{
@@ -308,7 +308,7 @@ public void ValidateCredentials_InvalidUserName_ThrowsException()
308308
}
309309

310310
[ActiveIssue(23800)]
311-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
311+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
312312
[OuterLoop("Takes too long on domain joined machines")]
313313
public void ValidateCredentials_IncorrectUserNamePassword_ThrowsException()
314314
{

src/System.DirectoryServices/tests/System/DirectoryServices/ActiveDirectory/ActiveDirectoryInterSiteTransportTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ public void FindByTransportType_NullContext_ThrowsArgumentNullException()
2222
public void FindByTransportType_ForestNoDomainAssociatedWithoutName_ThrowsActiveDirectoryOperationException()
2323
{
2424
var context = new DirectoryContext(DirectoryContextType.Forest);
25-
Assert.Throws<ActiveDirectoryOperationException>(() => ActiveDirectoryInterSiteTransport.FindByTransportType(context, ActiveDirectoryTransportType.Rpc));
25+
if (!PlatformDetection.IsDomainJoinedMachine)
26+
{
27+
Assert.Throws<ActiveDirectoryOperationException>(() => ActiveDirectoryInterSiteTransport.FindByTransportType(context, ActiveDirectoryTransportType.Rpc));
28+
}
2629
}
2730

2831
[Fact]
@@ -37,7 +40,7 @@ public void FindByTransportType_ForestNoDomainAssociatedWithName_ThrowsActiveDir
3740
public void FindByTransportType_ForestNoDomainAssociatedWithName_ThrowsActiveDirectoryOperationException_NoUap()
3841
{
3942
// Domain joined machines will not throw on the ActiveDirectoryInterSiteTransport.FindByTransportType call.
40-
if (Environment.MachineName.Equals(Environment.UserDomainName, StringComparison.OrdinalIgnoreCase))
43+
if (!PlatformDetection.IsDomainJoinedMachine)
4144
{
4245
var context = new DirectoryContext(DirectoryContextType.Forest, "\0");
4346
AssertExtensions.Throws<ArgumentException>("context", () => ActiveDirectoryInterSiteTransport.FindByTransportType(context, ActiveDirectoryTransportType.Rpc));

src/System.DirectoryServices/tests/System/DirectoryServices/ActiveDirectory/DomainControllerTests.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public void GetDomainController_InvalidContextType_ThrowsArgumentException(Direc
2929
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
3030
[OuterLoop("Takes too long on domain joined machines")]
3131
[InlineData("\0")]
32-
[InlineData("server:port")]
3332
[InlineData("[")]
3433
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "Access to path is denied when in App container")]
3534
public void GetDomainController_InvalidName_ThrowsActiveDirectoryObjectNotFoundException(string name)
@@ -38,7 +37,7 @@ public void GetDomainController_InvalidName_ThrowsActiveDirectoryObjectNotFoundE
3837
Assert.Throws<ActiveDirectoryObjectNotFoundException>(() => DomainController.GetDomainController(context));
3938
}
4039

41-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
40+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
4241
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "Access to path is denied when in App container")]
4342
public void GetDomainController_InvalidIPV6_ThrowsActiveDirectoryObjectNotFoundException()
4443
{
@@ -110,11 +109,11 @@ public void FindOne_InvalidName_ThrowsException(string name, Type exceptionType)
110109
public void FindAll_NoSuchName_ReturnsEmpty()
111110
{
112111
// Domain joined machines can have entries in the DomainController.
113-
if (Environment.MachineName.Equals(Environment.UserDomainName, StringComparison.OrdinalIgnoreCase))
112+
if (PlatformDetection.IsDomainJoinedMachine)
114113
{
115114
var context = new DirectoryContext(DirectoryContextType.Domain, "\0");
116-
Assert.Empty(DomainController.FindAll(context));
117-
Assert.Empty(DomainController.FindAll(context, "siteName"));
115+
Assert.NotNull(DomainController.FindAll(context));
116+
Assert.NotNull(DomainController.FindAll(context, "siteName"));
118117
}
119118
}
120119

@@ -125,7 +124,10 @@ public void FindAll_NoSuchName_ReturnsEmpty()
125124
public void FindAll_NullName_ThrowsActiveDirectoryOperationException()
126125
{
127126
var context = new DirectoryContext(DirectoryContextType.Domain);
128-
Assert.Throws<ActiveDirectoryOperationException>(() => DomainController.FindAll(context));
127+
if (!PlatformDetection.IsDomainJoinedMachine)
128+
{
129+
Assert.Throws<ActiveDirectoryOperationException>(() => DomainController.FindAll(context));
130+
}
129131
}
130132

131133
[Fact]
@@ -134,7 +136,7 @@ public void FindAll_NullContext_ThrowsArgumentNullException()
134136
AssertExtensions.Throws<ArgumentNullException>("context", () => DomainController.FindAll(null));
135137
AssertExtensions.Throws<ArgumentNullException>("context", () => DomainController.FindAll(null, "siteName"));
136138
}
137-
139+
138140
[Theory]
139141
[InlineData(DirectoryContextType.ApplicationPartition)]
140142
[InlineData(DirectoryContextType.ConfigurationSet)]

src/System.DirectoryServices/tests/System/DirectoryServices/ActiveDirectory/ForestTests.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public void GetForest_InvalidContextType_ThrowsArgumentException(DirectoryContex
3030
public void GetForest_NullNameAndNotRootedDomain_ThrowsActiveDirectoryOperationException()
3131
{
3232
var context = new DirectoryContext(DirectoryContextType.Forest);
33-
Assert.Throws<ActiveDirectoryOperationException>(() => Forest.GetForest(context));
33+
34+
if (!PlatformDetection.IsDomainJoinedMachine)
35+
Assert.Throws<ActiveDirectoryOperationException>(() => Forest.GetForest(context));
3436
}
3537

3638
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
@@ -54,10 +56,13 @@ public void GetForest_NonNullNameAndNotRootedDomain_ThrowsActiveDirectoryObjectN
5456
public void GetForest_NonNullNameAndNotRootedDomain_ThrowsActiveDirectoryObjectNotFoundException_NonUap(DirectoryContextType type, string name)
5557
{
5658
var context = new DirectoryContext(type, name);
57-
Assert.Throws<ActiveDirectoryObjectNotFoundException>(() => Forest.GetForest(context));
59+
if (!PlatformDetection.IsDomainJoinedMachine)
60+
{
61+
Assert.Throws<ActiveDirectoryObjectNotFoundException>(() => Forest.GetForest(context));
5862

59-
// The result of validation is cached, so repeat this to make sure it's cached properly.
60-
Assert.Throws<ActiveDirectoryObjectNotFoundException>(() => Forest.GetForest(context));
63+
// The result of validation is cached, so repeat this to make sure it's cached properly.
64+
Assert.Throws<ActiveDirectoryObjectNotFoundException>(() => Forest.GetForest(context));
65+
}
6166
}
6267
}
6368
}

0 commit comments

Comments
 (0)