diff --git a/src/Microsoft.AspNet.Http/Authentication/DefaultAuthenticationManager.cs b/src/Microsoft.AspNet.Http/Authentication/DefaultAuthenticationManager.cs index d0cec090c0..821a67395a 100644 --- a/src/Microsoft.AspNet.Http/Authentication/DefaultAuthenticationManager.cs +++ b/src/Microsoft.AspNet.Http/Authentication/DefaultAuthenticationManager.cs @@ -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}"); } diff --git a/test/Microsoft.AspNet.Http.Tests/Authentication/DefaultAuthenticationManagerTests.cs b/test/Microsoft.AspNet.Http.Tests/Authentication/DefaultAuthenticationManagerTests.cs index 2871c27ec3..3430382e8a 100644 --- a/test/Microsoft.AspNet.Http.Tests/Authentication/DefaultAuthenticationManagerTests.cs +++ b/test/Microsoft.AspNet.Http.Tests/Authentication/DefaultAuthenticationManagerTests.cs @@ -21,13 +21,14 @@ namespace Microsoft.AspNet.Http.Authentication.Internal await Assert.ThrowsAsync(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(() => context.Authentication.ChallengeAsync("Foo")); + await Assert.ThrowsAsync(() => context.Authentication.ChallengeAsync(scheme)); } [Fact]