Don't bind if only port is specified (#814) (#861)

- Also renamed ServerAddressFacts to ServerAddressTests to match existing test classes
This commit is contained in:
Mike Harder 2016-05-23 14:06:46 -07:00
parent 6098880132
commit 5ca6592677
3 changed files with 6 additions and 16 deletions

View File

@ -78,17 +78,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel
int schemeDelimiterStart = url.IndexOf("://", StringComparison.Ordinal);
if (schemeDelimiterStart < 0)
{
int port;
if (int.TryParse(url, NumberStyles.None, CultureInfo.InvariantCulture, out port))
{
return new ServerAddress()
{
Scheme = "http",
Host = "+",
Port = port,
PathBase = "/"
};
}
return null;
}
int schemeDelimiterEnd = schemeDelimiterStart + "://".Length;

View File

@ -97,8 +97,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
// Static port
var port1 = GetNextPort();
var port2 = GetNextPort();
dataset.Add($"{port1}", _ => new[] { $"http://localhost:{port1}/" });
dataset.Add($"{port1};{port2}", _ => new[] { $"http://localhost:{port1}/", $"http://localhost:{port2}/" });
// Ensure multiple addresses can be separated by semicolon
dataset.Add($"http://localhost:{port1};http://localhost:{port2}",
_ => new[] { $"http://localhost:{port1}/", $"http://localhost:{port2}/" });
// Ensure "localhost" and "127.0.0.1" are equivalent
dataset.Add($"http://localhost:{port1}", _ => new[] { $"http://localhost:{port1}/", $"http://127.0.0.1:{port1}/" });
@ -108,7 +110,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
dataset.Add($"http://localhost:{port1}/base/path", _ => new[] { $"http://localhost:{port1}/base/path" });
// Dynamic port
dataset.Add("0", GetTestUrls);
dataset.Add("http://localhost:0/", GetTestUrls);
dataset.Add($"http://{Dns.GetHostName()}:0/", GetTestUrls);

View File

@ -8,10 +8,11 @@ using Xunit;
namespace Microsoft.AspNetCore.Server.KestrelTests
{
public class ServerAddressFacts
public class ServerAddressTests
{
[Theory]
[InlineData("")]
[InlineData("5000")]
[InlineData("//noscheme")]
public void FromUriReturnsNullForSchemelessUrls(string url)
{
@ -19,7 +20,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
}
[Theory]
[InlineData("5000", "http", "+", 5000, "/", "http://+:5000/")]
[InlineData("://emptyscheme", "", "emptyscheme", 0, "", "://emptyscheme:0")]
[InlineData("http://localhost", "http", "localhost", 80, "", "http://localhost:80")]
[InlineData("http://www.example.com", "http", "www.example.com", 80, "", "http://www.example.com:80")]