using FsCheck; using FsCheck.Xunit; using MediaBrowser.Common.Net; using Xunit; namespace Jellyfin.Networking.Tests { public static class IPNetAddressTests { /// /// Checks IP address formats. /// /// IP Address. [Theory] [InlineData("127.0.0.1")] [InlineData("fd23:184f:2029:0:3139:7386:67d7:d517")] [InlineData("fd23:184f:2029:0:3139:7386:67d7:d517/56")] [InlineData("[fd23:184f:2029:0:3139:7386:67d7:d517]")] [InlineData("fe80::7add:12ff:febb:c67b%16")] [InlineData("[fe80::7add:12ff:febb:c67b%16]:123")] [InlineData("fe80::7add:12ff:febb:c67b%16:123")] [InlineData("[fe80::7add:12ff:febb:c67b%16]")] [InlineData("192.168.1.2/255.255.255.0")] [InlineData("192.168.1.2/24")] public static void TryParse_ValidIPStrings_True(string address) => Assert.True(IPNetAddress.TryParse(address, out _)); [Property] public static Property TryParse_IPv4Address_True(IPv4Address address) => IPNetAddress.TryParse(address.Item.ToString(), out _).ToProperty(); [Property] public static Property TryParse_IPv6Address_True(IPv6Address address) => IPNetAddress.TryParse(address.Item.ToString(), out _).ToProperty(); /// /// All should be invalid address strings. /// /// Invalid address strings. [Theory] [InlineData("256.128.0.0.0.1")] [InlineData("127.0.0.1#")] [InlineData("localhost!")] [InlineData("fd23:184f:2029:0:3139:7386:67d7:d517:1231")] [InlineData("[fd23:184f:2029:0:3139:7386:67d7:d517:1231]")] public static void TryParse_InvalidAddressString_False(string address) => Assert.False(IPNetAddress.TryParse(address, out _)); } }