|
|
|
@ -388,7 +388,7 @@ func Test_queryString(t *testing.T) {
|
|
|
|
|
ctx := context.Background() |
|
|
|
|
streamSettings := &internet.MemoryStreamConfig{ |
|
|
|
|
ProtocolName: "splithttp", |
|
|
|
|
ProtocolSettings: &Config{Path: "sh"}, |
|
|
|
|
ProtocolSettings: &Config{Path: "sh?ed=2048"}, |
|
|
|
|
} |
|
|
|
|
conn, err := Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), listenPort), streamSettings) |
|
|
|
|
|
|
|
|
@ -407,3 +407,57 @@ func Test_queryString(t *testing.T) {
|
|
|
|
|
common.Must(conn.Close()) |
|
|
|
|
common.Must(listen.Close()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func Test_maxUpload(t *testing.T) { |
|
|
|
|
listenPort := tcp.PickPort() |
|
|
|
|
streamSettings := &internet.MemoryStreamConfig{ |
|
|
|
|
ProtocolName: "splithttp", |
|
|
|
|
ProtocolSettings: &Config{ |
|
|
|
|
Path: "/sh", |
|
|
|
|
ScMaxEachPostBytes: &RandRangeConfig{ |
|
|
|
|
From: 100, |
|
|
|
|
To: 100, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var uploadSize int |
|
|
|
|
listen, err := ListenSH(context.Background(), net.LocalHostIP, listenPort, streamSettings, func(conn stat.Connection) { |
|
|
|
|
go func(c stat.Connection) { |
|
|
|
|
defer c.Close() |
|
|
|
|
var b [1024]byte |
|
|
|
|
c.SetReadDeadline(time.Now().Add(2 * time.Second)) |
|
|
|
|
n, err := c.Read(b[:]) |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uploadSize = n |
|
|
|
|
|
|
|
|
|
common.Must2(c.Write([]byte("Response"))) |
|
|
|
|
}(conn) |
|
|
|
|
}) |
|
|
|
|
common.Must(err) |
|
|
|
|
ctx := context.Background() |
|
|
|
|
|
|
|
|
|
conn, err := Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), listenPort), streamSettings) |
|
|
|
|
|
|
|
|
|
// send a slightly too large upload
|
|
|
|
|
var upload [101]byte |
|
|
|
|
_, err = conn.Write(upload[:]) |
|
|
|
|
common.Must(err) |
|
|
|
|
|
|
|
|
|
var b [1024]byte |
|
|
|
|
n, _ := io.ReadFull(conn, b[:]) |
|
|
|
|
fmt.Println("string is", n) |
|
|
|
|
if string(b[:n]) != "Response" { |
|
|
|
|
t.Error("response: ", string(b[:n])) |
|
|
|
|
} |
|
|
|
|
common.Must(conn.Close()) |
|
|
|
|
|
|
|
|
|
if uploadSize > 100 || uploadSize == 0 { |
|
|
|
|
t.Error("incorrect upload size: ", uploadSize) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
common.Must(listen.Close()) |
|
|
|
|
} |
|
|
|
|