some fixes
This commit is contained in:
86
certmgrTest/NetUtilsTest.cs
Normal file
86
certmgrTest/NetUtilsTest.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using CertMgr.Core.Utils;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace certmgrTest
|
||||
{
|
||||
public class NetUtilsTest
|
||||
{
|
||||
[Test]
|
||||
public void IPv6Test()
|
||||
{
|
||||
string[] validIPv6Addresses = new[]
|
||||
{
|
||||
"2001:0db8:0000:0000:0000:ff00:0042:8329", // full form
|
||||
"2001:db8:0:0:0:ff00:42:8329", // shortened zeros
|
||||
"2001:db8::ff00:42:8329", // compressed zeros
|
||||
"::1", // loopback
|
||||
"::", // unspecified address
|
||||
"fe80::1ff:fe23:4567:890a", // link-local address
|
||||
"2001:db8:1234:ffff:ffff:ffff:ffff:ffff", // maximum range
|
||||
"fd12:3456:789a:1::1", // unique local address (ULA)
|
||||
"2001:0:3238:DFE1:63::FEFB", // mixed compression
|
||||
"0:0:0:0:0:0:0:1", // loopback without compression
|
||||
"2001:db8::123", // short address
|
||||
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", // all bits set to 1
|
||||
"2001:db8:85a3::8a2e:370:7334", // example from RFC 4291
|
||||
"::ffff:192.0.2.128" // IPv4-mapped IPv6 address
|
||||
};
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
foreach (string ip in validIPv6Addresses)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool valid = NetUtils.IsValidIPv6(ip);
|
||||
Assert.That(valid, Is.True, string.Format("expected that IPv6 address '{0}' is valid", ip));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Assert.Fail(string.Format("address: '{0}' failed with: {1}: {2}", ip, e.GetType().Name, e.Message));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IPv6_InvalidTest()
|
||||
{
|
||||
string[] invalidIPv6Addresses = new[]
|
||||
{
|
||||
"2001:::85a3::8a2e:370:7334", // multiple "::"
|
||||
"2001:db8:85a3:0:0:8a2e:370g:7334", // invalid hex character (g)
|
||||
"1200::AB00:1234::2552:7777:1313", // two "::" sections
|
||||
"2001:db8:85a3:z:0:8a2e:370:7334", // invalid hex segment
|
||||
"2001:db8:85a3:0:0:8a2e:370:7334:1234", // too many segments (9)
|
||||
"2001:db8:85a3", // too few segments (3)
|
||||
":2001:db8::1", // leading colon without pair
|
||||
"2001:db8::1:", // trailing colon without pair
|
||||
"2001:db8::1::", // multiple compression points
|
||||
"2001:db8:85a3:0:0:8a2e:370:7334/64", // contains CIDR mask
|
||||
// "2001:db8:85a3:0:0:8a2e:370:7334%", // missing interface ID after % <= this is valid (at least on windows)
|
||||
"::ffff:999.0.2.128", // invalid IPv4-mapped part
|
||||
"::ffff:192.0.2.256", // IPv4 part out of range
|
||||
"2001:db8:85a3::8a2e:370:7334:xyz", // trailing junk
|
||||
"2001:db8:::", // triple colon
|
||||
};
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
foreach (string ip in invalidIPv6Addresses)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool valid = NetUtils.IsValidIPv6(ip);
|
||||
Assert.That(valid, Is.False, string.Format("expected that IPv6 address '{0}' is NOT valid", ip));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Assert.Fail(string.Format("address: '{0}' failed with: {1}: {2}", ip, e.GetType().Name, e.Message));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user