Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Ability to use complex segments for ManagementBasePath #109

Merged
merged 1 commit into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Duende.Bff/Endpoints/BffEndpointRouteBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void MapBffManagementLoginEndpoint(this IEndpointRouteBuilder endp

var options = endpoints.ServiceProvider.GetRequiredService<BffOptions>();

endpoints.MapGet(options.LoginPath, ProcessWith<ILoginService>);
endpoints.MapGet(options.LoginPath.Value!, ProcessWith<ILoginService>);
}

/// <summary>
Expand All @@ -62,8 +62,8 @@ public static void MapBffManagementSilentLoginEndpoints(this IEndpointRouteBuild

var options = endpoints.ServiceProvider.GetRequiredService<BffOptions>();

endpoints.MapGet(options.SilentLoginPath, ProcessWith<ISilentLoginService>);
endpoints.MapGet(options.SilentLoginCallbackPath, ProcessWith<ISilentLoginCallbackService>);
endpoints.MapGet(options.SilentLoginPath.Value!, ProcessWith<ISilentLoginService>);
endpoints.MapGet(options.SilentLoginCallbackPath.Value!, ProcessWith<ISilentLoginCallbackService>);
}

/// <summary>
Expand All @@ -76,7 +76,7 @@ public static void MapBffManagementLogoutEndpoint(this IEndpointRouteBuilder end

var options = endpoints.ServiceProvider.GetRequiredService<BffOptions>();

endpoints.MapGet(options.LogoutPath, ProcessWith<ILogoutService>);
endpoints.MapGet(options.LogoutPath.Value!, ProcessWith<ILogoutService>);
}

/// <summary>
Expand All @@ -89,7 +89,7 @@ public static void MapBffManagementUserEndpoint(this IEndpointRouteBuilder endpo

var options = endpoints.ServiceProvider.GetRequiredService<BffOptions>();

endpoints.MapGet(options.UserPath, ProcessWith<IUserService>)
endpoints.MapGet(options.UserPath.Value!, ProcessWith<IUserService>)
.AsBffApiEndpoint();
}

Expand All @@ -103,7 +103,7 @@ public static void MapBffManagementBackchannelEndpoint(this IEndpointRouteBuilde

var options = endpoints.ServiceProvider.GetRequiredService<BffOptions>();

endpoints.MapPost(options.BackChannelLogoutPath, ProcessWith<IBackchannelLogoutService>);
endpoints.MapPost(options.BackChannelLogoutPath.Value!, ProcessWith<IBackchannelLogoutService>);
}

/// <summary>
Expand All @@ -116,7 +116,7 @@ public static void MapBffDiagnosticsEndpoint(this IEndpointRouteBuilder endpoint

var options = endpoints.ServiceProvider.GetRequiredService<BffOptions>();

endpoints.MapGet(options.DiagnosticsPath, ProcessWith<IDiagnosticsService>);
endpoints.MapGet(options.DiagnosticsPath.Value!, ProcessWith<IDiagnosticsService>);
}

internal static void CheckLicense(this IEndpointRouteBuilder endpoints)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

using Duende.Bff.Tests.TestHosts;
using FluentAssertions;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;
using Microsoft.AspNetCore.Http;

namespace Duende.Bff.Tests.Endpoints.Management
{
public class ManagementBasePathTests : BffIntegrationTestBase
{
[Theory]
[InlineData(Constants.ManagementEndpoints.Login)]
[InlineData(Constants.ManagementEndpoints.Logout)]
[InlineData(Constants.ManagementEndpoints.SilentLogin)]
[InlineData(Constants.ManagementEndpoints.SilentLoginCallback)]
[InlineData(Constants.ManagementEndpoints.User)]
public async Task custom_ManagementBasePath_should_affect_basepath(string path)
{
BffHost.BffOptions.ManagementBasePath = new PathString("/{path:regex(^[a-zA-Z\\d-]+$)}/bff");
await BffHost.InitializeAsync();

var req = new HttpRequestMessage(HttpMethod.Get, BffHost.Url("/custom/bff" + path));
req.Headers.Add("x-csrf", "1");

var response = await BffHost.BrowserClient.SendAsync(req);

response.StatusCode.Should().NotBe(404);
}
}
}