service_matcher-go/imap/imap_test.go
2018-09-03 22:36:57 +09:00

152 lines
2.6 KiB
Go

package imap
import (
"crypto/tls"
"fmt"
"net"
"testing"
osm "git.loafle.net/overflow/service_matcher-go"
)
func ImapRun(matchCtx *osm.MatchCtx, conn net.Conn, t *testing.T) {
lm := NewMatcher()
//port := types.NewPort("143", types.NewHost("192.168.1.215"), types.TYPE_TCP)
//
//scanInfo := types.NewServiceScanInfo(port)
//
//var ipport string
//ipport = port.Host.Ip + ":" + string(port.Port)
//
//fmt.Println(ipport)
//conn, _ := net.Dial("tcp", ipport)
//defer conn.Close()
bytett := make([]byte, 1024)
rr, _ := conn.Read(bytett)
if err := lm.Match(matchCtx, 0, osm.NewPacket(bytett, rr)); 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)
read, _ := conn.Read(bytes)
fmt.Println(cap(bytes))
//fmt.Println(bytes)
if err := lm.Match(nil, ii+1, osm.NewPacket(bytes, read)); nil == err {
t.Log("send Good!")
}
}
}
func TestIMapTls(t *testing.T) {
conn, err := tls.Dial(
"tcp",
"192.168.1.15:993",
&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", 993)
ImapRun(matchCtx, conn, t)
}
func TestIMapNormal(t *testing.T) {
conn, err := net.Dial("tcp", "192.168.1.15:143")
if err != nil {
t.Fatal(err)
}
if err != nil {
t.Errorf("ERR %s", err)
}
defer conn.Close()
matchCtx := osm.NewMatchCtx("192.168.1.15", 143)
ImapRun(matchCtx, conn, t)
}
func TestImap(t *testing.T) {
lm := NewMatcher()
//port := types.NewPort("143", types.NewHost("192.168.1.215"), types.TYPE_TCP)
//scanInfo := scaninfo.NewServiceScanInfo(port)
var ipport string
//ipport = port.Host.Ip + ":" + port.Port_
fmt.Println(ipport)
conn, err := net.Dial("tcp", ipport)
if err != nil {
t.Errorf("ERR %s", err)
}
defer conn.Close()
matchCtx := osm.NewMatchCtx("192.168.1.15", 993)
bytett := make([]byte, 1024)
rr, _ := conn.Read(bytett)
//bb := lm.Match(0, osm.NewPacket(bytett, rr), scanInfo)
if err := lm.Match(nil, 0, osm.NewPacket(bytett, rr)); 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)
read, _ := conn.Read(bytes)
fmt.Println(cap(bytes))
//fmt.Println(bytes)
if err := lm.Match(nil, ii+1, osm.NewPacket(bytes, read)); nil == err {
t.Log("send Good!")
}
}
//t.Log(scanInfo)
}