Challenge now always checks for accept

This commit is contained in:
Hao Kung 2015-08-05 12:15:45 -07:00
parent 4576481a32
commit 67803d2f41
2 changed files with 8 additions and 8 deletions

View File

@ -72,8 +72,7 @@ namespace Microsoft.AspNet.Http.Authentication.Internal
await handler.ChallengeAsync(challengeContext);
}
// The default Challenge with no scheme is always accepted
if (!challengeContext.Accepted && !string.IsNullOrEmpty(authenticationScheme))
if (!challengeContext.Accepted)
{
throw new InvalidOperationException($"The following authentication scheme was not accepted: {authenticationScheme}");
}
@ -105,7 +104,7 @@ namespace Microsoft.AspNet.Http.Authentication.Internal
await handler.SignOutAsync(signOutContext);
}
if (!string.IsNullOrWhiteSpace(authenticationScheme) && !signOutContext.Accepted)
if (!signOutContext.Accepted)
{
throw new InvalidOperationException($"The following authentication scheme was not accepted: {authenticationScheme}");
}

View File

@ -21,13 +21,14 @@ namespace Microsoft.AspNet.Http.Authentication.Internal
await Assert.ThrowsAsync<InvalidOperationException>(async () => await context.Authentication.AuthenticateAsync("Foo"));
}
[Fact]
public async Task ChallengeWithNoAuthMiddlewareMayThrow()
[Theory]
[InlineData("")]
[InlineData(null)]
[InlineData("Foo")]
public async Task ChallengeWithNoAuthMiddlewareMayThrow(string scheme)
{
var context = CreateContext();
await context.Authentication.ChallengeAsync();
Assert.Equal(200, context.Response.StatusCode);
await Assert.ThrowsAsync<InvalidOperationException>(() => context.Authentication.ChallengeAsync("Foo"));
await Assert.ThrowsAsync<InvalidOperationException>(() => context.Authentication.ChallengeAsync(scheme));
}
[Fact]