NetworkParseTests.cs 22 KB

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