@@ -178,8 +178,10 @@ public async Task AddsAuthenticationHandlerByDefault()
178
178
Assert . True ( assertsExecuted ) ;
179
179
}
180
180
181
- [ Fact ]
182
- public async Task DoesNotAddAuthenticationHandlerIfWindowsAuthDisabled ( )
181
+ [ Theory ]
182
+ [ InlineData ( true ) ]
183
+ [ InlineData ( false ) ]
184
+ public async Task OnlyAddAuthenticationHandlerIfForwardWindowsAuthentication ( bool forward )
183
185
{
184
186
var assertsExecuted = false ;
185
187
@@ -192,7 +194,52 @@ public async Task DoesNotAddAuthenticationHandlerIfWindowsAuthDisabled()
192
194
{
193
195
services . Configure < IISOptions > ( options =>
194
196
{
195
- options . ForwardWindowsAuthentication = false ;
197
+ options . ForwardWindowsAuthentication = forward ;
198
+ } ) ;
199
+ services . AddAuthenticationCore ( ) ;
200
+ } )
201
+ . Configure ( app =>
202
+ {
203
+ app . Run ( async context =>
204
+ {
205
+ var auth = context . RequestServices . GetService < IAuthenticationSchemeProvider > ( ) ;
206
+ Assert . NotNull ( auth ) ;
207
+ var windowsAuth = await auth . GetSchemeAsync ( "Windows" ) ;
208
+ if ( forward )
209
+ {
210
+ Assert . NotNull ( windowsAuth ) ;
211
+ Assert . Null ( windowsAuth . DisplayName ) ;
212
+ Assert . Equal ( "AuthenticationHandler" , windowsAuth . HandlerType . Name ) ;
213
+ }
214
+ assertsExecuted = true ;
215
+ } ) ;
216
+ } ) ;
217
+ var server = new TestServer ( builder ) ;
218
+
219
+ var req = new HttpRequestMessage ( HttpMethod . Get , "" ) ;
220
+ req . Headers . TryAddWithoutValidation ( "MS-ASPNETCORE-TOKEN" , "TestToken" ) ;
221
+ await server . CreateClient ( ) . SendAsync ( req ) ;
222
+
223
+ Assert . True ( assertsExecuted ) ;
224
+ }
225
+
226
+ [ Theory ]
227
+ [ InlineData ( true ) ]
228
+ [ InlineData ( false ) ]
229
+ public async Task DoesNotBlowUpWithoutAuth ( bool forward )
230
+ {
231
+ var assertsExecuted = false ;
232
+
233
+ var builder = new WebHostBuilder ( )
234
+ . UseSetting ( "TOKEN" , "TestToken" )
235
+ . UseSetting ( "PORT" , "12345" )
236
+ . UseSetting ( "APPL_PATH" , "/" )
237
+ . UseIISIntegration ( )
238
+ . ConfigureServices ( services =>
239
+ {
240
+ services . Configure < IISOptions > ( options =>
241
+ {
242
+ options . ForwardWindowsAuthentication = forward ;
196
243
} ) ;
197
244
} )
198
245
. Configure ( app =>
@@ -213,5 +260,6 @@ public async Task DoesNotAddAuthenticationHandlerIfWindowsAuthDisabled()
213
260
214
261
Assert . True ( assertsExecuted ) ;
215
262
}
263
+
216
264
}
217
265
}
0 commit comments