amended testing unit.

This commit is contained in:
Greenback 2020-11-04 20:29:55 +00:00
parent ec245dce90
commit 3e62557959
3 changed files with 16 additions and 14 deletions

View File

@ -19,6 +19,8 @@ namespace Jellyfin.Networking.Manager
{ {
/// <summary> /// <summary>
/// Class to take care of network interface management. /// Class to take care of network interface management.
///
/// Note: The normal collection methods and properties will not work with NetCollection. <see cref="MediaBrowser.Common.Net.NetworkExtensions"/>.
/// </summary> /// </summary>
public class NetworkManager : INetworkManager, IDisposable public class NetworkManager : INetworkManager, IDisposable
{ {
@ -925,8 +927,8 @@ namespace Jellyfin.Networking.Manager
// Read and parse bind addresses and exclusions, removing ones that don't exist. // Read and parse bind addresses and exclusions, removing ones that don't exist.
_bindAddresses = CreateIPCollection(lanAddresses).Union(_interfaceAddresses); _bindAddresses = CreateIPCollection(lanAddresses).Union(_interfaceAddresses);
_bindExclusions = CreateIPCollection(lanAddresses, true).Union(_interfaceAddresses); _bindExclusions = CreateIPCollection(lanAddresses, true).Union(_interfaceAddresses);
_logger.LogInformation("Using bind addresses: {0}", _bindAddresses); _logger.LogInformation("Using bind addresses: {0}", _bindAddresses.AsString());
_logger.LogInformation("Using bind exclusions: {0}", _bindExclusions); _logger.LogInformation("Using bind exclusions: {0}", _bindExclusions.AsString());
} }
private void InitialiseRemote(NetworkConfiguration config) private void InitialiseRemote(NetworkConfiguration config)
@ -997,9 +999,9 @@ namespace Jellyfin.Networking.Manager
_internalInterfaces = CreateCollection(_interfaceAddresses.Where(i => IsInLocalNetwork(i))); _internalInterfaces = CreateCollection(_interfaceAddresses.Where(i => IsInLocalNetwork(i)));
} }
_logger.LogInformation("Defined LAN addresses : {0}", _lanSubnets); _logger.LogInformation("Defined LAN addresses : {0}", _lanSubnets.AsString());
_logger.LogInformation("Defined LAN exclusions : {0}", _excludedSubnets); _logger.LogInformation("Defined LAN exclusions : {0}", _excludedSubnets.AsString());
_logger.LogInformation("Using LAN addresses: {0}", _lanSubnets.Exclude(_excludedSubnets).AsNetworks()); _logger.LogInformation("Using LAN addresses: {0}", _lanSubnets.Exclude(_excludedSubnets).AsNetworks().AsString());
} }
} }
@ -1090,7 +1092,7 @@ namespace Jellyfin.Networking.Manager
} }
_logger.LogDebug("Discovered {0} interfaces.", _interfaceAddresses.Count); _logger.LogDebug("Discovered {0} interfaces.", _interfaceAddresses.Count);
_logger.LogDebug("Interfaces addresses : {0}", _interfaceAddresses); _logger.LogDebug("Interfaces addresses : {0}", _interfaceAddresses.AsString());
// If for some reason we don't have an interface info, resolve our DNS name. // If for some reason we don't have an interface info, resolve our DNS name.
if (_interfaceAddresses.Count == 0) if (_interfaceAddresses.Count == 0)

View File

@ -45,7 +45,7 @@ namespace MediaBrowser.Common.Net
/// </summary> /// </summary>
/// <param name="source">The <see cref="NetCollection"/>.</param> /// <param name="source">The <see cref="NetCollection"/>.</param>
/// <returns>Returns a string representation of this object.</returns> /// <returns>Returns a string representation of this object.</returns>
public static string Readable(this NetCollection source) public static string AsString(this NetCollection source)
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
string output = "["; string output = "[";

View File

@ -71,7 +71,7 @@ namespace NetworkTesting
var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>()); var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
NetworkManager.MockNetworkSettings = string.Empty; NetworkManager.MockNetworkSettings = string.Empty;
Assert.True(string.Equals(nm.GetInternalBindAddresses().Readable(), value, StringComparison.Ordinal)); Assert.True(string.Equals(nm.GetInternalBindAddresses().AsString(), value, StringComparison.Ordinal));
} }
[Theory] [Theory]
@ -163,22 +163,22 @@ namespace NetworkTesting
// Test included, IP6. // Test included, IP6.
NetCollection nc = nm.CreateIPCollection(settings.Split(","), false); NetCollection nc = nm.CreateIPCollection(settings.Split(","), false);
Assert.True(string.Equals(nc.Readable(), result1, System.StringComparison.OrdinalIgnoreCase)); Assert.True(string.Equals(nc?.AsString(), result1, System.StringComparison.OrdinalIgnoreCase));
// Text excluded, non IP6. // Text excluded, non IP6.
nc = nm.CreateIPCollection(settings.Split(","), true); nc = nm.CreateIPCollection(settings.Split(","), true);
Assert.True(string.Equals(nc?.Readable(), result3, System.StringComparison.OrdinalIgnoreCase)); Assert.True(string.Equals(nc?.AsString(), result3, System.StringComparison.OrdinalIgnoreCase));
conf.EnableIPV6 = false; conf.EnableIPV6 = false;
nm.UpdateSettings(conf); nm.UpdateSettings(conf);
// Test included, non IP6. // Test included, non IP6.
nc = nm.CreateIPCollection(settings.Split(","), false); nc = nm.CreateIPCollection(settings.Split(","), false);
Assert.True(string.Equals(nc.Readable(), result2, System.StringComparison.OrdinalIgnoreCase)); Assert.True(string.Equals(nc?.AsString(), result2, System.StringComparison.OrdinalIgnoreCase));
// Test excluded, including IPv6. // Test excluded, including IPv6.
nc = nm.CreateIPCollection(settings.Split(","), true); nc = nm.CreateIPCollection(settings.Split(","), true);
Assert.True(string.Equals(nc.Readable(), result4, System.StringComparison.OrdinalIgnoreCase)); Assert.True(string.Equals(nc?.AsString(), result4, System.StringComparison.OrdinalIgnoreCase));
conf.EnableIPV6 = true; conf.EnableIPV6 = true;
nm.UpdateSettings(conf); nm.UpdateSettings(conf);
@ -186,7 +186,7 @@ namespace NetworkTesting
// Test network addresses of collection. // Test network addresses of collection.
nc = nm.CreateIPCollection(settings.Split(","), false); nc = nm.CreateIPCollection(settings.Split(","), false);
nc = nc.AsNetworks(); nc = nc.AsNetworks();
Assert.True(string.Equals(nc.Readable(), result5, System.StringComparison.OrdinalIgnoreCase)); Assert.True(string.Equals(nc?.AsString(), result5, System.StringComparison.OrdinalIgnoreCase));
} }
[Theory] [Theory]
@ -205,7 +205,7 @@ namespace NetworkTesting
NetCollection nc1 = nm.CreateIPCollection(settings.Split(","), false); NetCollection nc1 = nm.CreateIPCollection(settings.Split(","), false);
NetCollection nc2 = nm.CreateIPCollection(compare.Split(","), false); NetCollection nc2 = nm.CreateIPCollection(compare.Split(","), false);
Assert.True(nc1.Union(nc2).Readable() == result); Assert.True(nc1.Union(nc2).AsString() == result);
} }
[Theory] [Theory]