Fix SignInResult with default scheme (#27531)

Description
Fixes #27494

A community PR introduced new overloads to ControllerBase for SignIn. The new overload throws due to an existing check which blocks when the scheme is null. The fix is to remove this unnecessary check. Note SignOutResult already had test coverage for this usage and is unaffected

Customer Impact
The bug was reported by a customer trying to use the new overload. The fix enables the method to be used.

Regression?
No

Risk
Low as this is a new API, and the api was unuseable in its current form.
This commit is contained in:
Hao Kung 2020-11-13 12:02:59 -08:00 committed by GitHub
parent 135f7820d1
commit 6108c0d03e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 9 deletions

View File

@ -85,14 +85,6 @@ namespace Microsoft.AspNetCore.Mvc
throw new ArgumentNullException(nameof(context));
}
if (AuthenticationScheme == null)
{
throw new InvalidOperationException(
Resources.FormatPropertyOfTypeCannotBeNull(
/* property: */ nameof(AuthenticationScheme),
/* type: */ nameof(SignInResult)));
}
var loggerFactory = context.HttpContext.RequestServices.GetRequiredService<ILoggerFactory>();
var logger = loggerFactory.CreateLogger<SignInResult>();

View File

@ -45,6 +45,33 @@ namespace Microsoft.AspNetCore.Mvc
auth.Verify();
}
[Fact]
public async Task ExecuteResultAsync_InvokesSignInAsyncOnAuthenticationManagerWithDefaultScheme()
{
// Arrange
var principal = new ClaimsPrincipal();
var httpContext = new Mock<HttpContext>();
var auth = new Mock<IAuthenticationService>();
auth
.Setup(c => c.SignInAsync(httpContext.Object, null, principal, null))
.Returns(Task.CompletedTask)
.Verifiable();
httpContext.Setup(c => c.RequestServices).Returns(CreateServices(auth.Object));
var result = new SignInResult(principal);
var routeData = new RouteData();
var actionContext = new ActionContext(
httpContext.Object,
routeData,
new ActionDescriptor());
// Act
await result.ExecuteResultAsync(actionContext);
// Assert
auth.Verify();
}
[Fact]
public async Task ExecuteResultAsync_InvokesSignInAsyncOnConfiguredScheme()
{