mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-09 11:21:04 +08:00
Fixing tenants unit tests
This commit is contained in:
@@ -182,6 +182,19 @@ namespace Orchard.Tests.Environment {
|
||||
var settingsA = new ShellSettings { Name = "Alpha", RequestUrlHost = "example.com" };
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "www.example.com")), Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "wiki.example.com")), Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "example.com")), Is.EqualTo(settingsA).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "localhost")), Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HostNameMatchesRightmostIfStar() {
|
||||
var table = (IRunningShellTable)new RunningShellTable();
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName };
|
||||
var settingsA = new ShellSettings { Name = "Alpha", RequestUrlHost = "*.example.com" };
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "www.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()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "example.com")), Is.EqualTo(settingsA).Using(new ShellComparer()));
|
||||
@@ -193,7 +206,7 @@ namespace Orchard.Tests.Environment {
|
||||
var table = (IRunningShellTable) new RunningShellTable();
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName };
|
||||
var settingsA = new ShellSettings { Name = "Alpha", RequestUrlHost = "www.example.com" };
|
||||
var settingsB = new ShellSettings { Name = "Beta", RequestUrlHost = "example.com" };
|
||||
var settingsB = new ShellSettings { Name = "Beta", RequestUrlHost = "*.example.com" };
|
||||
var settingsG = new ShellSettings { Name = "Gamma", RequestUrlHost = "wiki.example.com" };
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<label for="@Html.FieldIdFor(m => m.RequestUrlHost)">@T("Host")</label>
|
||||
@Html.TextBoxFor(m => m.RequestUrlHost, new { @class = "text medium" })
|
||||
<span class="hint">@T("Example: If host is \"orchardproject.net\", the tenant site URL is \"http://orchardproject.net/\"")</span>
|
||||
<span class="hint">@T("You may define multiple domains using the comma (,) as a separator. Use the '*.' prefix to map all subdomains.")</span>
|
||||
</div>
|
||||
<div>
|
||||
<label for="@Html.FieldIdFor(m => m.RequestUrlPrefix)">@T("URL prefix")</label>
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Orchard.Environment {
|
||||
public class RunningShellTable : IRunningShellTable {
|
||||
private IEnumerable<ShellSettings> _shells = Enumerable.Empty<ShellSettings>();
|
||||
private IDictionary<string, IEnumerable<ShellSettings>> _shellsByHost;
|
||||
private ConcurrentDictionary<string, ShellSettings> _shellsByHostAndPrefix = new ConcurrentDictionary<string, ShellSettings>(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly ConcurrentDictionary<string, ShellSettings> _shellsByHostAndPrefix = new ConcurrentDictionary<string, ShellSettings>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
private ShellSettings _fallback;
|
||||
private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();
|
||||
@@ -111,6 +111,10 @@ namespace Orchard.Environment {
|
||||
public ShellSettings Match(string host, string appRelativePath) {
|
||||
_lock.EnterReadLock();
|
||||
try {
|
||||
if (_shellsByHost == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// optimized path when only one tenant (Default), configured with no custom host
|
||||
if (!_shellsByHost.Any() && _fallback != null) {
|
||||
return _fallback;
|
||||
@@ -127,8 +131,24 @@ namespace Orchard.Environment {
|
||||
return _shellsByHostAndPrefix.GetOrAdd(hostAndPrefix, key => {
|
||||
|
||||
// filtering shells by host
|
||||
var shells = _shellsByHost.ContainsKey(host) ? _shellsByHost[host] : _shellsByHost[""];
|
||||
IEnumerable<ShellSettings> shells;
|
||||
|
||||
if (!_shellsByHost.TryGetValue(host, out shells)) {
|
||||
if (!_shellsByHost.TryGetValue("", out shells)) {
|
||||
|
||||
// no specific match, then look for star mapping
|
||||
var subHostKey = _shellsByHost.Keys.FirstOrDefault(x =>
|
||||
x.StartsWith("*.") && host.EndsWith(x.Substring(2))
|
||||
);
|
||||
|
||||
if (subHostKey == null) {
|
||||
return _fallback;
|
||||
}
|
||||
|
||||
shells = _shellsByHost[subHostKey];
|
||||
}
|
||||
}
|
||||
|
||||
// looking for a request url prefix match
|
||||
var mostQualifiedMatch = shells.FirstOrDefault(settings => {
|
||||
if (settings.State == TenantState.Disabled) {
|
||||
|
||||
Reference in New Issue
Block a user