Skip to content

Commit

Permalink
fix: BasePathStrategy combine path bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Romanky committed Oct 23, 2022
1 parent d813457 commit 0628b0f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Expand Up @@ -230,7 +230,7 @@ public static class FinbuckleMultiTenantBuilderExtensions
httpContext.Request.Path.StartsWithSegments($"/{tenantResolvedContext.TenantInfo?.Identifier}",
out var matched, out var
newPath);
httpContext.Request.PathBase = Path.Combine(httpContext.Request.PathBase, matched);
httpContext.Request.PathBase = httpContext.Request.PathBase.Add(matched);
httpContext.Request.Path = newPath;
}
Expand Down
Expand Up @@ -13,11 +13,11 @@ namespace Finbuckle.MultiTenant.AspNetCore.Test.Strategies
{
public class BasePathStrategyShould
{
private HttpContext CreateHttpContextMock(string path)
private HttpContext CreateHttpContextMock(string path, string pathBase = "/")
{
var mock = new Mock<HttpContext>();
mock.SetupProperty<PathString>(c => c.Request.Path, path);
mock.SetupProperty<PathString>(c => c.Request.PathBase, "/");
mock.SetupProperty<PathString>(c => c.Request.PathBase, pathBase);
mock.SetupProperty(c => c.RequestServices);
return mock.Object;
}
Expand Down Expand Up @@ -104,5 +104,34 @@ public async void ThrowIfContextIsNotHttpContext()

await Assert.ThrowsAsync<MultiTenantException>(() => strategy.GetIdentifierAsync(context));
}

[Fact]
public async void AppendTenantToExistingBase()
{

var services = new ServiceCollection();
services.AddOptions().AddMultiTenant<TenantInfo>().WithBasePathStrategy().WithInMemoryStore(options =>
{
options.Tenants.Add(new TenantInfo
{
Id = "tenant",
Identifier = "tenant",
Name = "tenant"
});
});
services.Configure<BasePathStrategyOptions>(options => options.RebaseAspNetCorePathBase = true);
var serviceProvider = services.BuildServiceProvider();
var httpContext = CreateHttpContextMock("/tenant/path", "/base");
httpContext.RequestServices = serviceProvider;

Assert.Equal("/base", httpContext.Request.PathBase);
Assert.Equal("/tenant/path", httpContext.Request.Path);

// will trigger OnTenantFound event...
var resolver = await serviceProvider.GetRequiredService<ITenantResolver>().ResolveAsync(httpContext);

Assert.Equal("/base/tenant", httpContext.Request.PathBase);
Assert.Equal("/path", httpContext.Request.Path);
}
}
}

0 comments on commit 0628b0f

Please sign in to comment.