Skip to content
This repository was archived by the owner on Nov 1, 2018. It is now read-only.

Commit e2b7288

Browse files
committed
Fix tests
1 parent 6aa53d8 commit e2b7288

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

test/Microsoft.AspNetCore.Server.IISIntegration.Tests/IISMiddlewareTests.cs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ public async Task AddsAuthenticationHandlerByDefault()
178178
Assert.True(assertsExecuted);
179179
}
180180

181-
[Fact]
182-
public async Task DoesNotAddAuthenticationHandlerIfWindowsAuthDisabled()
181+
[Theory]
182+
[InlineData(true)]
183+
[InlineData(false)]
184+
public async Task OnlyAddAuthenticationHandlerIfForwardWindowsAuthentication(bool forward)
183185
{
184186
var assertsExecuted = false;
185187

@@ -192,7 +194,52 @@ public async Task DoesNotAddAuthenticationHandlerIfWindowsAuthDisabled()
192194
{
193195
services.Configure<IISOptions>(options =>
194196
{
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;
196243
});
197244
})
198245
.Configure(app =>
@@ -213,5 +260,6 @@ public async Task DoesNotAddAuthenticationHandlerIfWindowsAuthDisabled()
213260

214261
Assert.True(assertsExecuted);
215262
}
263+
216264
}
217265
}

0 commit comments

Comments
 (0)