Skip to content

Commit

Permalink
2024-10-05 10:19:47
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Oct 5, 2024
1 parent 07dd54d commit be883b2
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 18 deletions.
43 changes: 40 additions & 3 deletions protocol/ashe/engine_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package ashe

import (
"encoding/binary"
"io"
"math/rand/v2"
"testing"

"github.com/mohanson/daze"
Expand All @@ -28,9 +30,44 @@ func TestProtocolAsheTCP(t *testing.T) {
cli := doa.Try(dazeClient.Dial(ctx, "tcp", EchoServerListenOn))
defer cli.Close()

buf := make([]byte, 2048)
doa.Try(cli.Write([]byte{0x00, 0x00, 0x00, 0x80}))
doa.Try(io.ReadFull(cli, buf[:128]))
var (
bsz = max(4, int(rand.Uint32N(256)))
buf = make([]byte, bsz)
cnt int
rsz = int(rand.Uint32N(65536))
)

copy(buf[0:2], []byte{0x00, 0x00})
binary.BigEndian.PutUint16(buf[2:], uint16(rsz))
doa.Try(cli.Write(buf[:4]))
cnt = 0
for {
e := min(rand.IntN(bsz+1), rsz-cnt)
n := doa.Try(io.ReadFull(cli, buf[:e]))
for i := range n {
doa.Doa(buf[i] == 0x00)
}
cnt += n
if cnt == rsz {
break
}
}

copy(buf[0:2], []byte{0x01, 0x00})
binary.BigEndian.PutUint16(buf[2:], uint16(rsz))
doa.Try(cli.Write(buf[:4]))
for i := range bsz {
buf[i] = 0x00
}
cnt = 0
for {
e := min(rand.IntN(bsz+1), rsz-cnt)
n := doa.Try(cli.Write(buf[:e]))
cnt += n
if cnt == rsz {
break
}
}
}

func TestProtocolAsheTCPClientClose(t *testing.T) {
Expand Down
43 changes: 40 additions & 3 deletions protocol/baboon/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package baboon

import (
"bytes"
"encoding/binary"
"io"
"math/rand/v2"
"net/http"
"testing"

Expand Down Expand Up @@ -30,9 +32,44 @@ func TestProtocolBaboonTCP(t *testing.T) {
cli := doa.Try(dazeClient.Dial(ctx, "tcp", EchoServerListenOn))
defer cli.Close()

buf := make([]byte, 2048)
doa.Try(cli.Write([]byte{0x00, 0x00, 0x00, 0x80}))
doa.Try(io.ReadFull(cli, buf[:128]))
var (
bsz = max(4, int(rand.Uint32N(256)))
buf = make([]byte, bsz)
cnt int
rsz = int(rand.Uint32N(65536))
)

copy(buf[0:2], []byte{0x00, 0x00})
binary.BigEndian.PutUint16(buf[2:], uint16(rsz))
doa.Try(cli.Write(buf[:4]))
cnt = 0
for {
e := min(rand.IntN(bsz+1), rsz-cnt)
n := doa.Try(io.ReadFull(cli, buf[:e]))
for i := range n {
doa.Doa(buf[i] == 0x00)
}
cnt += n
if cnt == rsz {
break
}
}

copy(buf[0:2], []byte{0x01, 0x00})
binary.BigEndian.PutUint16(buf[2:], uint16(rsz))
doa.Try(cli.Write(buf[:4]))
for i := range bsz {
buf[i] = 0x00
}
cnt = 0
for {
e := min(rand.IntN(bsz+1), rsz-cnt)
n := doa.Try(cli.Write(buf[:e]))
cnt += n
if cnt == rsz {
break
}
}
}

func TestProtocolBaboonTCPClientClose(t *testing.T) {
Expand Down
43 changes: 40 additions & 3 deletions protocol/czar/engine_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package czar

import (
"encoding/binary"
"io"
"math/rand/v2"
"testing"

"github.com/mohanson/daze"
Expand Down Expand Up @@ -29,9 +31,44 @@ func TestProtocolCzarTCP(t *testing.T) {
cli := doa.Try(dazeClient.Dial(ctx, "tcp", EchoServerListenOn))
defer cli.Close()

buf := make([]byte, 2048)
doa.Try(cli.Write([]byte{0x00, 0x00, 0x00, 0x80}))
doa.Try(io.ReadFull(cli, buf[:128]))
var (
bsz = max(4, int(rand.Uint32N(256)))
buf = make([]byte, bsz)
cnt int
rsz = int(rand.Uint32N(65536))
)

copy(buf[0:2], []byte{0x00, 0x00})
binary.BigEndian.PutUint16(buf[2:], uint16(rsz))
doa.Try(cli.Write(buf[:4]))
cnt = 0
for {
e := min(rand.IntN(bsz+1), rsz-cnt)
n := doa.Try(io.ReadFull(cli, buf[:e]))
for i := range n {
doa.Doa(buf[i] == 0x00)
}
cnt += n
if cnt == rsz {
break
}
}

copy(buf[0:2], []byte{0x01, 0x00})
binary.BigEndian.PutUint16(buf[2:], uint16(rsz))
doa.Try(cli.Write(buf[:4]))
for i := range bsz {
buf[i] = 0x00
}
cnt = 0
for {
e := min(rand.IntN(bsz+1), rsz-cnt)
n := doa.Try(cli.Write(buf[:e]))
cnt += n
if cnt == rsz {
break
}
}
}

func TestProtocolCzarTCPClientClose(t *testing.T) {
Expand Down
46 changes: 40 additions & 6 deletions protocol/czar/mux_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package czar

import (
"encoding/binary"
"errors"
"io"
"log"
"math/rand/v2"
"net"
"strings"
"testing"
Expand All @@ -22,12 +24,44 @@ func TestProtocolCzarMux(t *testing.T) {
cli := doa.Try(mux.Open())
defer cli.Close()

buf := make([]byte, 2048)
doa.Try(cli.Write([]byte{0x00, 0x00, 0x00, 0x80}))
doa.Doa(doa.Try(io.ReadFull(cli, buf[:128])) == 128)
doa.Try(cli.Write([]byte{0x00, 0x00, 0x00, 0x80}))
doa.Doa(doa.Try(io.ReadFull(cli, buf[:64])) == 64)
doa.Doa(doa.Try(io.ReadFull(cli, buf[:64])) == 64)
var (
bsz = max(4, int(rand.Uint32N(256)))
buf = make([]byte, bsz)
cnt int
rsz = int(rand.Uint32N(65536))
)

copy(buf[0:2], []byte{0x00, 0x00})
binary.BigEndian.PutUint16(buf[2:], uint16(rsz))
doa.Try(cli.Write(buf[:4]))
cnt = 0
for {
e := min(rand.IntN(bsz+1), rsz-cnt)
n := doa.Try(io.ReadFull(cli, buf[:e]))
for i := range n {
doa.Doa(buf[i] == 0x00)
}
cnt += n
if cnt == rsz {
break
}
}

copy(buf[0:2], []byte{0x01, 0x00})
binary.BigEndian.PutUint16(buf[2:], uint16(rsz))
doa.Try(cli.Write(buf[:4]))
for i := range bsz {
buf[i] = 0x00
}
cnt = 0
for {
e := min(rand.IntN(bsz+1), rsz-cnt)
n := doa.Try(cli.Write(buf[:e]))
cnt += n
if cnt == rsz {
break
}
}
}

func TestProtocolCzarMuxStreamClientClose(t *testing.T) {
Expand Down
44 changes: 41 additions & 3 deletions protocol/dahlia/engine_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package dahlia

import (
"encoding/binary"
"io"
"math/rand/v2"
"testing"

"github.com/mohanson/daze"
Expand Down Expand Up @@ -30,7 +32,43 @@ func TestProtocolDahliaTCP(t *testing.T) {

cli := doa.Try(daze.Dial("tcp", DazeClientListenOn))
defer cli.Close()
buf := make([]byte, 2048)
doa.Try(cli.Write([]byte{0x00, 0x00, 0x00, 0x80}))
doa.Try(io.ReadFull(cli, buf[:128]))

var (
bsz = max(4, int(rand.Uint32N(256)))
buf = make([]byte, bsz)
cnt int
rsz = int(rand.Uint32N(65536))
)

copy(buf[0:2], []byte{0x00, 0x00})
binary.BigEndian.PutUint16(buf[2:], uint16(rsz))
doa.Try(cli.Write(buf[:4]))
cnt = 0
for {
e := min(rand.IntN(bsz+1), rsz-cnt)
n := doa.Try(io.ReadFull(cli, buf[:e]))
for i := range n {
doa.Doa(buf[i] == 0x00)
}
cnt += n
if cnt == rsz {
break
}
}

copy(buf[0:2], []byte{0x01, 0x00})
binary.BigEndian.PutUint16(buf[2:], uint16(rsz))
doa.Try(cli.Write(buf[:4]))
for i := range bsz {
buf[i] = 0x00
}
cnt = 0
for {
e := min(rand.IntN(bsz+1), rsz-cnt)
n := doa.Try(cli.Write(buf[:e]))
cnt += n
if cnt == rsz {
break
}
}
}

0 comments on commit be883b2

Please sign in to comment.