Skip to content

Commit 6108c0d

Browse files
authored
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.
1 parent 135f782 commit 6108c0d

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/Mvc/Mvc.Core/src/SignInResult.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,6 @@ public override async Task ExecuteResultAsync(ActionContext context)
8585
throw new ArgumentNullException(nameof(context));
8686
}
8787

88-
if (AuthenticationScheme == null)
89-
{
90-
throw new InvalidOperationException(
91-
Resources.FormatPropertyOfTypeCannotBeNull(
92-
/* property: */ nameof(AuthenticationScheme),
93-
/* type: */ nameof(SignInResult)));
94-
}
95-
9688
var loggerFactory = context.HttpContext.RequestServices.GetRequiredService<ILoggerFactory>();
9789
var logger = loggerFactory.CreateLogger<SignInResult>();
9890

src/Mvc/Mvc.Core/test/SignInResultTest.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,33 @@ public async Task ExecuteResultAsync_InvokesSignInAsyncOnAuthenticationManager()
4545
auth.Verify();
4646
}
4747

48+
[Fact]
49+
public async Task ExecuteResultAsync_InvokesSignInAsyncOnAuthenticationManagerWithDefaultScheme()
50+
{
51+
// Arrange
52+
var principal = new ClaimsPrincipal();
53+
var httpContext = new Mock<HttpContext>();
54+
var auth = new Mock<IAuthenticationService>();
55+
auth
56+
.Setup(c => c.SignInAsync(httpContext.Object, null, principal, null))
57+
.Returns(Task.CompletedTask)
58+
.Verifiable();
59+
httpContext.Setup(c => c.RequestServices).Returns(CreateServices(auth.Object));
60+
var result = new SignInResult(principal);
61+
var routeData = new RouteData();
62+
63+
var actionContext = new ActionContext(
64+
httpContext.Object,
65+
routeData,
66+
new ActionDescriptor());
67+
68+
// Act
69+
await result.ExecuteResultAsync(actionContext);
70+
71+
// Assert
72+
auth.Verify();
73+
}
74+
4875
[Fact]
4976
public async Task ExecuteResultAsync_InvokesSignInAsyncOnConfiguredScheme()
5077
{
@@ -81,4 +108,4 @@ private static IServiceProvider CreateServices(IAuthenticationService auth)
81108
.BuildServiceProvider();
82109
}
83110
}
84-
}
111+
}

0 commit comments

Comments
 (0)