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

Commit 67803d2

Browse files
committed
Challenge now always checks for accept
1 parent 4576481 commit 67803d2

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/Microsoft.AspNet.Http/Authentication/DefaultAuthenticationManager.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public override async Task ChallengeAsync([NotNull] string authenticationScheme,
7272
await handler.ChallengeAsync(challengeContext);
7373
}
7474

75-
// The default Challenge with no scheme is always accepted
76-
if (!challengeContext.Accepted && !string.IsNullOrEmpty(authenticationScheme))
75+
if (!challengeContext.Accepted)
7776
{
7877
throw new InvalidOperationException($"The following authentication scheme was not accepted: {authenticationScheme}");
7978
}
@@ -105,7 +104,7 @@ public override async Task SignOutAsync([NotNull] string authenticationScheme, A
105104
await handler.SignOutAsync(signOutContext);
106105
}
107106

108-
if (!string.IsNullOrWhiteSpace(authenticationScheme) && !signOutContext.Accepted)
107+
if (!signOutContext.Accepted)
109108
{
110109
throw new InvalidOperationException($"The following authentication scheme was not accepted: {authenticationScheme}");
111110
}

test/Microsoft.AspNet.Http.Tests/Authentication/DefaultAuthenticationManagerTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ public async Task AuthenticateWithNoAuthMiddlewareThrows()
2121
await Assert.ThrowsAsync<InvalidOperationException>(async () => await context.Authentication.AuthenticateAsync("Foo"));
2222
}
2323

24-
[Fact]
25-
public async Task ChallengeWithNoAuthMiddlewareMayThrow()
24+
[Theory]
25+
[InlineData("")]
26+
[InlineData(null)]
27+
[InlineData("Foo")]
28+
public async Task ChallengeWithNoAuthMiddlewareMayThrow(string scheme)
2629
{
2730
var context = CreateContext();
28-
await context.Authentication.ChallengeAsync();
29-
Assert.Equal(200, context.Response.StatusCode);
30-
await Assert.ThrowsAsync<InvalidOperationException>(() => context.Authentication.ChallengeAsync("Foo"));
31+
await Assert.ThrowsAsync<InvalidOperationException>(() => context.Authentication.ChallengeAsync(scheme));
3132
}
3233

3334
[Fact]

0 commit comments

Comments
 (0)