|
|
@@ -298,3 +298,65 @@ func Test_listenSHAndDial_QUIC(t *testing.T) {
|
|
|
t.Error("end: ", end, " start: ", start)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func Test_listenSHAndDial_Unix(t *testing.T) {
|
|
|
+ tempDir := t.TempDir()
|
|
|
+ tempSocket := tempDir + "/server.sock"
|
|
|
+
|
|
|
+ listen, err := ListenSH(context.Background(), net.DomainAddress(tempSocket), 0, &internet.MemoryStreamConfig{
|
|
|
+ ProtocolName: "splithttp",
|
|
|
+ ProtocolSettings: &Config{
|
|
|
+ Path: "/sh",
|
|
|
+ },
|
|
|
+ }, func(conn stat.Connection) {
|
|
|
+ go func(c stat.Connection) {
|
|
|
+ defer c.Close()
|
|
|
+
|
|
|
+ var b [1024]byte
|
|
|
+ c.SetReadDeadline(time.Now().Add(2 * time.Second))
|
|
|
+ _, err := c.Read(b[:])
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ common.Must2(c.Write([]byte("Response")))
|
|
|
+ }(conn)
|
|
|
+ })
|
|
|
+ common.Must(err)
|
|
|
+ ctx := context.Background()
|
|
|
+ streamSettings := &internet.MemoryStreamConfig{
|
|
|
+ ProtocolName: "splithttp",
|
|
|
+ ProtocolSettings: &Config{
|
|
|
+ Host: "example.com",
|
|
|
+ Path: "sh",
|
|
|
+ },
|
|
|
+ }
|
|
|
+ conn, err := Dial(ctx, net.UnixDestination(net.DomainAddress(tempSocket)), streamSettings)
|
|
|
+
|
|
|
+ common.Must(err)
|
|
|
+ _, err = conn.Write([]byte("Test connection 1"))
|
|
|
+ common.Must(err)
|
|
|
+
|
|
|
+ var b [1024]byte
|
|
|
+ fmt.Println("test2")
|
|
|
+ n, _ := conn.Read(b[:])
|
|
|
+ fmt.Println("string is", n)
|
|
|
+ if string(b[:n]) != "Response" {
|
|
|
+ t.Error("response: ", string(b[:n]))
|
|
|
+ }
|
|
|
+
|
|
|
+ common.Must(conn.Close())
|
|
|
+ conn, err = Dial(ctx, net.UnixDestination(net.DomainAddress(tempSocket)), streamSettings)
|
|
|
+
|
|
|
+ common.Must(err)
|
|
|
+ _, err = conn.Write([]byte("Test connection 2"))
|
|
|
+ common.Must(err)
|
|
|
+ n, _ = conn.Read(b[:])
|
|
|
+ common.Must(err)
|
|
|
+ if string(b[:n]) != "Response" {
|
|
|
+ t.Error("response: ", string(b[:n]))
|
|
|
+ }
|
|
|
+ common.Must(conn.Close())
|
|
|
+
|
|
|
+ common.Must(listen.Close())
|
|
|
+}
|