Browse Source
Do not short-circuit tenant resolver chain when query string tenant value is blank
pull/25212/head
maliming
4 months ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
2 changed files with
18 additions and
5 deletions
-
framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/QueryStringTenantResolveContributor.cs
-
framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancy_Without_DomainResolver_Tests.cs
|
|
|
@ -19,13 +19,10 @@ public class QueryStringTenantResolveContributor : HttpTenantResolveContributorB |
|
|
|
if (httpContext.Request.Query.ContainsKey(tenantKey)) |
|
|
|
{ |
|
|
|
var tenantValue = httpContext.Request.Query[tenantKey].ToString(); |
|
|
|
if (tenantValue.IsNullOrWhiteSpace()) |
|
|
|
if (!tenantValue.IsNullOrWhiteSpace()) |
|
|
|
{ |
|
|
|
context.Handled = true; |
|
|
|
return Task.FromResult<string?>(null); |
|
|
|
return Task.FromResult(tenantValue)!; |
|
|
|
} |
|
|
|
|
|
|
|
return Task.FromResult(tenantValue)!; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -70,4 +70,20 @@ public class AspNetCoreMultiTenancy_Without_DomainResolver_Tests : AspNetCoreMul |
|
|
|
var result = await GetResponseAsObjectAsync<Dictionary<string, string>>("http://abp.io"); |
|
|
|
result["TenantId"].ShouldBe(_testTenantId.ToString()); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_Use_Header_Tenant_Id_When_QueryString_Tenant_Is_Empty() |
|
|
|
{ |
|
|
|
Client.DefaultRequestHeaders.Add(_options.TenantKey, _testTenantId.ToString()); |
|
|
|
|
|
|
|
var result = await GetResponseAsObjectAsync<Dictionary<string, string>>($"http://abp.io?{_options.TenantKey}="); |
|
|
|
result["TenantId"].ShouldBe(_testTenantId.ToString()); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_Fallback_To_Host_When_QueryString_Tenant_Is_Empty_And_No_Other_Resolver() |
|
|
|
{ |
|
|
|
var result = await GetResponseAsObjectAsync<Dictionary<string, string>>($"http://abp.io?{_options.TenantKey}="); |
|
|
|
result["TenantId"].ShouldBe(""); |
|
|
|
} |
|
|
|
} |
|
|
|
|