From 372674abde2146f5c26915e97ee22123d2e73edf Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 2 Dec 2020 13:32:14 +1100 Subject: [PATCH] re-adds test scheme for test authn/authz --- .../TestServerTest/TestAuthHandler.cs | 5 +++-- .../TestServerTest/UmbracoTestServerTestBase.cs | 6 +++--- .../Extensions/UmbracoBuilderExtensions.cs | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Tests.Integration/TestServerTest/TestAuthHandler.cs b/src/Umbraco.Tests.Integration/TestServerTest/TestAuthHandler.cs index 1163d60055..b9acd9529c 100644 --- a/src/Umbraco.Tests.Integration/TestServerTest/TestAuthHandler.cs +++ b/src/Umbraco.Tests.Integration/TestServerTest/TestAuthHandler.cs @@ -14,8 +14,9 @@ namespace Umbraco.Tests.Integration.TestServerTest { public class TestAuthHandler : AuthenticationHandler { - private readonly IBackOfficeSignInManager _backOfficeSignInManager; + public const string TestAuthenticationScheme = "Test"; + private readonly IBackOfficeSignInManager _backOfficeSignInManager; private readonly BackOfficeIdentityUser _fakeUser; public TestAuthHandler(IOptionsMonitor options, @@ -33,7 +34,7 @@ namespace Umbraco.Tests.Integration.TestServerTest { var principal = await _backOfficeSignInManager.CreateUserPrincipalAsync(_fakeUser); - var ticket = new AuthenticationTicket(principal, Constants.Security.BackOfficeAuthenticationType); + var ticket = new AuthenticationTicket(principal, TestAuthenticationScheme); return AuthenticateResult.Success(ticket); } diff --git a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs index b5ab4cacbb..5867e6522c 100644 --- a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs +++ b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs @@ -48,8 +48,8 @@ namespace Umbraco.Tests.Integration.TestServerTest builder.ConfigureTestServices(services => { // Add a test auth scheme with a test auth handler to authn and assign the user - services.AddAuthentication(Constants.Security.BackOfficeAuthenticationType) - .AddScheme(Constants.Security.BackOfficeAuthenticationType, options => { }); + services.AddAuthentication(TestAuthHandler.TestAuthenticationScheme) + .AddScheme(TestAuthHandler.TestAuthenticationScheme, options => { }); }); }); @@ -144,7 +144,7 @@ namespace Umbraco.Tests.Integration.TestServerTest .AddRuntimeMinifier() .AddBackOffice() .AddBackOfficeIdentity() - .AddBackOfficeAuthorizationPolicies() + .AddBackOfficeAuthorizationPolicies(TestAuthHandler.TestAuthenticationScheme) .AddPreviewSupport() //.WithMiniProfiler() // we don't want this running in tests .AddMvcAndRazor(mvcBuilding: mvcBuilder => diff --git a/src/Umbraco.Web.BackOffice/Extensions/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.BackOffice/Extensions/UmbracoBuilderExtensions.cs index 85ec4dfac0..35b7e8e859 100644 --- a/src/Umbraco.Web.BackOffice/Extensions/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.BackOffice/Extensions/UmbracoBuilderExtensions.cs @@ -62,9 +62,9 @@ namespace Umbraco.Extensions return builder; } - public static IUmbracoBuilder AddBackOfficeAuthorizationPolicies(this IUmbracoBuilder builder) + public static IUmbracoBuilder AddBackOfficeAuthorizationPolicies(this IUmbracoBuilder builder, string backOfficeAuthenticationScheme = Umbraco.Core.Constants.Security.BackOfficeAuthenticationType) { - builder.Services.AddBackOfficeAuthorizationPolicies(Umbraco.Core.Constants.Security.BackOfficeAuthenticationType); + builder.Services.AddBackOfficeAuthorizationPolicies(backOfficeAuthenticationScheme); // TODO: See other TODOs in things like UmbracoApiControllerBase ... AFAIK all of this is only used for the back office // so IMO these controllers and the features auth policies should just be moved to the back office project and then this // ext method can be removed.