23 lines
516 B
Go
23 lines
516 B
Go
package main
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseOpenAllowsEmptyToken(t *testing.T) {
|
|
host := "example.com"
|
|
p := make([]byte, 6+len(host))
|
|
binary.BigEndian.PutUint16(p[0:2], 0)
|
|
binary.BigEndian.PutUint16(p[2:4], uint16(len(host)))
|
|
binary.BigEndian.PutUint16(p[4:6], 443)
|
|
copy(p[6:], host)
|
|
token, gotHost, port, err := parseOpen(p)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if token != "" || gotHost != host || port != 443 {
|
|
t.Fatalf("got token=%q host=%q port=%d", token, gotHost, port)
|
|
}
|
|
}
|