From 6108c0d03e0028519262f0d10d96604fb39a2647 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Fri, 13 Nov 2020 12:02:59 -0800 Subject: [PATCH] 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. --- src/Mvc/Mvc.Core/src/SignInResult.cs | 8 ------- src/Mvc/Mvc.Core/test/SignInResultTest.cs | 29 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/Mvc/Mvc.Core/src/SignInResult.cs b/src/Mvc/Mvc.Core/src/SignInResult.cs index c6cf63ffe8..d558706158 100644 --- a/src/Mvc/Mvc.Core/src/SignInResult.cs +++ b/src/Mvc/Mvc.Core/src/SignInResult.cs @@ -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(); var logger = loggerFactory.CreateLogger(); diff --git a/src/Mvc/Mvc.Core/test/SignInResultTest.cs b/src/Mvc/Mvc.Core/test/SignInResultTest.cs index 1b3246ccb0..15f895bd5b 100644 --- a/src/Mvc/Mvc.Core/test/SignInResultTest.cs +++ b/src/Mvc/Mvc.Core/test/SignInResultTest.cs @@ -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(); + var auth = new Mock(); + 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() { @@ -81,4 +108,4 @@ namespace Microsoft.AspNetCore.Mvc .BuildServiceProvider(); } } -} \ No newline at end of file +}