diff --git a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlProvider.cs b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlProvider.cs index 8bb3656fae..dc9a6102f8 100644 --- a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlProvider.cs +++ b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlProvider.cs @@ -86,7 +86,7 @@ public class AppUrlProvider : IAppUrlProvider, ITransientDependency { if (CurrentTenant.Id.HasValue) { - url = url.Replace(tenantNamePlaceHolder, await GetCurrentTenantNameAsync()); + url = url.Replace(tenantNamePlaceHolder, await GetCurrentTenantNameAsync() + "."); } else { diff --git a/framework/test/Volo.Abp.UI.Navigation.Tests/Volo/Abp/Ui/Navigation/AppUrlProvider_Tests.cs b/framework/test/Volo.Abp.UI.Navigation.Tests/Volo/Abp/Ui/Navigation/AppUrlProvider_Tests.cs new file mode 100644 index 0000000000..53ca25e7c7 --- /dev/null +++ b/framework/test/Volo.Abp.UI.Navigation.Tests/Volo/Abp/Ui/Navigation/AppUrlProvider_Tests.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Volo.Abp.MultiTenancy; +using Volo.Abp.Testing; +using Volo.Abp.UI.Navigation.Urls; +using Xunit; + +namespace Volo.Abp.UI.Navigation; + +public class AppUrlProvider_Tests : AbpIntegratedTest +{ + private readonly IAppUrlProvider _appUrlProvider; + private readonly ICurrentTenant _currentTenant; + + public AppUrlProvider_Tests() + { + _appUrlProvider = ServiceProvider.GetRequiredService(); + _currentTenant = ServiceProvider.GetRequiredService(); + } + + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) + { + options.UseAutofac(); + } + + protected override void AfterAddApplication(IServiceCollection services) + { + services.Configure(options => + { + options.Applications["MVC"].RootUrl = "https://{{tenantName}}.abp.io"; + options.Applications["MVC"].Urls["PasswordReset"] = "account/reset-password"; + options.RedirectAllowedUrls.AddRange(new List() + { + "https://wwww.volosoft.com", + "https://wwww.aspnetzero.com" + }); + + options.Applications["BLAZOR"].RootUrl = "https://{{tenantId}}.abp.io"; + options.Applications["BLAZOR"].Urls["PasswordReset"] = "account/reset-password"; + }); + } + + [Fact] + public async Task GetUrlAsync() + { + using (_currentTenant.Change(null)) + { + var url = await _appUrlProvider.GetUrlAsync("MVC"); + url.ShouldBe("https://abp.io"); + + url = await _appUrlProvider.GetUrlAsync("MVC", "PasswordReset"); + url.ShouldBe("https://abp.io/account/reset-password"); + } + + using (_currentTenant.Change(Guid.NewGuid(), "community")) + { + var url = await _appUrlProvider.GetUrlAsync("MVC"); + url.ShouldBe("https://community.abp.io"); + + url = await _appUrlProvider.GetUrlAsync("MVC", "PasswordReset"); + url.ShouldBe("https://community.abp.io/account/reset-password"); + } + + var tenantId = Guid.NewGuid(); + using (_currentTenant.Change(tenantId)) + { + var url = await _appUrlProvider.GetUrlAsync("BLAZOR"); + url.ShouldBe($"https://{tenantId}.abp.io"); + + url = await _appUrlProvider.GetUrlAsync("BLAZOR", "PasswordReset"); + url.ShouldBe($"https://{tenantId}.abp.io/account/reset-password"); + } + + await Assert.ThrowsAsync(async () => + { + await _appUrlProvider.GetUrlAsync("ANGULAR"); + }); + } + + [Fact] + public async Task GetUrlOrNullAsync() + { + (await _appUrlProvider.GetUrlOrNullAsync("ANGULAR")).ShouldBeNull(); + } + + [Fact] + public void IsRedirectAllowedUrl() + { + _appUrlProvider.IsRedirectAllowedUrl("https://community.abp.io").ShouldBeFalse(); + _appUrlProvider.IsRedirectAllowedUrl("https://wwww.volosoft.com").ShouldBeTrue(); + } +}