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

Commit 538744d

Browse files
committed
Make WindowsPrincipalIsInRoleNeg pass when a domain client is offline
1 parent dc722e9 commit 538744d

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/System.Security.Principal.Windows/tests/WindowsPrincipalTests.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System;
6+
using System.ComponentModel;
57
using System.Security.Principal;
68
using Xunit;
79

@@ -12,7 +14,23 @@ public static void WindowsPrincipalIsInRoleNeg()
1214
{
1315
WindowsIdentity windowsIdentity = WindowsIdentity.GetAnonymous();
1416
WindowsPrincipal windowsPrincipal = new WindowsPrincipal(windowsIdentity);
15-
var ret = windowsPrincipal.IsInRole("FAKEDOMAIN\\nonexist");
16-
Assert.False(ret);
17+
18+
try
19+
{
20+
bool ret = windowsPrincipal.IsInRole("FAKEDOMAIN\\nonexist");
21+
Assert.False(ret);
22+
}
23+
catch (SystemException e)
24+
{
25+
// If a domain joined machine can't talk to the domain controller then it
26+
// can't determine if "FAKEDOMAIN" is resolvable within the AD forest, so it
27+
// fails with ERROR_TRUSTED_RELATIONSHIP_FAILURE (resulting in an exception).
28+
const int ERROR_TRUSTED_RELATIONSHIP_FAILURE = 0x6FD;
29+
Win32Exception win32Exception = new Win32Exception(ERROR_TRUSTED_RELATIONSHIP_FAILURE);
30+
31+
// NetFx throws a plain SystemException which has the message built via FormatMessage.
32+
// CoreFx throws a Win32Exception based on the error, which gets the same message value.
33+
Assert.Equal(win32Exception.Message, e.Message);
34+
}
1735
}
1836
}

0 commit comments

Comments
 (0)