Files
tbd-station-14/Content.Tests/Server/Utility/IPAddressExtTest.cs
Pieter-Jan Briers 66c8a68891 Holy crap auth works (#2099)
* Holy crap auth works

* Fix some usages of UserID instead of UserName

* Refactor preferences.

They be non-async now. Also faster.

* Rename DbContext.

* Guest username assignment.

* Fix saving of profiles.

* Don't store data for guests.

* Fix generating invalid random colors.

* Don't allow dumb garbage for char preferences.

* Bans.

* Lol forgot to fill out the command description.

* Connection log.

* Rename all the tables and columns to be snake_case.

* Re-do migrations.

* Fixing tests and warnings.

* Update submodule
2020-09-29 14:26:00 +02:00

62 lines
2.8 KiB
C#

using System.Net;
using Content.Server.Utility;
using NUnit.Framework;
namespace Content.Tests.Server.Utility
{
public class IPAddressExtTest
{
[Test]
[TestCase("192.168.5.85/24", "192.168.5.1")]
[TestCase("192.168.5.85/24", "192.168.5.254")]
[TestCase("10.128.240.50/30", "10.128.240.48")]
[TestCase("10.128.240.50/30", "10.128.240.49")]
[TestCase("10.128.240.50/30", "10.128.240.50")]
[TestCase("10.128.240.50/30", "10.128.240.51")]
public void IpV4SubnetMaskMatchesValidIpAddress(string netMask, string ipAddress)
{
var ipAddressObj = IPAddress.Parse(ipAddress);
Assert.That(ipAddressObj.IsInSubnet(netMask), Is.True);
}
[Test]
[TestCase("192.168.5.85/24", "192.168.4.254")]
[TestCase("192.168.5.85/24", "191.168.5.254")]
[TestCase("10.128.240.50/30", "10.128.240.47")]
[TestCase("10.128.240.50/30", "10.128.240.52")]
[TestCase("10.128.240.50/30", "10.128.239.50")]
[TestCase("10.128.240.50/30", "10.127.240.51")]
public void IpV4SubnetMaskDoesNotMatchInvalidIpAddress(string netMask, string ipAddress)
{
var ipAddressObj = IPAddress.Parse(ipAddress);
Assert.That(ipAddressObj.IsInSubnet(netMask), Is.False);
}
// ReSharper disable StringLiteralTypo
[Test]
[TestCase("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0012:0000:0000:0000:0000")]
[TestCase("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0012:FFFF:FFFF:FFFF:FFFF")]
[TestCase("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0012:0001:0000:0000:0000")]
[TestCase("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0012:FFFF:FFFF:FFFF:FFF0")]
[TestCase("2001:db8:abcd:0012::0/128", "2001:0DB8:ABCD:0012:0000:0000:0000:0000")]
public void IpV6SubnetMaskMatchesValidIpAddress(string netMask, string ipAddress)
{
var ipAddressObj = IPAddress.Parse(ipAddress);
Assert.That(ipAddressObj.IsInSubnet(netMask), Is.True);
}
[Test]
[TestCase("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0011:FFFF:FFFF:FFFF:FFFF")]
[TestCase("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0013:0000:0000:0000:0000")]
[TestCase("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0013:0001:0000:0000:0000")]
[TestCase("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0011:FFFF:FFFF:FFFF:FFF0")]
[TestCase("2001:db8:abcd:0012::0/128", "2001:0DB8:ABCD:0012:0000:0000:0000:0001")]
// ReSharper restore StringLiteralTypo
public void IpV6SubnetMaskDoesNotMatchInvalidIpAddress(string netMask, string ipAddress)
{
var ipAddressObj = IPAddress.Parse(ipAddress);
Assert.That(ipAddressObj.IsInSubnet(netMask), Is.False);
}
}
}