Improve test
This commit is contained in:
parent
74123021be
commit
3baccaccac
@ -2,22 +2,13 @@ package secure
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/gob"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPacketBasic(t *testing.T) {
|
func TestBasic(t *testing.T) {
|
||||||
// pSrc := PacketStart{
|
|
||||||
// OperationType: 0,
|
|
||||||
// ClientName: "test1",
|
|
||||||
// ProtocolVersion: "test2",
|
|
||||||
// AuthToken: "test3",
|
|
||||||
// }
|
|
||||||
// pDst := PacketStart{}
|
|
||||||
|
|
||||||
// buf := bytes.Buffer{}
|
|
||||||
|
|
||||||
srcConn, dstConn := net.Pipe()
|
srcConn, dstConn := net.Pipe()
|
||||||
|
|
||||||
srcSecConn := SecureConnection{
|
srcSecConn := SecureConnection{
|
||||||
@ -71,6 +62,61 @@ func TestPacketBasic(t *testing.T) {
|
|||||||
t.Errorf("%v not equal to %v", out[:n], b)
|
t.Errorf("%v not equal to %v", out[:n], b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPacketBasic(t *testing.T) {
|
||||||
|
// test encoding/decoding of packets over the encrypted wire
|
||||||
|
srcConn, dstConn := net.Pipe()
|
||||||
|
|
||||||
|
srcSecConn := SecureConnection{
|
||||||
|
Conn: srcConn,
|
||||||
|
SharedKey: &[32]byte{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
},
|
||||||
|
Buffer: &bytes.Buffer{},
|
||||||
|
}
|
||||||
|
|
||||||
|
dstSecConn := SecureConnection{
|
||||||
|
Conn: dstConn,
|
||||||
|
SharedKey: &[32]byte{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
},
|
||||||
|
Buffer: &bytes.Buffer{},
|
||||||
|
}
|
||||||
|
|
||||||
|
enc := gob.NewEncoder(&srcSecConn)
|
||||||
|
dec := gob.NewDecoder(&dstSecConn)
|
||||||
|
|
||||||
|
packet := PacketStartRequest{
|
||||||
|
OperationType: OperationTypeReceive,
|
||||||
|
ClientName: "foo",
|
||||||
|
ProtocolVersion: "1.1",
|
||||||
|
AuthToken: "abc123",
|
||||||
|
}
|
||||||
|
go func() { enc.Encode(packet) }()
|
||||||
|
|
||||||
|
recvPacket := PacketStartRequest{}
|
||||||
|
dec.Decode(&recvPacket)
|
||||||
|
|
||||||
|
if recvPacket.OperationType != OperationTypeReceive {
|
||||||
|
t.Error("bad OperationType")
|
||||||
|
}
|
||||||
|
if recvPacket.ClientName != "foo" {
|
||||||
|
t.Error("bad ClientName")
|
||||||
|
}
|
||||||
|
if recvPacket.ClientName != "foo" {
|
||||||
|
t.Error("bad ClientName")
|
||||||
|
}
|
||||||
|
if recvPacket.AuthToken != "abc123" {
|
||||||
|
t.Error("bad AuthToken")
|
||||||
|
}
|
||||||
|
if recvPacket.ProtocolVersion != "1.1" {
|
||||||
|
t.Error("bad ProtocolVersion")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user