service_matcher-go/pop/pop_test.go
2018-09-03 22:36:57 +09:00

88 lines
1.5 KiB
Go

package pop
import (
"crypto/tls"
"fmt"
osm "git.loafle.net/overflow/service_matcher-go"
"net"
"testing"
)
func TestPopTLS(t *testing.T) {
conn, err := tls.Dial(
"tcp",
"192.168.1.15:995",
&tls.Config{
InsecureSkipVerify: true,
ServerName: "192.168.1.15",
},
)
if err != nil {
t.Errorf("ERR %s", err)
}
defer conn.Close()
matchCtx := osm.NewMatchCtx("192.168.1.15", 995)
pop3Run(matchCtx, conn, t)
}
func TestPopNor(t *testing.T) {
conn, err := net.Dial("tcp", "192.168.1.15:110")
if err != nil {
t.Errorf("ERR %s", err)
}
defer conn.Close()
matchCtx := osm.NewMatchCtx("192.168.1.15", 110)
pop3Run(matchCtx, conn, t)
}
func pop3Run(matchCtx *osm.MatchCtx, conn net.Conn, t *testing.T) {
lm := NewMatcher()
//port := types.NewPort("110", types.NewHost("192.168.1.215"), types.TYPE_TCP)
//scanInfo := scaninfo.NewServiceScanInfo(port)
//var ipport string
//ipport = port.Host.Ip + ":" + string(port.Port)
//
//fmt.Println(ipport)
bytett := make([]byte, 1024)
read, _ := conn.Read(bytett)
if err := lm.Match(matchCtx, 0, osm.NewPacket(bytett, read)); nil == err {
t.Log("good!")
}
fmt.Println(lm.PacketCount(matchCtx))
for ii := 0; ii < lm.PacketCount(matchCtx); ii++ {
pack := lm.Packet(matchCtx, ii)
//fmt.Println(pack)
conn.Write(pack.Buffer)
bytes := make([]byte, 1024)
rr, _ := conn.Read(bytes)
//fmt.Println(bytes)
if err := lm.Match(matchCtx, ii+1, osm.NewPacket(bytes, rr)); nil == err {
t.Log("send Good!")
}
}
}