AddressRegistrationTests should get local IPs from System.Net.NetworkInformation (#796)

This commit is contained in:
Mike Harder 2016-07-11 14:40:12 -07:00 committed by GitHub
parent 82a0a99107
commit 8a43be94ef
2 changed files with 13 additions and 3 deletions

View File

@ -2,9 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
@ -166,7 +168,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
dataset.Add("http://127.0.0.1:0/", GetTestUrls);
dataset.Add($"http://{Dns.GetHostName()}:0/", GetTestUrls);
var ipv4Addresses = Dns.GetHostAddressesAsync(Dns.GetHostName()).Result
var ipv4Addresses = GetIPAddresses()
.Where(ip => ip.AddressFamily == AddressFamily.InterNetwork);
foreach (var ip in ipv4Addresses)
{
@ -224,7 +226,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
dataset.Add($"http://[::1]:{port1}/base/path", _ => new[] { $"http://[::1]:{port1}/base/path" });
// Dynamic port and non-loopback addresses
var ipv6Addresses = Dns.GetHostAddressesAsync(Dns.GetHostName()).Result
var ipv6Addresses = GetIPAddresses()
.Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6)
.Where(ip => ip.ScopeId == 0);
foreach (var ip in ipv6Addresses)
@ -258,7 +260,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
var dataset = new TheoryData<string, Func<IServerAddressesFeature, string[]>>();
// Dynamic port
var ipv6Addresses = Dns.GetHostAddressesAsync(Dns.GetHostName()).Result
var ipv6Addresses = GetIPAddresses()
.Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6)
.Where(ip => ip.ScopeId != 0);
foreach (var ip in ipv6Addresses)
@ -270,6 +272,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
}
}
private static IEnumerable<IPAddress> GetIPAddresses()
{
return NetworkInterface.GetAllNetworkInterfaces()
.SelectMany(i => i.GetIPProperties().UnicastAddresses)
.Select(a => a.Address);
}
private static string[] GetTestUrls(IServerAddressesFeature addressesFeature)
{
return addressesFeature.Addresses

View File

@ -19,6 +19,7 @@
},
"System.Net.Http": "4.1.0-*",
"System.Net.Http.WinHttpHandler": "4.0.0-*",
"System.Net.NetworkInformation": "4.1.0-*",
"System.Runtime.Serialization.Primitives": "4.1.1-*"
}
},