This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
src/System.Security.Principal.Windows/tests Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 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 ;
57using System . Security . Principal ;
68using 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}
You can’t perform that action at this time.
0 commit comments