mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-19 09:42:29 +08:00
Upgrade host resolution (#8387)
* Reverted changes to RunningShellTable and then changed the way shells are sorted, so we can correctly give "priority" to tenants based on their prefix. Added test adapter reference to Orchard.Framework.Tests so tests can be run in the latest VS 2017. Fixed a test that was failing to account for the order the shells were being processed. * Removed some stuff from csproj that vs had added
This commit is contained in:
committed by
GitHub
parent
b528ecd1e0
commit
f67e6b3695
@@ -128,9 +128,10 @@ namespace Orchard.Tests.Environment {
|
|||||||
var settingsG = new ShellSettings { Name = "Gamma", RequestUrlHost = "wiki.example.com" };
|
var settingsG = new ShellSettings { Name = "Gamma", RequestUrlHost = "wiki.example.com" };
|
||||||
var settingsD = new ShellSettings { Name = "Delta", RequestUrlPrefix = "Quux" };
|
var settingsD = new ShellSettings { Name = "Delta", RequestUrlPrefix = "Quux" };
|
||||||
table.Add(settings);
|
table.Add(settings);
|
||||||
|
// add this shell first, because the order the shells where processed used to matter
|
||||||
|
table.Add(settingsG);
|
||||||
table.Add(settingsA);
|
table.Add(settingsA);
|
||||||
table.Add(settingsB);
|
table.Add(settingsB);
|
||||||
table.Add(settingsG);
|
|
||||||
table.Add(settingsD);
|
table.Add(settingsD);
|
||||||
|
|
||||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "wiki.example.com")), Is.EqualTo(settingsA).Using(new ShellComparer()));
|
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "wiki.example.com")), Is.EqualTo(settingsA).Using(new ShellComparer()));
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="..\packages\NUnitTestAdapter.2.3.0\build\NUnitTestAdapter.props" Condition="Exists('..\packages\NUnitTestAdapter.2.3.0\build\NUnitTestAdapter.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
|||||||
@@ -17,4 +17,5 @@
|
|||||||
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
|
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
|
||||||
<package id="NHibernate" version="4.0.1.4000" targetFramework="net452" />
|
<package id="NHibernate" version="4.0.1.4000" targetFramework="net452" />
|
||||||
<package id="NUnit" version="2.5.10.11092" targetFramework="net452" />
|
<package id="NUnit" version="2.5.10.11092" targetFramework="net452" />
|
||||||
|
<package id="NUnitTestAdapter" version="2.3.0" targetFramework="net452" />
|
||||||
</packages>
|
</packages>
|
||||||
@@ -84,7 +84,12 @@ namespace Orchard.Environment {
|
|||||||
.Select(h => new ShellSettings(s) {RequestUrlHost = h}))
|
.Select(h => new ShellSettings(s) {RequestUrlHost = h}))
|
||||||
.GroupBy(s => s.RequestUrlHost ?? string.Empty)
|
.GroupBy(s => s.RequestUrlHost ?? string.Empty)
|
||||||
.OrderByDescending(g => g.Key.Length)
|
.OrderByDescending(g => g.Key.Length)
|
||||||
.ToDictionary(x => x.Key, x => x.AsEnumerable(), StringComparer.OrdinalIgnoreCase);
|
.ToDictionary(
|
||||||
|
x => x.Key,
|
||||||
|
// we want to keep this ordered so that, for the same host, shells with a configured
|
||||||
|
// RequestUrlPrefix are tested first when trying to match them to coming requests.
|
||||||
|
x => x.OrderByDescending(ss => (ss.RequestUrlPrefix ?? "").Length).AsEnumerable(),
|
||||||
|
StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
if (unqualified.Count() == 1) {
|
if (unqualified.Count() == 1) {
|
||||||
// only one shell had no request url criteria
|
// only one shell had no request url criteria
|
||||||
@@ -164,20 +169,20 @@ namespace Orchard.Environment {
|
|||||||
shells = _shellsByHost[subHostKey];
|
shells = _shellsByHost[subHostKey];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// looking for a request url prefix match
|
// looking for a request url prefix match
|
||||||
var mostQualifiedMatch = shells.FirstOrDefault(settings => {
|
var mostQualifiedMatch = shells.FirstOrDefault(settings => {
|
||||||
if (settings.State == TenantState.Disabled) {
|
if (settings.State == TenantState.Disabled) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (String.IsNullOrWhiteSpace(settings.RequestUrlPrefix)) {
|
if (String.IsNullOrWhiteSpace(settings.RequestUrlPrefix)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return key.Equals(host + "/" + settings.RequestUrlPrefix, StringComparison.OrdinalIgnoreCase);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
return key.Equals(host + "/" + settings.RequestUrlPrefix, StringComparison.OrdinalIgnoreCase);
|
||||||
|
});
|
||||||
|
|
||||||
return mostQualifiedMatch ?? _fallback;
|
return mostQualifiedMatch ?? _fallback;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user