@@ -19,9 +19,8 @@ public class NtlmAuthenticationTests
19
19
{
20
20
[ ConditionalTheory , Trait ( "ServerComparison.FunctionalTests" , "ServerComparison.FunctionalTests" ) ]
21
21
[ OSSkipCondition ( OperatingSystems . Linux | OperatingSystems . MacOSX ) ]
22
- // TODO: Figure out why IISExpress failing
23
- //[InlineData(ServerType.IISExpress, RuntimeFlavor.CoreClr, RuntimeArchitecture.x86, "http://localhost:5050/")]
24
- //[InlineData(ServerType.IISExpress, RuntimeFlavor.Clr, RuntimeArchitecture.x64, "http://localhost:5051/")]
22
+ [ InlineData ( ServerType . IISExpress , RuntimeFlavor . CoreClr , RuntimeArchitecture . x86 , "http://localhost:5050/" ) ]
23
+ [ InlineData ( ServerType . IISExpress , RuntimeFlavor . Clr , RuntimeArchitecture . x64 , "http://localhost:5051/" ) ]
25
24
[ InlineData ( ServerType . WebListener , RuntimeFlavor . Clr , RuntimeArchitecture . x86 , "http://localhost:5052/" ) ]
26
25
[ InlineData ( ServerType . WebListener , RuntimeFlavor . CoreClr , RuntimeArchitecture . x64 , "http://localhost:5052/" ) ]
27
26
public async Task NtlmAuthentication ( ServerType serverType , RuntimeFlavor runtimeFlavor , RuntimeArchitecture architecture , string applicationBaseUrl )
@@ -61,14 +60,52 @@ public async Task NtlmAuthentication(ServerType serverType, RuntimeFlavor runtim
61
60
Assert . Equal ( "Anonymous?True" , responseText ) ;
62
61
63
62
response = await httpClient . GetAsync ( "/Restricted" ) ;
63
+ Assert . Equal ( HttpStatusCode . Unauthorized , response . StatusCode ) ;
64
+ Assert . Contains ( "NTLM" , response . Headers . WwwAuthenticate . ToString ( ) ) ;
65
+ Assert . Contains ( "Negotiate" , response . Headers . WwwAuthenticate . ToString ( ) ) ;
64
66
67
+ response = await httpClient . GetAsync ( "/RestrictedNTLM" ) ;
65
68
Assert . Equal ( HttpStatusCode . Unauthorized , response . StatusCode ) ;
66
69
Assert . Contains ( "NTLM" , response . Headers . WwwAuthenticate . ToString ( ) ) ;
70
+ // Note IIS can't restrict a challenge to a specific auth type, the native auth modules always add themselves.
71
+ // However WebListener can.
72
+ if ( serverType == ServerType . WebListener )
73
+ {
74
+ Assert . DoesNotContain ( "Negotiate" , response . Headers . WwwAuthenticate . ToString ( ) ) ;
75
+ }
76
+ else if ( serverType == ServerType . IISExpress )
77
+ {
78
+ Assert . Contains ( "Negotiate" , response . Headers . WwwAuthenticate . ToString ( ) ) ;
79
+ }
80
+
81
+ response = await httpClient . GetAsync ( "/Forbidden" ) ;
82
+ Assert . Equal ( HttpStatusCode . Forbidden , response . StatusCode ) ;
67
83
68
84
httpClientHandler = new HttpClientHandler ( ) { UseDefaultCredentials = true } ;
69
85
httpClient = new HttpClient ( httpClientHandler ) { BaseAddress = new Uri ( deploymentResult . ApplicationBaseUri ) } ;
86
+
87
+ response = await httpClient . GetAsync ( "/AutoForbid" ) ;
88
+ Assert . Equal ( HttpStatusCode . Forbidden , response . StatusCode ) ;
89
+
70
90
responseText = await httpClient . GetStringAsync ( "/Restricted" ) ;
71
- Assert . Equal ( "NotAnonymous" , responseText ) ;
91
+ Assert . Equal ( "Negotiate" , responseText ) ;
92
+
93
+ responseText = await httpClient . GetStringAsync ( "/RestrictedNegotiate" ) ;
94
+ Assert . Equal ( "Negotiate" , responseText ) ;
95
+
96
+ if ( serverType == ServerType . WebListener )
97
+ {
98
+ responseText = await httpClient . GetStringAsync ( "/RestrictedNTLM" ) ;
99
+ Assert . Equal ( "NTLM" , responseText ) ;
100
+ }
101
+ else if ( serverType == ServerType . IISExpress )
102
+ {
103
+ response = await httpClient . GetAsync ( "/RestrictedNTLM" ) ;
104
+ // This isn't a Forbidden because we authenticate with Negotiate and challenge for NTLM.
105
+ Assert . Equal ( HttpStatusCode . Unauthorized , response . StatusCode ) ;
106
+ // Note IIS can't restrict a challenge to a specific auth type, the native auth modules always add themselves,
107
+ // so both Negotiate and NTLM get sent again.
108
+ }
72
109
}
73
110
catch ( XunitException )
74
111
{
0 commit comments