aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/slskd.Tests.Unit/Common/BlacklistTests.cs39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/slskd.Tests.Unit/Common/BlacklistTests.cs b/tests/slskd.Tests.Unit/Common/BlacklistTests.cs
index 71f67dd4..efe76921 100644
--- a/tests/slskd.Tests.Unit/Common/BlacklistTests.cs
+++ b/tests/slskd.Tests.Unit/Common/BlacklistTests.cs
@@ -1,5 +1,7 @@
using System;
+using System.Collections.Generic;
using System.IO;
+using System.Net;
using System.Threading.Tasks;
using Xunit;
@@ -7,6 +9,25 @@ namespace slskd.Tests.Unit.Common;
public class BlacklistTests
{
+ private List<(string, bool)> IPs = new List<(string, bool)>()
+ {
+ ("1.2.4.0", true),
+ ("1.2.4.128", true),
+ ("1.2.4.255", true),
+ ("1.2.8.0", true),
+ ("1.2.8.128", true),
+ ("1.2.8.255", true),
+ ("1.9.96.104", false),
+ ("1.9.96.105", true),
+ ("1.9.102.250", false),
+ ("1.9.102.251", true),
+ ("1.9.106.186", true),
+ ("1.9.106.187", false),
+ ("192.168.1.1", false),
+ ("4.4.4.4", false),
+ ("123.234.111.123", false),
+ };
+
[Theory]
[InlineData("Data/Blacklist/cidr.txt", BlacklistFormat.CIDR)]
[InlineData("Data/Blacklist/dat.txt", BlacklistFormat.DAT)]
@@ -71,4 +92,22 @@ public class BlacklistTests
// the test files are assumed to all contain 5 entries
Assert.Equal(5, bl.Count);
}
+
+ [Theory]
+ [InlineData("Data/Blacklist/cidr.txt")]
+ [InlineData("Data/Blacklist/dat.txt")]
+ [InlineData("Data/Blacklist/p2p.txt")]
+ public async Task CIDR_Contains(string filename)
+ {
+ var bl = new Blacklist();
+ await bl.Load(filename);
+
+ foreach (var ip in IPs)
+ {
+ if (bl.Contains(IPAddress.Parse(ip.Item1)) != ip.Item2)
+ {
+ throw new Exception($"Expected contains for {ip.Item1} to be {ip.Item2} but it wasn't");
+ }
+ }
+ }
} \ No newline at end of file