2021-06-05 11:32:22 +00:00
|
|
|
using FsCheck;
|
|
|
|
using FsCheck.Xunit;
|
2023-11-10 15:59:45 +00:00
|
|
|
using MediaBrowser.Common.Net;
|
2021-06-05 11:32:22 +00:00
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Jellyfin.Networking.Tests
|
|
|
|
{
|
2022-07-19 19:28:04 +00:00
|
|
|
public static class NetworkExtensionsTests
|
2021-06-05 11:32:22 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Checks IP address formats.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="address">IP Address.</param>
|
|
|
|
[Theory]
|
|
|
|
[InlineData("127.0.0.1")]
|
|
|
|
[InlineData("127.0.0.1:123")]
|
|
|
|
[InlineData("localhost")]
|
|
|
|
[InlineData("localhost:1345")]
|
|
|
|
[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]:124")]
|
|
|
|
[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_ValidHostStrings_True(string address)
|
2023-11-10 15:59:45 +00:00
|
|
|
=> Assert.True(NetworkUtils.TryParseHost(address, out _, true, true));
|
2021-06-05 11:32:22 +00:00
|
|
|
|
|
|
|
[Property]
|
|
|
|
public static Property TryParse_IPv4Address_True(IPv4Address address)
|
2023-11-10 15:59:45 +00:00
|
|
|
=> NetworkUtils.TryParseHost(address.Item.ToString(), out _, true, true).ToProperty();
|
2021-06-05 11:32:22 +00:00
|
|
|
|
|
|
|
[Property]
|
|
|
|
public static Property TryParse_IPv6Address_True(IPv6Address address)
|
2023-11-10 15:59:45 +00:00
|
|
|
=> NetworkUtils.TryParseHost(address.Item.ToString(), out _, true, true).ToProperty();
|
2021-06-05 11:32:22 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// All should be invalid address strings.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="address">Invalid address strings.</param>
|
|
|
|
[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)
|
2023-11-10 15:59:45 +00:00
|
|
|
=> Assert.False(NetworkUtils.TryParseHost(address, out _, true, true));
|
2021-06-05 11:32:22 +00:00
|
|
|
}
|
|
|
|
}
|