public async void LookupPrivateNetworkHostTestMethod() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string localHostname = Dns.GetHostName(); if (localHostname.EndsWith(STUNDns.MDNS_TLD)) { // TODO: Look into why DNS calls on macos cannot resolve domains ending in ".local" // RFC6762 domains. logger.LogWarning("Skipping unit test LookupPrivateNetworkHostTestMethod due to RFC6762 domain."); } else { logger.LogDebug($"Attempting DNS lookup for {localHostname}."); STUNUri.TryParse(localHostname, out var stunUri); var result = await STUNDns.Resolve(stunUri); Assert.NotNull(result); logger.LogDebug($"STUN DNS lookup for {stunUri} {result}."); } }
public async void LookupLocalhostIPv6TestMethod() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); STUNUri.TryParse("localhost", out var stunUri); var result = await STUNDns.Resolve(stunUri, true).ConfigureAwait(false); Assert.NotNull(result); logger.LogDebug($"STUN DNS lookup for {stunUri} resolved to {result}."); // Using System.Net.Dns.GetHostEntry doesn't return IPv6 results on Linux or WSL // even when there is an IPv6 address assigned. Works correctly on Mac and Windows. // Disabled the check below as it's not that important and requires different OS conditionals. // AC 09 Jun 2020. //if (Socket.OSSupportsIPv6 && System.Environment.OSVersion.Platform == System.PlatformID.Win32NT) //{ // Assert.Equal(IPAddress.IPv6Loopback, result.Address); //} //else //{ // Assert.Equal(IPAddress.Loopback, result.Address); //} }
public async void LookupNonExistentCanoncialHostTestMethod() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); STUNUri.TryParse("somehost.fsdfergerw.com", out var stunUri); var result = await STUNDns.Resolve(stunUri, true).ConfigureAwait(false); logger.LogDebug($"STUN DNS lookup for {stunUri} resolved to {result}."); Assert.Null(result); }
public async void LookupWithSRVTestMethod() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); STUNUri.TryParse("sipsorcery.com", out var stunUri); var result = await STUNDns.Resolve(stunUri).ConfigureAwait(false); Assert.NotNull(result); logger.LogDebug($"STUN DNS lookup for {stunUri} resolved to {result}."); }
public async void LookupNonExistentHostTestMethod() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); STUNUri.TryParse("idontexist", out var stunUri); var result = await STUNDns.Resolve(stunUri, true); logger.LogDebug($"STUN DNS lookup for {stunUri} {result}."); Assert.Null(result); }
public async void LookupHostWithExplicitPortTestMethod() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); STUNUri.TryParse("stun.sipsorcery.com:3478", out var stunUri); var result = await STUNDns.Resolve(stunUri); Assert.NotNull(result); logger.LogDebug($"STUN DNS lookup for {stunUri} {result}."); }
public async void LookupLocalhostTestMethod() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); STUNUri.TryParse("localhost", out var stunUri); var result = await STUNDns.Resolve(stunUri).ConfigureAwait(false); Assert.NotNull(result); Assert.Equal(IPAddress.Loopback, result.Address); logger.LogDebug($"STUN DNS lookup for {stunUri} resolved to {result}."); }
public async void LookupHostPreferIPv6FallbackTestMethod() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); STUNUri.TryParse("www.sipsorcery.com", out var stunUri); var result = await STUNDns.Resolve(stunUri, true).ConfigureAwait(false); logger.LogDebug($"STUN DNS lookup for {stunUri} resolved to {result}."); Assert.NotNull(result); Assert.Equal(AddressFamily.InterNetwork, result.AddressFamily); }
public async void LookupHostPreferIPv6TestMethod() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); STUNUri.TryParse("www.google.com", out var stunUri); var result = await STUNDns.Resolve(stunUri, true).ConfigureAwait(false); logger.LogDebug($"STUN DNS lookup for {stunUri} resolved to {result}."); Assert.NotNull(result); // There's no guarantee that a particular DNS server will have AAAA records for // a particular hostname so can't check which result type was returned. }
public async void LookupWithSRVTestPreferIPv6Method() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); STUNUri.TryParse("sipsorcery.com", out var stunUri); var result = await STUNDns.Resolve(stunUri, true); Assert.NotNull(result); // No IPv6 DNS record available so should fallback to IPv4. Assert.Equal(AddressFamily.InterNetwork, result.AddressFamily); logger.LogDebug($"STUN DNS lookup for {stunUri} {result}."); }
public async void LookupPrivateNetworkHostIPv6TestMethod() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string localHostname = Dns.GetHostName(); if (localHostname.EndsWith(STUNDns.MDNS_TLD)) { // TODO: Look into why DNS calls on macos cannot resolve domains ending in ".local" // RFC6762 domains. logger.LogWarning("Skipping unit test LookupPrivateNetworkHostIPv6TestMethod due to RFC6762 domain."); } else { STUNUri.TryParse(localHostname, out var stunUri); logger.LogDebug($"Attempting DNS lookup for {stunUri}."); var result = await STUNDns.Resolve(stunUri, true); Assert.NotNull(result); logger.LogDebug($"STUN DNS lookup for {stunUri} {result}."); } // Using System.Net.Dns.GetHostEntry doesn't return IPv6 results on Linux or WSL // even when there is an IPv6 address assigned. Works correctly on Mac and Windows. // Disabled the check below as it's not that important and requires different OS conditionals. // AC 09 Jun 2020. //if (Socket.OSSupportsIPv6 && System.Environment.OSVersion.Platform == System.PlatformID.Win32NT) //{ // Assert.Equal(AddressFamily.InterNetworkV6, result.AddressFamily); //} //else //{ // Assert.Equal(AddressFamily.InterNetwork, result.AddressFamily); //} }
public async void LookupPrivateNetworkHostTestMethod() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string localHostname = Dns.GetHostName(); if (localHostname.EndsWith(STUNDns.MDNS_TLD)) { logger.LogWarning("Skipping unit test due to RFC6762 domain."); } else { logger.LogDebug($"Attempting DNS lookup for {localHostname}."); STUNUri.TryParse(localHostname, out var stunUri); var result = await STUNDns.Resolve(stunUri).ConfigureAwait(false); Assert.NotNull(result); logger.LogDebug($"STUN DNS lookup for {stunUri} resolved to {result}."); } }