service_matcher-go/http/http_test.go
crusader 1ae4509bc6 ing
2018-09-18 12:42:15 +09:00

79 lines
1.4 KiB
Go

package http
import (
"crypto/tls"
"net"
"testing"
"time"
osm "git.loafle.net/overflow/service_matcher-go"
)
func TestHTTP(t *testing.T) {
m := NewMatcher()
conn, err := net.Dial("tcp", "localhost:8000")
if err != nil {
t.Errorf("ERR %s", err)
}
defer conn.Close()
matchCtx := osm.NewMatchCtx("localhost", 8000)
for i := 0; i < m.PacketCount(matchCtx); i++ {
_, err := conn.Write(m.Packet(matchCtx, i).Buffer)
if err != nil {
t.Error(err)
}
bytes := make([]byte, 1024)
n, _ := conn.Read(bytes)
p := osm.NewPacket(bytes, n)
if err := m.Match(matchCtx, i, p); err != nil {
t.Error(err)
}
}
t.Log(m.Name(matchCtx))
t.Log(matchCtx)
}
func TestHTTPS(t *testing.T) {
m := NewMatcher()
dialer := &net.Dialer{
Timeout: 5 * time.Second,
}
conn, err := tls.DialWithDialer(
dialer,
"tcp",
"192.168.1.1:443",
&tls.Config{
InsecureSkipVerify: true,
ServerName: "192.168.1.1",
},
)
if err != nil {
t.Errorf("ERR %s", err)
}
defer conn.Close()
matchCtx := osm.NewMatchCtx("192.168.1.1", 443)
for i := 0; i < m.PacketCount(matchCtx); i++ {
_, err := conn.Write(m.Packet(matchCtx, i).Buffer)
if err != nil {
t.Error(err)
}
bytes := make([]byte, 1024)
n, _ := conn.Read(bytes)
p := osm.NewPacket(bytes, n)
if err := m.Match(matchCtx, i, p); err != nil {
t.Error(err)
}
}
t.Log(m.Name(matchCtx))
t.Log(matchCtx)
}