Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
splitice committed Jan 1, 2024
1 parent 4c27a1b commit 7adf541
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ jobs:
run: dotnet restore

- name: Modprobe IP6 tables
run: sudo modprobe ip6_tables
run: |
sudo modprobe ip6_tables
sudo modprobe ip6table_filter
sudo modprobe ip6table_mangle
- name: NUnit Tests
run: SKIP_SYSTEM_TESTS=1 dotnet test IPTables.Net.Tests
Expand Down
43 changes: 28 additions & 15 deletions IPTables.Net.Tests/IptcInterfaceTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
Expand Down Expand Up @@ -29,7 +30,7 @@ public IptcInterfaceTest(int ipVersion)
_ipVersion = ipVersion;
}

private String GetBinary()
private String GetBinaryName()
{
if (_ipVersion == 4)
{
Expand All @@ -38,6 +39,14 @@ private String GetBinary()
return "ip6tables";
}

private String GetBinary()
{
var name = GetBinaryName();
if(Path.Exists("/sbin/"+name)) return "/sbin/"+name;
if(Path.Exists("/usr/sbin/"+name)) return "/usr/sbin/"+name;
return name;
}

[OneTimeSetUp]
public void TestStartup()
{
Expand All @@ -47,14 +56,17 @@ public void TestStartup()
{
Assert.Ignore();
}
Process.Start("/sbin/" + GetBinary(), "-F test").WaitForExit();

Process.Start("/sbin/" + GetBinary(), "-N test2").WaitForExit();
Process.Start("/sbin/" + GetBinary(), "-N test").WaitForExit();
Process.Start("/sbin/" + GetBinary(), "-A test -j ACCEPT").WaitForExit();

Process.Start("/sbin/" + GetBinary(), "-N test3").WaitForExit();
Process.Start("/sbin/" + GetBinary(), "-A test3 -p tcp -m tcp --dport 80 -j ACCEPT").WaitForExit();
var binary = GetBinary();
Process.Start(binary, "-F test").WaitForExit();

Process.Start(binary, "-N test2").WaitForExit();
Process.Start(binary, "-N test").WaitForExit();
Process.Start(binary, "-A test -j ACCEPT").WaitForExit();

Process.Start(binary, "-N test3").WaitForExit();
Process.Start(binary, "-A test3 -p tcp -m tcp --dport 80 -j ACCEPT").WaitForExit();
}
}

Expand All @@ -67,13 +79,14 @@ public void TestDestroy()
{
Assert.Ignore();
}
Process.Start("/sbin/" + GetBinary(), "-D test -j ACCEPT").WaitForExit();
Process.Start("/sbin/" + GetBinary(), "-F test").WaitForExit();
Process.Start("/sbin/"+GetBinary(), "-X test").WaitForExit();
Process.Start("/sbin/"+GetBinary(), "-F test2").WaitForExit();
Process.Start("/sbin/"+GetBinary(), "-X test2").WaitForExit();
Process.Start("/sbin/"+GetBinary(), "-F test3").WaitForExit();
Process.Start("/sbin/"+GetBinary(), "-X test3").WaitForExit();
var binary = GetBinary();
Process.Start(binary, "-D test -j ACCEPT").WaitForExit();
Process.Start(binary, "-F test").WaitForExit();
Process.Start(binary, "-X test").WaitForExit();
Process.Start(binary, "-F test2").WaitForExit();
Process.Start(binary, "-X test2").WaitForExit();
Process.Start(binary, "-F test3").WaitForExit();
Process.Start(binary, " - X test3").WaitForExit();
}
}

Expand Down Expand Up @@ -120,7 +133,7 @@ public void TestRuleInput()
using (IptcInterface iptc = new IptcInterface("filter", _ipVersion))
{

var status = iptc.ExecuteCommand(_ipVersion == 4 ? "iptables -A test2 -d 1.1.1.1 -p tcp -m tcp --dport 80 -j ACCEPT" : "iptables -A test2 -d ::1 -p tcp -m tcp --dport 80 -j ACCEPT");
var status = iptc.ExecuteCommand(_ipVersion == 4 ? "iptables -A test2 -d 1.1.1.1 -p tcp -m tcp --dport 80 -j ACCEPT" : "ip6tables -A test2 -d ::1 -p tcp -m tcp --dport 80 -j ACCEPT");
Assert.AreEqual(1, status, "Expected OK return value");

var rules = iptc.GetRules("test2");
Expand Down

0 comments on commit 7adf541

Please sign in to comment.