diff --git a/.github/workflows/publish-executable-on-release.yaml b/.github/workflows/publish-executable-on-release.yaml
index 0657e34..b881a65 100644
--- a/.github/workflows/publish-executable-on-release.yaml
+++ b/.github/workflows/publish-executable-on-release.yaml
@@ -15,10 +15,10 @@ jobs:
result-encoding: string
script: return context.payload.release.tag_name.substring(1) # remove `v`
- uses: actions/checkout@v3
- - name: Setup .Net 6.0
+ - name: Setup .Net 8.0
uses: actions/setup-dotnet@v3
with:
- dotnet-version: '6.0'
+ dotnet-version: '8.0'
- name: Install dependencies
run: dotnet restore
- name: Build WinSocat
diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml
index 22d5cc1..90e6d8e 100644
--- a/.github/workflows/unit-test.yml
+++ b/.github/workflows/unit-test.yml
@@ -18,10 +18,10 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- - name: Setup .Net 6.0
+ - name: Setup .Net 8.0
uses: actions/setup-dotnet@v3
with:
- dotnet-version: '6.0'
+ dotnet-version: '8.0'
- name: Install dependencies
run: dotnet restore
- name: Build
diff --git a/.gitignore b/.gitignore
index 813e24b..7571bbc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,5 @@
/winsocat/bin/
/Tests/obj
/Tests/bin
+/.vs
*.user
\ No newline at end of file
diff --git a/.idea/.idea.WinSocat/.idea/.gitignore b/.idea/.idea.WinSocat/.idea/.gitignore
deleted file mode 100644
index 0275247..0000000
--- a/.idea/.idea.WinSocat/.idea/.gitignore
+++ /dev/null
@@ -1,13 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Rider ignored files
-/modules.xml
-/projectSettingsUpdater.xml
-/.idea.Solution1.iml
-/contentModel.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
diff --git a/.idea/.idea.WinSocat/.idea/.name b/.idea/.idea.WinSocat/.idea/.name
deleted file mode 100644
index b843923..0000000
--- a/.idea/.idea.WinSocat/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-WinSocat
\ No newline at end of file
diff --git a/.idea/.idea.WinSocat/.idea/encodings.xml b/.idea/.idea.WinSocat/.idea/encodings.xml
deleted file mode 100644
index df87cf9..0000000
--- a/.idea/.idea.WinSocat/.idea/encodings.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/.idea/.idea.WinSocat/.idea/indexLayout.xml b/.idea/.idea.WinSocat/.idea/indexLayout.xml
deleted file mode 100644
index 7b08163..0000000
--- a/.idea/.idea.WinSocat/.idea/indexLayout.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/.idea.WinSocat/.idea/vcs.xml b/.idea/.idea.WinSocat/.idea/vcs.xml
deleted file mode 100644
index 94a25f7..0000000
--- a/.idea/.idea.WinSocat/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
index f7ecfb4..f0a2f26 100644
--- a/README.md
+++ b/README.md
@@ -37,6 +37,8 @@ The `address1` can accept `STDIO`, `TCP-LISTEN`, `TCP`, `NPIPE`, `NPIPE-LISTEN`,
The `address2` can accept `STDIO`, `TCP`, `NPIPE`, `EXEC`, `WSL`, `UNIX`, `HVSOCK`, `SP` socket types.
+`NPIPE-LISTEN` supports the `ACL=AllowCurrentUser` parameter, in this case, no other user that is connected to the machine can read / write from / to the pipe. The default is `ACL=AllowEveryone`.
+
## Examples
* It can bridge standard input/output and tcp connection to address **127.0.0.1** on port **80**.
diff --git a/Tests/AddressElementTest.cs b/Tests/AddressElementTest.cs
index d9d6dbd..56be0fb 100644
--- a/Tests/AddressElementTest.cs
+++ b/Tests/AddressElementTest.cs
@@ -13,7 +13,7 @@ public class AddressElementTest
[TestCase("tag:\'foo \"bar\"\',opt1,opt2")]
public void ValidInputParseTest(string input)
{
- Assert.NotNull(AddressElement.TryParse(input));
+ Assert.That(AddressElement.TryParse(input), Is.Not.Null);
}
[TestCase("tag:\'foo\"")]
@@ -21,7 +21,7 @@ public void ValidInputParseTest(string input)
[TestCase("tag:\'foo \"bar\',opt1, opt2")]
public void InvalidInputParseTest(string input)
{
- Assert.Null(AddressElement.TryParse(input));
+ Assert.That(AddressElement.TryParse(input), Is.Null);
}
[TestCase("STDIO", ExpectedResult = "STDIO")]
diff --git a/Tests/HyperVListenPiperInfoTest.cs b/Tests/HyperVListenPiperInfoTest.cs
index 018ce76..05fc7f9 100644
--- a/Tests/HyperVListenPiperInfoTest.cs
+++ b/Tests/HyperVListenPiperInfoTest.cs
@@ -25,7 +25,7 @@ public class HyperVListenPiperInfoTest
public void ValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(HyperVListenPiperInfo.TryParse(element));
+ Assert.That(HyperVListenPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("HVSOCK-LISTEN:00000000-0000-0000-0000-000000000000:00000000-0000-0000-0000-000000000000")]
@@ -39,7 +39,7 @@ public void ValidInputParseTest(string input)
public void CaseInsensitiveValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(HyperVListenPiperInfo.TryParse(element));
+ Assert.That(HyperVListenPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("STDIO")]
@@ -53,7 +53,7 @@ public void CaseInsensitiveValidInputParseTest(string input)
public void InvalidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.Null(HyperVListenPiperInfo.TryParse(element));
+ Assert.That(HyperVListenPiperInfo.TryParse(element), Is.Null);
}
[TestCase("HVSOCK-LISTEN:00000000-0000-0000-0000-000000000000:00000000-0000-0000-0000-000000000000", ExpectedResult = "00000000-0000-0000-0000-000000000000")]
diff --git a/Tests/HyperVStreamPiperInfoTest.cs b/Tests/HyperVStreamPiperInfoTest.cs
index de32d3e..123c989 100644
--- a/Tests/HyperVStreamPiperInfoTest.cs
+++ b/Tests/HyperVStreamPiperInfoTest.cs
@@ -1,4 +1,5 @@
using Firejox.App.WinSocat;
+
namespace APPTest;
public class HyperVStreamPiperInfoTest
@@ -24,7 +25,7 @@ public class HyperVStreamPiperInfoTest
public void ValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(HyperVStreamPiperInfo.TryParse(element));
+ Assert.That(HyperVStreamPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("HVSOCK:00000000-0000-0000-0000-000000000000:00000000-0000-0000-0000-000000000000")]
@@ -38,7 +39,7 @@ public void ValidInputParseTest(string input)
public void CaseInsensitiveValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(HyperVStreamPiperInfo.TryParse(element));
+ Assert.That(HyperVStreamPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("STDIO")]
@@ -52,7 +53,7 @@ public void CaseInsensitiveValidInputParseTest(string input)
public void InvalidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.Null(HyperVStreamPiperInfo.TryParse(element));
+ Assert.That(HyperVStreamPiperInfo.TryParse(element), Is.Null);
}
[TestCase("HVSOCK:00000000-0000-0000-0000-000000000000:00000000-0000-0000-0000-000000000000", ExpectedResult = "00000000-0000-0000-0000-000000000000")]
diff --git a/Tests/NamedPipeListenPiperInfoTest.cs b/Tests/NamedPipeListenPiperInfoTest.cs
index 2d84ef9..7d793fa 100644
--- a/Tests/NamedPipeListenPiperInfoTest.cs
+++ b/Tests/NamedPipeListenPiperInfoTest.cs
@@ -5,10 +5,12 @@ namespace APPTest;
public class NamedPipeListenPiperInfoTest
{
[TestCase("NPIPE-LISTEN:fooPipe")]
+ [TestCase("NPIPE-LISTEN:fooPipe,ACL=AllowEveryone")]
+ [TestCase("NPIPE-LISTEN:fooPipe,ACL=AllowCurrentUser")]
public void VaildInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(Firejox.App.WinSocat.NamedPipeListenPiperInfo.TryParse(element));
+ Assert.That(NamedPipeListenPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("NPIPE-LISTEN:fooPipe")]
@@ -16,24 +18,44 @@ public void VaildInputParseTest(string input)
public void CaseInsensitiveValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(Firejox.App.WinSocat.NamedPipeListenPiperInfo.TryParse(element));
+ Assert.That(NamedPipeListenPiperInfo.TryParse(element), Is.Not.Null);
}
-
+
[TestCase("STDIO")]
[TestCase("TCP:127.0.0.1:80")]
[TestCase("TCP-LISTEN:127.0.0.1:80")]
[TestCase("NPIPE:fooServer:barPipe")]
+ [TestCase("NPIPE:fooServer:barPipe")]
+ [TestCase("NPIPE:fooServer:barPipe")]
[TestCase(@"EXEC:'C:\Foo.exe bar'")]
public void InvalidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.Null(Firejox.App.WinSocat.NamedPipeListenPiperInfo.TryParse(element));
- }
-
- [TestCase("NPIPE-LISTEN:fooPipe", ExpectedResult = "fooPipe")]
- public string PipePatternMatchTest(string input)
+ Assert.That(NamedPipeListenPiperInfo.TryParse(element), Is.Null);
+ }
+
+ [TestCase("NPIPE-LISTEN:fooPipe")]
+ [TestCase("NPIPE-LISTEN:fooPipe,ACL=AllowEveryone")]
+ [TestCase("NPIPE-LISTEN:fooPipe,ACL=AllowCurrentUser")]
+ public void PipePatternMatchTest(string input)
{
- var element = AddressElement.TryParse(input);
- return Firejox.App.WinSocat.NamedPipeListenPiperInfo.TryParse(element).PipeName;
+ // Case 1 - Default ACL
+ var element = AddressElement.TryParse("NPIPE-LISTEN:fooPipe");
+ var parsed = NamedPipeListenPiperInfo.TryParse(element);
+ Assert.That(parsed.PipeName, Is.EqualTo("fooPipe"));
+ Assert.That(parsed.ACL, Is.EqualTo("AllowEveryone"));
+
+ // Case 2 - AllowEveryone ACL
+ element = AddressElement.TryParse("NPIPE-LISTEN:fooPipe,ACL=AllowEveryone");
+ parsed = NamedPipeListenPiperInfo.TryParse(element);
+ Assert.That(parsed.PipeName, Is.EqualTo("fooPipe"));
+ Assert.That(parsed.ACL, Is.EqualTo("AllowEveryone"));
+
+ // Case 3 - AllowCurrentUser ACL
+ element = AddressElement.TryParse("NPIPE-LISTEN:fooPipe,ACL=AllowCurrentUser");
+ parsed = NamedPipeListenPiperInfo.TryParse(element);
+ Assert.That(parsed.PipeName, Is.EqualTo("fooPipe"));
+ Assert.That(parsed.ACL, Is.EqualTo("AllowCurrentUser"));
+
}
-}
\ No newline at end of file
+}
diff --git a/Tests/NamedPipeListenPiperStrategyTest.cs b/Tests/NamedPipeListenPiperStrategyTest.cs
index 4b631bd..379a6ba 100644
--- a/Tests/NamedPipeListenPiperStrategyTest.cs
+++ b/Tests/NamedPipeListenPiperStrategyTest.cs
@@ -52,8 +52,8 @@ public void EchoPiperTest()
writer.WriteLine("Foo");
writer.Flush();
-
- StringAssert.AreEqualIgnoringCase("Foo", reader.ReadLine());
+
+ Assert.That(reader.ReadLine(), Is.EqualTo("Foo").IgnoreCase);
}
}
@@ -61,5 +61,7 @@ public void EchoPiperTest()
public void CleanUp()
{
_source.Cancel();
+ _source.Dispose();
}
+
}
\ No newline at end of file
diff --git a/Tests/NamedPipeStreamPiperInfoTest.cs b/Tests/NamedPipeStreamPiperInfoTest.cs
index 868694c..b6268f1 100644
--- a/Tests/NamedPipeStreamPiperInfoTest.cs
+++ b/Tests/NamedPipeStreamPiperInfoTest.cs
@@ -9,27 +9,27 @@ public class NamedPipeStreamPiperInfoTest
[TestCase("NPIPE:barPipe")]
public void ValidInputParseTest(string input)
{
- var element = AddressElement.TryParse(input);
- Assert.NotNull(Firejox.App.WinSocat.NamedPipeStreamPiperInfo.TryParse(element));
+ var element = AddressElement.TryParse(input);
+ Assert.That(NamedPipeStreamPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("NPIPE:fooServer:barPipe")]
[TestCase("npipe:fooServer:barPipe")]
public void CaseInsensitiveValidInputParseTest(string input)
{
- var element = AddressElement.TryParse(input);
- Assert.NotNull(Firejox.App.WinSocat.NamedPipeStreamPiperInfo.TryParse(element));
+ var element = AddressElement.TryParse(input);
+ Assert.That(NamedPipeStreamPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("STDIO")]
[TestCase("TCP:127.0.0.1:80")]
[TestCase("TCP-LISTEN:127.0.0.1:80")]
- [TestCase("NPIPE-LISTEN:fooPipe")]
+ [TestCase("NPIPE-LISTEN:fooPipe")]
[TestCase(@"EXEC:'C:\Foo.exe bar'")]
public void InvalidInputParseTest(string input)
{
- var element = AddressElement.TryParse(input);
- Assert.Null(Firejox.App.WinSocat.NamedPipeStreamPiperInfo.TryParse(element));
+ var element = AddressElement.TryParse(input);
+ Assert.That(NamedPipeStreamPiperInfo.TryParse(element), Is.Null);
}
[TestCase("NPIPE:fooServer:barPipe", ExpectedResult = "fooServer")]
diff --git a/Tests/PiperStrategyTest.cs b/Tests/PiperStrategyTest.cs
index 0c851d4..cf19170 100644
--- a/Tests/PiperStrategyTest.cs
+++ b/Tests/PiperStrategyTest.cs
@@ -104,7 +104,7 @@ public void EchoPiperTest()
_writeStream.Seek(0, SeekOrigin.Begin);
var reader = new StreamReader(_writeStream);
- StringAssert.AreEqualIgnoringCase("Foo", reader.ReadToEnd());
+ Assert.That(reader.ReadToEnd(), Is.EqualTo("Foo").IgnoreCase);
}
[Test]
@@ -149,10 +149,10 @@ public void TcpStreamPiperTest()
serverThread.Join();
_writeStream.Seek(0, SeekOrigin.Begin);
- var reader = new StreamReader(_writeStream);
-
- StringAssert.AreEqualIgnoringCase("Foo", tcs.Task.Result);
- StringAssert.AreEqualIgnoringCase("Bar", reader.ReadToEnd());
+ var reader = new StreamReader(_writeStream);
+
+ Assert.That(tcs.Task.Result, Is.EqualTo("Foo").IgnoreCase);
+ Assert.That(reader.ReadToEnd(), Is.EqualTo("Bar").IgnoreCase);
}
[Test]
@@ -188,8 +188,9 @@ public void NamedPipeStreamPiperTest()
_writeStream.Seek(0, SeekOrigin.Begin);
var reader = new StreamReader(_writeStream);
- StringAssert.AreEqualIgnoringCase("Bar", reader.ReadToEnd());
- StringAssert.AreEqualIgnoringCase("Foo", tcs.Task.Result);
+
+ Assert.That(reader.ReadToEnd(), Is.EqualTo("Bar").IgnoreCase);
+ Assert.That(tcs.Task.Result, Is.EqualTo("Foo").IgnoreCase);
}
[Test]
@@ -241,14 +242,16 @@ public void UnixSocketStreamPiperTest()
_strategy.Execute(factory);
_writeStream.Seek(0, SeekOrigin.Begin);
- var reader = new StreamReader(_writeStream);
- StringAssert.AreEqualIgnoringCase("Bar", reader.ReadToEnd());
- StringAssert.AreEqualIgnoringCase("Foo", tcs.Task.Result);
+ var reader = new StreamReader(_writeStream);
+
+ Assert.That(reader.ReadToEnd(), Is.EqualTo("Bar").IgnoreCase);
+ Assert.That(tcs.Task.Result, Is.EqualTo("Foo").IgnoreCase);
}
[TearDown]
public void CleanUp()
{
_writeStream.Dispose();
+ _writer.Dispose();
}
}
\ No newline at end of file
diff --git a/Tests/ProcPiperInfoTest.cs b/Tests/ProcPiperInfoTest.cs
index 2b1e122..eda201a 100644
--- a/Tests/ProcPiperInfoTest.cs
+++ b/Tests/ProcPiperInfoTest.cs
@@ -10,7 +10,7 @@ public class ProcPiperInfoTest
public void ValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(Firejox.App.WinSocat.ProcPiperInfo.TryParse(element));
+ Assert.That(ProcPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase(@"EXEC:C:\Foo.exe bar")]
@@ -18,7 +18,7 @@ public void ValidInputParseTest(string input)
public void CaseInsensitiveValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(Firejox.App.WinSocat.ProcPiperInfo.TryParse(element));
+ Assert.That(ProcPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("STDIO")]
@@ -29,7 +29,7 @@ public void CaseInsensitiveValidInputParseTest(string input)
public void InvalidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.Null(Firejox.App.WinSocat.ProcPiperInfo.TryParse(element));
+ Assert.That(ProcPiperInfo.TryParse(element), Is.Null);
}
[TestCase(@"EXEC:C:\Foo.exe bar", ExpectedResult = @"C:\Foo.exe")]
@@ -38,7 +38,7 @@ public void InvalidInputParseTest(string input)
public string FileNamePatternMatchTest(string input)
{
var element = AddressElement.TryParse(input);
- return Firejox.App.WinSocat.ProcPiperInfo.TryParse(element).FileName;
+ return ProcPiperInfo.TryParse(element).FileName;
}
[TestCase(@"EXEC:C:\Foo.exe bar1 bar2", ExpectedResult = "bar1 bar2")]
@@ -46,6 +46,6 @@ public string FileNamePatternMatchTest(string input)
public string ArgumentPatternMatchTest(string input)
{
var element = AddressElement.TryParse(input);
- return Firejox.App.WinSocat.ProcPiperInfo.TryParse(element).Arguments;
+ return ProcPiperInfo.TryParse(element).Arguments;
}
}
\ No newline at end of file
diff --git a/Tests/SerialPortPiperInfoTest.cs b/Tests/SerialPortPiperInfoTest.cs
index 77e8764..9f3c0e0 100644
--- a/Tests/SerialPortPiperInfoTest.cs
+++ b/Tests/SerialPortPiperInfoTest.cs
@@ -11,7 +11,7 @@ public class SerialPortPiperInfoTest
public void ValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(SerialPortPiperInfo.TryParse(element));
+ Assert.That(SerialPortPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("sp:COM1")]
@@ -19,7 +19,7 @@ public void ValidInputParseTest(string input)
public void CaseInsensitiveValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(SerialPortPiperInfo.TryParse(element));
+ Assert.That(SerialPortPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("STDIO")]
@@ -33,7 +33,7 @@ public void CaseInsensitiveValidInputParseTest(string input)
public void InvalidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.Null(SerialPortPiperInfo.TryParse(element));
+ Assert.That(SerialPortPiperInfo.TryParse(element), Is.Null);
}
[TestCase("sp:COM1", ExpectedResult = "COM1")]
diff --git a/Tests/StdPiperInfoTest.cs b/Tests/StdPiperInfoTest.cs
index c910e77..ec0cfc6 100644
--- a/Tests/StdPiperInfoTest.cs
+++ b/Tests/StdPiperInfoTest.cs
@@ -9,7 +9,7 @@ public class StdPiperInfoTest
public void VaildInputCheckTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.IsTrue(Firejox.App.WinSocat.StdPiperInfo.Check(element));
+ Assert.That(Firejox.App.WinSocat.StdPiperInfo.Check(element), Is.True);
}
[TestCase("STDIO")]
@@ -17,7 +17,7 @@ public void VaildInputCheckTest(string input)
public void CaseInsensitiveValidInputCheckTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.IsTrue(Firejox.App.WinSocat.StdPiperInfo.Check(element));
+ Assert.That(Firejox.App.WinSocat.StdPiperInfo.Check(element), Is.True);
}
[TestCase("TCP:127.0.0.1:80")]
@@ -28,6 +28,6 @@ public void CaseInsensitiveValidInputCheckTest(string input)
public void InvalidInputCheckTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.IsFalse(Firejox.App.WinSocat.StdPiperInfo.Check(element));
+ Assert.That(Firejox.App.WinSocat.StdPiperInfo.Check(element), Is.False);
}
}
\ No newline at end of file
diff --git a/Tests/TcpListenPiperInfoTest.cs b/Tests/TcpListenPiperInfoTest.cs
index 40f0614..2751d21 100644
--- a/Tests/TcpListenPiperInfoTest.cs
+++ b/Tests/TcpListenPiperInfoTest.cs
@@ -11,7 +11,7 @@ public class TcpListenPiperInfoTest
public void ValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(Firejox.App.WinSocat.TcpListenPiperInfo.TryParse(element));
+ Assert.That(Firejox.App.WinSocat.TcpListenPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("TCP-LISTEN:127.0.0.1:80")]
@@ -19,7 +19,7 @@ public void ValidInputParseTest(string input)
public void CaseInsensitiveValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(Firejox.App.WinSocat.TcpListenPiperInfo.TryParse(element));
+ Assert.That(Firejox.App.WinSocat.TcpListenPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("STDIO")]
@@ -30,7 +30,7 @@ public void CaseInsensitiveValidInputParseTest(string input)
public void InvalidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.Null(Firejox.App.WinSocat.TcpListenPiperInfo.TryParse(element));
+ Assert.That(Firejox.App.WinSocat.TcpListenPiperInfo.TryParse(element), Is.Null);
}
[TestCaseSource(nameof(AddressCases))]
diff --git a/Tests/TcpListenPiperStrategyTest.cs b/Tests/TcpListenPiperStrategyTest.cs
index 28102c9..c792d25 100644
--- a/Tests/TcpListenPiperStrategyTest.cs
+++ b/Tests/TcpListenPiperStrategyTest.cs
@@ -50,15 +50,16 @@ public void EchoPiperTest()
var reader = new StreamReader(stream);
writer.WriteLine("Foo");
- writer.Flush();
-
- StringAssert.AreEqualIgnoringCase("Foo", reader.ReadLine());
+ writer.Flush();
+
+ Assert.That(reader.ReadLine(), Is.EqualTo("Foo").IgnoreCase);
}
[TearDown]
public void CleanUp()
{
_source.Cancel();
+ _source.Dispose();
}
diff --git a/Tests/TcpStreamPiperInfoTest.cs b/Tests/TcpStreamPiperInfoTest.cs
index db22c95..19a1b2e 100644
--- a/Tests/TcpStreamPiperInfoTest.cs
+++ b/Tests/TcpStreamPiperInfoTest.cs
@@ -9,8 +9,8 @@ public class TcpStreamPiperInfoTest
[TestCase("TCP:80")]
public void ValidInputParseTest(string input)
{
- var element = AddressElement.TryParse(input);
- Assert.NotNull(Firejox.App.WinSocat.TcpStreamPiperInfo.TryParse(element));
+ var element = AddressElement.TryParse(input);
+ Assert.That(TcpStreamPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("TCP:127.0.0.1:80")]
@@ -18,7 +18,7 @@ public void ValidInputParseTest(string input)
public void CaseInsensitiveValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(Firejox.App.WinSocat.TcpStreamPiperInfo.TryParse(element));
+ Assert.That(TcpStreamPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("STDIO")]
@@ -29,7 +29,7 @@ public void CaseInsensitiveValidInputParseTest(string input)
public void InvalidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.Null(Firejox.App.WinSocat.TcpStreamPiperInfo.TryParse(element));
+ Assert.That(TcpStreamPiperInfo.TryParse(element), Is.Null);
}
[TestCase("TCP:127.0.0.1:80", ExpectedResult = "127.0.0.1")]
@@ -38,7 +38,7 @@ public void InvalidInputParseTest(string input)
public string HostPatternMatchTest(string input)
{
var element = AddressElement.TryParse(input);
- return Firejox.App.WinSocat.TcpStreamPiperInfo.TryParse(element).Host;
+ return TcpStreamPiperInfo.TryParse(element).Host;
}
[TestCase("TCP:127.0.0.1:80", ExpectedResult = 80)]
@@ -47,6 +47,6 @@ public string HostPatternMatchTest(string input)
public int PortPatternMatchTest(string input)
{
var element = AddressElement.TryParse(input);
- return Firejox.App.WinSocat.TcpStreamPiperInfo.TryParse(element).Port;
+ return TcpStreamPiperInfo.TryParse(element).Port;
}
}
\ No newline at end of file
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index 44c45b5..3c29060 100644
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net8.0
enable
enable
@@ -11,13 +11,19 @@
-
-
-
-
-
-
-
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
diff --git a/Tests/UnixSocketListenPiperInfoTest.cs b/Tests/UnixSocketListenPiperInfoTest.cs
index 22cbe30..7227e74 100644
--- a/Tests/UnixSocketListenPiperInfoTest.cs
+++ b/Tests/UnixSocketListenPiperInfoTest.cs
@@ -9,7 +9,7 @@ public class UnixSocketListenPiperInfoTest
public void ValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(UnixSocketListenPiperInfo.TryParse(element));
+ Assert.That(UnixSocketListenPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("UNIX-LISTEN:foo.sock")]
@@ -17,7 +17,7 @@ public void ValidInputParseTest(string input)
public void CaseInsensitiveValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(UnixSocketListenPiperInfo.TryParse(element));
+ Assert.That(UnixSocketListenPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("STDIO")]
@@ -30,7 +30,7 @@ public void CaseInsensitiveValidInputParseTest(string input)
public void InvalidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.Null(UnixSocketListenPiperInfo.TryParse(element));
+ Assert.That(UnixSocketListenPiperInfo.TryParse(element), Is.Null);
}
[TestCase("UNIX-LISTEN:foo.sock", ExpectedResult = "foo.sock")]
diff --git a/Tests/UnixSocketListenPiperStrategyTest.cs b/Tests/UnixSocketListenPiperStrategyTest.cs
index 495409c..f5ac13d 100644
--- a/Tests/UnixSocketListenPiperStrategyTest.cs
+++ b/Tests/UnixSocketListenPiperStrategyTest.cs
@@ -55,13 +55,14 @@ public void EchoPiperTest()
writer.WriteLine("Foo");
writer.Flush();
-
- StringAssert.AreEqualIgnoringCase("Foo", reader.ReadLine());
+
+ Assert.That(reader.ReadLine(), Is.EqualTo("Foo").IgnoreCase);
}
[TearDown]
public void CleanUp()
{
_source.Cancel();
+ _source.Dispose();
}
}
\ No newline at end of file
diff --git a/Tests/UnixSocketStreamPiperInfoTest.cs b/Tests/UnixSocketStreamPiperInfoTest.cs
index 028766c..2bdaea7 100644
--- a/Tests/UnixSocketStreamPiperInfoTest.cs
+++ b/Tests/UnixSocketStreamPiperInfoTest.cs
@@ -9,7 +9,8 @@ public class UnixSocketStreamPiperInfoTest
public void ValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(UnixSocketStreamPiperInfo.TryParse(element));
+ Assert.That(UnixSocketStreamPiperInfo.TryParse(element), Is.Not.Null);
+
}
[TestCase("UNIX:foo.sock")]
@@ -17,7 +18,7 @@ public void ValidInputParseTest(string input)
public void CaseInsensitiveValidInputParseTest(string input)
{
var element = AddressElement.TryParse(input);
- Assert.NotNull(UnixSocketStreamPiperInfo.TryParse(element));
+ Assert.That(UnixSocketStreamPiperInfo.TryParse(element), Is.Not.Null);
}
[TestCase("STDIO")]
@@ -29,7 +30,7 @@ public void CaseInsensitiveValidInputParseTest(string input)
public void InvalidInputParse(string input)
{
var element = AddressElement.TryParse(input);
- Assert.Null(UnixSocketStreamPiperInfo.TryParse(element));
+ Assert.That(UnixSocketStreamPiperInfo.TryParse(element), Is.Null);
}
[TestCase("UNIX:foo.sock", ExpectedResult = "foo.sock")]
diff --git a/global.json b/global.json
index 9e5e1fd..dad2db5 100644
--- a/global.json
+++ b/global.json
@@ -1,6 +1,6 @@
{
"sdk": {
- "version": "6.0.0",
+ "version": "8.0.0",
"rollForward": "latestMajor",
"allowPrerelease": true
}
diff --git a/winsocat/NamedPipe.cs b/winsocat/NamedPipe.cs
index a3c28dd..8548248 100644
--- a/winsocat/NamedPipe.cs
+++ b/winsocat/NamedPipe.cs
@@ -1,4 +1,5 @@
using System.IO.Pipes;
+using System.Security.Principal;
namespace Firejox.App.WinSocat;
@@ -6,14 +7,17 @@ public class NamedPipeStreamPiperInfo
{
private readonly string _serverName;
private readonly string _pipeName;
+ private readonly string _acl;
public string ServerName => _serverName;
public string PipeName => _pipeName;
+ public string ACL => _acl;
- public NamedPipeStreamPiperInfo(string serverName, string pipeName)
+ public NamedPipeStreamPiperInfo(string serverName, string pipeName, string acl)
{
_serverName = serverName;
_pipeName = pipeName;
+ _acl = acl;
}
public static NamedPipeStreamPiperInfo TryParse(AddressElement element)
{
@@ -31,24 +35,28 @@ public static NamedPipeStreamPiperInfo TryParse(AddressElement element)
pipeName = element.Address.Substring(sepIndex + 1);
- return new NamedPipeStreamPiperInfo(serverName, pipeName);
+ return new NamedPipeStreamPiperInfo(serverName, pipeName, element.Options.GetValueOrDefault("ACL", "AllowEveryone"));
}
}
public class NamedPipeListenPiperInfo
{
private readonly string _pipeName;
+ private readonly string _acl = "AllowEveryone";
+
public string PipeName => _pipeName;
+ public string ACL => _acl;
- public NamedPipeListenPiperInfo(string pipeName)
+ public NamedPipeListenPiperInfo(string pipeName, string acl = "AllowEveryone")
{
_pipeName = pipeName;
+ _acl = acl;
}
public static NamedPipeListenPiperInfo TryParse(AddressElement element)
{
if (element.Tag.Equals("NPIPE-LISTEN", StringComparison.OrdinalIgnoreCase))
- return new NamedPipeListenPiperInfo(element.Address);
+ return new NamedPipeListenPiperInfo(element.Address, element.Options.GetValueOrDefault("ACL", "AllowEveryone"));
return null!;
}
@@ -135,6 +143,24 @@ public NamedPipeListenPiper(NamedPipeListenPiperInfo info)
_closed = false;
}
+ public void SetPermissions(NamedPipeServerStream _serverStream)
+ {
+ if (OperatingSystem.IsWindows())
+ {
+ // Only allow current user
+ if (_info.ACL.Equals("AllowCurrentUser", StringComparison.OrdinalIgnoreCase))
+ {
+ var securityIdentifier = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
+ var pipeAcl = new PipeAccessRule(securityIdentifier,
+ PipeAccessRights.ReadWrite | PipeAccessRights.CreateNewInstance,
+ System.Security.AccessControl.AccessControlType.Allow);
+ var pipeSecurity = new PipeSecurity();
+ pipeSecurity.AddAccessRule(pipeAcl);
+ _serverStream.SetAccessControl(pipeSecurity);
+ }
+ }
+ }
+
public IPiper NewIncomingPiper()
{
_serverStream = new NamedPipeServerStream(
@@ -143,8 +169,8 @@ public IPiper NewIncomingPiper()
-1,
PipeTransmissionMode.Byte,
PipeOptions.Asynchronous);
+ SetPermissions(_serverStream);
_serverStream.WaitForConnection();
-
var tmpServerStream = _serverStream;
_serverStream = null;
return new StreamPiper(tmpServerStream);
@@ -161,6 +187,7 @@ public async Task NewIncomingPiperAsync()
-1,
PipeTransmissionMode.Byte,
PipeOptions.Asynchronous);
+ SetPermissions(_serverStream);
await _serverStream.WaitForConnectionAsync();
var tmpServerStream = _serverStream;
diff --git a/winsocat/Program.cs b/winsocat/Program.cs
index f0778c9..6c13aa6 100644
--- a/winsocat/Program.cs
+++ b/winsocat/Program.cs
@@ -9,9 +9,11 @@ public static async Task Main(string[] args)
var arg1 = new Argument("address1");
var arg2 = new Argument("address2");
- var rootCommand = new RootCommand();
- rootCommand.Add(arg1);
- rootCommand.Add(arg2);
+ var rootCommand = new RootCommand
+ {
+ arg1,
+ arg2
+ };
rootCommand.SetHandler(async (address1, address2) =>
{
diff --git a/winsocat/winsocat.csproj b/winsocat/winsocat.csproj
index fdc1716..c8ac7cb 100644
--- a/winsocat/winsocat.csproj
+++ b/winsocat/winsocat.csproj
@@ -2,7 +2,7 @@
Exe
- net6.0
+ net8.0
enable
enable
true
@@ -27,11 +27,11 @@
-
+
-
-
+
+