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 a091ba7 commit 3adbc4a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
41 changes: 27 additions & 14 deletions IPTables.Net.Tests/IptablesLibraryTest.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.Text;
using IPTables.Net.Iptables;
Expand All @@ -11,6 +12,7 @@

namespace IPTables.Net.Tests
{
[NonParallelizable]
[TestFixture(4)]
[TestFixture(6)]
class IptablesLibraryTest
Expand All @@ -31,7 +33,8 @@ public IptablesLibraryTest(int ipVersion)
_ipVersion = ipVersion;
}

private String GetBinary()

private String GetBinaryName()
{
if (_ipVersion == 4)
{
Expand All @@ -40,6 +43,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 @@ -49,12 +60,13 @@ public void TestStartup()
{
Assert.Ignore();
}
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, "-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,14 +79,15 @@ public void TestDestroy()
{
Assert.Ignore();
}
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, "-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();
} }

[Test]
public void TestRuleOutput()
Expand Down
1 change: 1 addition & 0 deletions IPTables.Net.Tests/IptcInterfaceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace IPTables.Net.Tests
{
[NonParallelizable]
[TestFixture(4)]
[TestFixture(6)]
class IptcInterfaceTest
Expand Down

0 comments on commit 3adbc4a

Please sign in to comment.