NetworkParseTests.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. using System;
  2. using System.Net;
  3. using Jellyfin.Networking.Configuration;
  4. using Jellyfin.Networking.Manager;
  5. using MediaBrowser.Common.Configuration;
  6. using MediaBrowser.Common.Net;
  7. using Moq;
  8. using Microsoft.Extensions.Logging.Abstractions;
  9. using Xunit;
  10. using System.Collections.ObjectModel;
  11. namespace Jellyfin.Networking.Tests
  12. {
  13. public class NetworkParseTests
  14. {
  15. private static IConfigurationManager GetMockConfig(NetworkConfiguration conf)
  16. {
  17. var configManager = new Mock<IConfigurationManager>
  18. {
  19. CallBase = true
  20. };
  21. configManager.Setup(x => x.GetConfiguration(It.IsAny<string>())).Returns(conf);
  22. return (IConfigurationManager)configManager.Object;
  23. }
  24. /// <summary>
  25. /// Checks the ability to ignore interfaces
  26. /// </summary>
  27. /// <param name="interfaces">Mock network setup, in the format (IP address, interface index, interface name) | .... </param>
  28. /// <param name="lan">LAN addresses.</param>
  29. /// <param name="value">Bind addresses that are excluded.</param>
  30. [Theory]
  31. [InlineData("192.168.1.208/24,-16,eth16|200.200.200.200/24,11,eth11", "192.168.1.0/24;200.200.200.0/24", "[192.168.1.208/24,200.200.200.200/24]")]
  32. [InlineData("192.168.1.208/24,-16,eth16|200.200.200.200/24,11,eth11", "192.168.1.0/24", "[192.168.1.208/24]")]
  33. [InlineData("192.168.1.208/24,-16,vEthernet1|192.168.1.208/24,-16,vEthernet212|200.200.200.200/24,11,eth11", "192.168.1.0/24", "[192.168.1.208/24]")]
  34. public void IgnoreVirtualInterfaces(string interfaces, string lan, string value)
  35. {
  36. var conf = new NetworkConfiguration()
  37. {
  38. EnableIPV6 = true,
  39. EnableIPV4 = true,
  40. LocalNetworkSubnets = lan?.Split(';') ?? throw new ArgumentNullException(nameof(lan))
  41. };
  42. NetworkManager.MockNetworkSettings = interfaces;
  43. using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
  44. NetworkManager.MockNetworkSettings = string.Empty;
  45. Assert.Equal(nm.GetInternalBindAddresses().AsString(), value);
  46. }
  47. /// <summary>
  48. /// Check that the value given is in the network provided.
  49. /// </summary>
  50. /// <param name="network">Network address.</param>
  51. /// <param name="value">Value to check.</param>
  52. [Theory]
  53. [InlineData("192.168.10.0/24, !192.168.10.60/32", "192.168.10.60")]
  54. public void IsInNetwork(string network, string value)
  55. {
  56. if (network == null)
  57. {
  58. throw new ArgumentNullException(nameof(network));
  59. }
  60. var conf = new NetworkConfiguration()
  61. {
  62. EnableIPV6 = true,
  63. EnableIPV4 = true,
  64. LocalNetworkSubnets = network.Split(',')
  65. };
  66. using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
  67. Assert.False(nm.IsInLocalNetwork(value));
  68. }
  69. /// <summary>
  70. /// Checks IP address formats.
  71. /// </summary>
  72. /// <param name="address"></param>
  73. [Theory]
  74. [InlineData("127.0.0.1")]
  75. [InlineData("127.0.0.1:123")]
  76. [InlineData("localhost")]
  77. [InlineData("localhost:1345")]
  78. [InlineData("www.google.co.uk")]
  79. [InlineData("fd23:184f:2029:0:3139:7386:67d7:d517")]
  80. [InlineData("fd23:184f:2029:0:3139:7386:67d7:d517/56")]
  81. [InlineData("[fd23:184f:2029:0:3139:7386:67d7:d517]:124")]
  82. [InlineData("fe80::7add:12ff:febb:c67b%16")]
  83. [InlineData("[fe80::7add:12ff:febb:c67b%16]:123")]
  84. [InlineData("fe80::7add:12ff:febb:c67b%16:123")]
  85. [InlineData("[fe80::7add:12ff:febb:c67b%16]")]
  86. [InlineData("192.168.1.2/255.255.255.0")]
  87. [InlineData("192.168.1.2/24")]
  88. public void ValidHostStrings(string address)
  89. {
  90. Assert.True(IPHost.TryParse(address, out _));
  91. }
  92. /// <summary>
  93. /// Checks IP address formats.
  94. /// </summary>
  95. /// <param name="address"></param>
  96. [Theory]
  97. [InlineData("127.0.0.1")]
  98. [InlineData("fd23:184f:2029:0:3139:7386:67d7:d517")]
  99. [InlineData("fd23:184f:2029:0:3139:7386:67d7:d517/56")]
  100. [InlineData("[fd23:184f:2029:0:3139:7386:67d7:d517]")]
  101. [InlineData("fe80::7add:12ff:febb:c67b%16")]
  102. [InlineData("[fe80::7add:12ff:febb:c67b%16]:123")]
  103. [InlineData("fe80::7add:12ff:febb:c67b%16:123")]
  104. [InlineData("[fe80::7add:12ff:febb:c67b%16]")]
  105. [InlineData("192.168.1.2/255.255.255.0")]
  106. [InlineData("192.168.1.2/24")]
  107. public void ValidIPStrings(string address)
  108. {
  109. Assert.True(IPNetAddress.TryParse(address, out _));
  110. }
  111. /// <summary>
  112. /// All should be invalid address strings.
  113. /// </summary>
  114. /// <param name="address">Invalid address strings.</param>
  115. [Theory]
  116. [InlineData("256.128.0.0.0.1")]
  117. [InlineData("127.0.0.1#")]
  118. [InlineData("localhost!")]
  119. [InlineData("fd23:184f:2029:0:3139:7386:67d7:d517:1231")]
  120. [InlineData("[fd23:184f:2029:0:3139:7386:67d7:d517:1231]")]
  121. public void InvalidAddressString(string address)
  122. {
  123. Assert.False(IPNetAddress.TryParse(address, out _));
  124. Assert.False(IPHost.TryParse(address, out _));
  125. }
  126. /// <summary>
  127. /// Test collection parsing.
  128. /// </summary>
  129. /// <param name="settings">Collection to parse.</param>
  130. /// <param name="result1">Included addresses from the collection.</param>
  131. /// <param name="result2">Included IP4 addresses from the collection.</param>
  132. /// <param name="result3">Excluded addresses from the collection.</param>
  133. /// <param name="result4">Excluded IP4 addresses from the collection.</param>
  134. /// <param name="result5">Network addresses of the collection.</param>
  135. [Theory]
  136. [InlineData("127.0.0.1#",
  137. "[]",
  138. "[]",
  139. "[]",
  140. "[]",
  141. "[]")]
  142. [InlineData("!127.0.0.1",
  143. "[]",
  144. "[]",
  145. "[127.0.0.1/32]",
  146. "[127.0.0.1/32]",
  147. "[]")]
  148. [InlineData("",
  149. "[]",
  150. "[]",
  151. "[]",
  152. "[]",
  153. "[]")]
  154. [InlineData(
  155. "192.158.1.2/16, localhost, fd23:184f:2029:0:3139:7386:67d7:d517, !10.10.10.10",
  156. "[192.158.1.2/16,[127.0.0.1/32,::1/128],fd23:184f:2029:0:3139:7386:67d7:d517/128]",
  157. "[192.158.1.2/16,127.0.0.1/32]",
  158. "[10.10.10.10/32]",
  159. "[10.10.10.10/32]",
  160. "[192.158.0.0/16,127.0.0.1/32,::1/128,fd23:184f:2029:0:3139:7386:67d7:d517/128]")]
  161. [InlineData("192.158.1.2/255.255.0.0,192.169.1.2/8",
  162. "[192.158.1.2/16,192.169.1.2/8]",
  163. "[192.158.1.2/16,192.169.1.2/8]",
  164. "[]",
  165. "[]",
  166. "[192.158.0.0/16,192.0.0.0/8]")]
  167. public void TestCollections(string settings, string result1, string result2, string result3, string result4, string result5)
  168. {
  169. if (settings == null)
  170. {
  171. throw new ArgumentNullException(nameof(settings));
  172. }
  173. var conf = new NetworkConfiguration()
  174. {
  175. EnableIPV6 = true,
  176. EnableIPV4 = true,
  177. };
  178. using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
  179. // Test included.
  180. Collection<IPObject> nc = nm.CreateIPCollection(settings.Split(","), false);
  181. Assert.Equal(nc.AsString(), result1);
  182. // Test excluded.
  183. nc = nm.CreateIPCollection(settings.Split(","), true);
  184. Assert.Equal(nc.AsString(), result3);
  185. conf.EnableIPV6 = false;
  186. nm.UpdateSettings(conf);
  187. // Test IP4 included.
  188. nc = nm.CreateIPCollection(settings.Split(","), false);
  189. Assert.Equal(nc.AsString(), result2);
  190. // Test IP4 excluded.
  191. nc = nm.CreateIPCollection(settings.Split(","), true);
  192. Assert.Equal(nc.AsString(), result4);
  193. conf.EnableIPV6 = true;
  194. nm.UpdateSettings(conf);
  195. // Test network addresses of collection.
  196. nc = nm.CreateIPCollection(settings.Split(","), false);
  197. nc = nc.AsNetworks();
  198. Assert.Equal(nc.AsString(), result5);
  199. }
  200. /// <summary>
  201. /// Union two collections.
  202. /// </summary>
  203. /// <param name="settings">Source.</param>
  204. /// <param name="compare">Destination.</param>
  205. /// <param name="result">Result.</param>
  206. [Theory]
  207. [InlineData("127.0.0.1", "fd23:184f:2029:0:3139:7386:67d7:d517/64,fd23:184f:2029:0:c0f0:8a8a:7605:fffa/128,fe80::3139:7386:67d7:d517%16/64,192.168.1.208/24,::1/128,127.0.0.1/8", "[127.0.0.1/32]")]
  208. [InlineData("127.0.0.1", "127.0.0.1/8", "[127.0.0.1/32]")]
  209. public void UnionCheck(string settings, string compare, string result)
  210. {
  211. if (settings == null)
  212. {
  213. throw new ArgumentNullException(nameof(settings));
  214. }
  215. if (compare == null)
  216. {
  217. throw new ArgumentNullException(nameof(compare));
  218. }
  219. if (result == null)
  220. {
  221. throw new ArgumentNullException(nameof(result));
  222. }
  223. var conf = new NetworkConfiguration()
  224. {
  225. EnableIPV6 = true,
  226. EnableIPV4 = true,
  227. };
  228. using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
  229. Collection<IPObject> nc1 = nm.CreateIPCollection(settings.Split(","), false);
  230. Collection<IPObject> nc2 = nm.CreateIPCollection(compare.Split(","), false);
  231. Assert.Equal(nc1.Union(nc2).AsString(), result);
  232. }
  233. [Theory]
  234. [InlineData("192.168.5.85/24", "192.168.5.1")]
  235. [InlineData("192.168.5.85/24", "192.168.5.254")]
  236. [InlineData("10.128.240.50/30", "10.128.240.48")]
  237. [InlineData("10.128.240.50/30", "10.128.240.49")]
  238. [InlineData("10.128.240.50/30", "10.128.240.50")]
  239. [InlineData("10.128.240.50/30", "10.128.240.51")]
  240. [InlineData("127.0.0.1/8", "127.0.0.1")]
  241. public void IpV4SubnetMaskMatchesValidIpAddress(string netMask, string ipAddress)
  242. {
  243. var ipAddressObj = IPNetAddress.Parse(netMask);
  244. Assert.True(ipAddressObj.Contains(IPAddress.Parse(ipAddress)));
  245. }
  246. [Theory]
  247. [InlineData("192.168.5.85/24", "192.168.4.254")]
  248. [InlineData("192.168.5.85/24", "191.168.5.254")]
  249. [InlineData("10.128.240.50/30", "10.128.240.47")]
  250. [InlineData("10.128.240.50/30", "10.128.240.52")]
  251. [InlineData("10.128.240.50/30", "10.128.239.50")]
  252. [InlineData("10.128.240.50/30", "10.127.240.51")]
  253. public void IpV4SubnetMaskDoesNotMatchInvalidIpAddress(string netMask, string ipAddress)
  254. {
  255. var ipAddressObj = IPNetAddress.Parse(netMask);
  256. Assert.False(ipAddressObj.Contains(IPAddress.Parse(ipAddress)));
  257. }
  258. [Theory]
  259. [InlineData("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0012:0000:0000:0000:0000")]
  260. [InlineData("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0012:FFFF:FFFF:FFFF:FFFF")]
  261. [InlineData("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0012:0001:0000:0000:0000")]
  262. [InlineData("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0012:FFFF:FFFF:FFFF:FFF0")]
  263. [InlineData("2001:db8:abcd:0012::0/128", "2001:0DB8:ABCD:0012:0000:0000:0000:0000")]
  264. public void IpV6SubnetMaskMatchesValidIpAddress(string netMask, string ipAddress)
  265. {
  266. var ipAddressObj = IPNetAddress.Parse(netMask);
  267. Assert.True(ipAddressObj.Contains(IPAddress.Parse(ipAddress)));
  268. }
  269. [Theory]
  270. [InlineData("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0011:FFFF:FFFF:FFFF:FFFF")]
  271. [InlineData("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0013:0000:0000:0000:0000")]
  272. [InlineData("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0013:0001:0000:0000:0000")]
  273. [InlineData("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0011:FFFF:FFFF:FFFF:FFF0")]
  274. [InlineData("2001:db8:abcd:0012::0/128", "2001:0DB8:ABCD:0012:0000:0000:0000:0001")]
  275. public void IpV6SubnetMaskDoesNotMatchInvalidIpAddress(string netMask, string ipAddress)
  276. {
  277. var ipAddressObj = IPNetAddress.Parse(netMask);
  278. Assert.False(ipAddressObj.Contains(IPAddress.Parse(ipAddress)));
  279. }
  280. [Theory]
  281. [InlineData("10.0.0.0/255.0.0.0", "10.10.10.1/32")]
  282. [InlineData("10.0.0.0/8", "10.10.10.1/32")]
  283. [InlineData("10.0.0.0/255.0.0.0", "10.10.10.1")]
  284. [InlineData("10.10.0.0/255.255.0.0", "10.10.10.1/32")]
  285. [InlineData("10.10.0.0/16", "10.10.10.1/32")]
  286. [InlineData("10.10.0.0/255.255.0.0", "10.10.10.1")]
  287. [InlineData("10.10.10.0/255.255.255.0", "10.10.10.1/32")]
  288. [InlineData("10.10.10.0/24", "10.10.10.1/32")]
  289. [InlineData("10.10.10.0/255.255.255.0", "10.10.10.1")]
  290. public void TestSubnetContains(string network, string ip)
  291. {
  292. Assert.True(IPNetAddress.TryParse(network, out var networkObj));
  293. Assert.True(IPNetAddress.TryParse(ip, out var ipObj));
  294. Assert.True(networkObj.Contains(ipObj));
  295. }
  296. [Theory]
  297. [InlineData("192.168.1.2/24,10.10.10.1/24,172.168.1.2/24", "172.168.1.2/24", "172.168.1.2/24")]
  298. [InlineData("192.168.1.2/24,10.10.10.1/24,172.168.1.2/24", "172.168.1.2/24, 10.10.10.1", "172.168.1.2/24,10.10.10.1/24")]
  299. [InlineData("192.168.1.2/24,10.10.10.1/24,172.168.1.2/24", "192.168.1.2/255.255.255.0, 10.10.10.1", "192.168.1.2/24,10.10.10.1/24")]
  300. [InlineData("192.168.1.2/24,10.10.10.1/24,172.168.1.2/24", "192.168.1.2/24, 100.10.10.1", "192.168.1.2/24")]
  301. [InlineData("192.168.1.2/24,10.10.10.1/24,172.168.1.2/24", "194.168.1.2/24, 100.10.10.1", "")]
  302. public void TestCollectionEquality(string source, string dest, string result)
  303. {
  304. if (source == null)
  305. {
  306. throw new ArgumentNullException(nameof(source));
  307. }
  308. if (dest == null)
  309. {
  310. throw new ArgumentNullException(nameof(dest));
  311. }
  312. if (result == null)
  313. {
  314. throw new ArgumentNullException(nameof(result));
  315. }
  316. var conf = new NetworkConfiguration()
  317. {
  318. EnableIPV6 = true,
  319. EnableIPV4 = true
  320. };
  321. using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
  322. // Test included, IP6.
  323. Collection<IPObject> ncSource = nm.CreateIPCollection(source.Split(","));
  324. Collection<IPObject> ncDest = nm.CreateIPCollection(dest.Split(","));
  325. Collection<IPObject> ncResult = ncSource.Union(ncDest);
  326. Collection<IPObject> resultCollection = nm.CreateIPCollection(result.Split(","));
  327. Assert.True(ncResult.Compare(resultCollection));
  328. }
  329. [Theory]
  330. [InlineData("10.1.1.1/32", "10.1.1.1")]
  331. [InlineData("192.168.1.254/32", "192.168.1.254/255.255.255.255")]
  332. public void TestEquals(string source, string dest)
  333. {
  334. Assert.True(IPNetAddress.Parse(source).Equals(IPNetAddress.Parse(dest)));
  335. Assert.True(IPNetAddress.Parse(dest).Equals(IPNetAddress.Parse(source)));
  336. }
  337. [Theory]
  338. // Testing bind interfaces.
  339. // On my system eth16 is internal, eth11 external (Windows defines the indexes).
  340. //
  341. // This test is to replicate how DNLA requests work throughout the system.
  342. // User on internal network, we're bound internal and external - so result is internal.
  343. [InlineData("192.168.1.1", "eth16,eth11", false, "eth16")]
  344. // User on external network, we're bound internal and external - so result is external.
  345. [InlineData("8.8.8.8", "eth16,eth11", false, "eth11")]
  346. // User on internal network, we're bound internal only - so result is internal.
  347. [InlineData("10.10.10.10", "eth16", false, "eth16")]
  348. // User on internal network, no binding specified - so result is the 1st internal.
  349. [InlineData("192.168.1.1", "", false, "eth16")]
  350. // User on external network, internal binding only - so result is the 1st internal.
  351. [InlineData("jellyfin.org", "eth16", false, "eth16")]
  352. // User on external network, no binding - so result is the 1st external.
  353. [InlineData("jellyfin.org", "", false, "eth11")]
  354. // User assumed to be internal, no binding - so result is the 1st internal.
  355. [InlineData("", "", false, "eth16")]
  356. public void TestBindInterfaces(string source, string bindAddresses, bool ipv6enabled, string result)
  357. {
  358. if (source == null)
  359. {
  360. throw new ArgumentNullException(nameof(source));
  361. }
  362. if (bindAddresses == null)
  363. {
  364. throw new ArgumentNullException(nameof(bindAddresses));
  365. }
  366. if (result == null)
  367. {
  368. throw new ArgumentNullException(nameof(result));
  369. }
  370. var conf = new NetworkConfiguration()
  371. {
  372. LocalNetworkAddresses = bindAddresses.Split(','),
  373. EnableIPV6 = ipv6enabled,
  374. EnableIPV4 = true
  375. };
  376. NetworkManager.MockNetworkSettings = "192.168.1.208/24,-16,eth16|200.200.200.200/24,11,eth11";
  377. using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
  378. NetworkManager.MockNetworkSettings = string.Empty;
  379. _ = nm.TryParseInterface(result, out Collection<IPObject>? resultObj);
  380. if (resultObj != null)
  381. {
  382. result = ((IPNetAddress)resultObj[0]).ToString(true);
  383. var intf = nm.GetBindInterface(source, out int? _);
  384. Assert.Equal(intf, result);
  385. }
  386. }
  387. [Theory]
  388. // Testing bind interfaces. These are set for my system so won't work elsewhere.
  389. // On my system eth16 is internal, eth11 external (Windows defines the indexes).
  390. //
  391. // This test is to replicate how subnet bound ServerPublisherUri work throughout the system.
  392. // User on internal network, we're bound internal and external - so result is internal override.
  393. [InlineData("192.168.1.1", "192.168.1.0/24", "eth16,eth11", false, "192.168.1.0/24=internal.jellyfin", "internal.jellyfin")]
  394. // User on external network, we're bound internal and external - so result is override.
  395. [InlineData("8.8.8.8", "192.168.1.0/24", "eth16,eth11", false, "0.0.0.0=http://helloworld.com", "http://helloworld.com")]
  396. // User on internal network, we're bound internal only, but the address isn't in the LAN - so return the override.
  397. [InlineData("10.10.10.10", "192.168.1.0/24", "eth16", false, "0.0.0.0=http://internalButNotDefinedAsLan.com", "http://internalButNotDefinedAsLan.com")]
  398. // User on internal network, no binding specified - so result is the 1st internal.
  399. [InlineData("192.168.1.1", "192.168.1.0/24", "", false, "0.0.0.0=http://helloworld.com", "eth16")]
  400. // User on external network, internal binding only - so assumption is a proxy forward, return external override.
  401. [InlineData("jellyfin.org", "192.168.1.0/24", "eth16", false, "0.0.0.0=http://helloworld.com", "http://helloworld.com")]
  402. // User on external network, no binding - so result is the 1st external which is overriden.
  403. [InlineData("jellyfin.org", "192.168.1.0/24", "", false, "0.0.0.0 = http://helloworld.com", "http://helloworld.com")]
  404. // User assumed to be internal, no binding - so result is the 1st internal.
  405. [InlineData("", "192.168.1.0/24", "", false, "0.0.0.0=http://helloworld.com", "eth16")]
  406. // User is internal, no binding - so result is the 1st internal, which is then overridden.
  407. [InlineData("192.168.1.1", "192.168.1.0/24", "", false, "eth16=http://helloworld.com", "http://helloworld.com")]
  408. public void TestBindInterfaceOverrides(string source, string lan, string bindAddresses, bool ipv6enabled, string publishedServers, string result)
  409. {
  410. if (lan == null)
  411. {
  412. throw new ArgumentNullException(nameof(lan));
  413. }
  414. if (bindAddresses == null)
  415. {
  416. throw new ArgumentNullException(nameof(bindAddresses));
  417. }
  418. var conf = new NetworkConfiguration()
  419. {
  420. LocalNetworkSubnets = lan.Split(','),
  421. LocalNetworkAddresses = bindAddresses.Split(','),
  422. EnableIPV6 = ipv6enabled,
  423. EnableIPV4 = true,
  424. PublishedServerUriBySubnet = new string[] { publishedServers }
  425. };
  426. NetworkManager.MockNetworkSettings = "192.168.1.208/24,-16,eth16|200.200.200.200/24,11,eth11";
  427. using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
  428. NetworkManager.MockNetworkSettings = string.Empty;
  429. if (nm.TryParseInterface(result, out Collection<IPObject>? resultObj) && resultObj != null)
  430. {
  431. // Parse out IPAddresses so we can do a string comparison. (Ignore subnet masks).
  432. result = ((IPNetAddress)resultObj[0]).ToString(true);
  433. }
  434. var intf = nm.GetBindInterface(source, out int? _);
  435. Assert.Equal(intf, result);
  436. }
  437. }
  438. }