service_matcher-go/ftp/ftp_test.go
crusader d14425f824 ing
2018-10-23 11:38:28 +09:00

89 lines
1.5 KiB
Go

package ftp
import (
"crypto/tls"
"net"
"strconv"
"testing"
"time"
osm "git.loafle.net/overflow/service_matcher-go"
)
func TestFTP(t *testing.T) {
ip := "192.168.100.21"
port := 2121
m := NewMatcher()
conn, err := net.Dial("tcp", net.JoinHostPort(ip, strconv.Itoa(port)))
if err != nil {
t.Error(err)
}
defer conn.Close()
matchCtx := osm.NewMatchCtx(ip, port)
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)
return
}
}
t.Log(m.Name(matchCtx))
t.Log(matchCtx)
}
func TestFTPS(t *testing.T) {
ip := "192.168.100.21"
port := 2121
m := NewMatcher()
dialer := &net.Dialer{
Timeout: 5 * time.Second,
}
conn, err := tls.DialWithDialer(
dialer,
"tcp",
net.JoinHostPort(ip, strconv.Itoa(port)),
&tls.Config{
InsecureSkipVerify: true,
ServerName: ip,
},
)
if err != nil {
t.Error(err)
}
defer conn.Close()
matchCtx := osm.NewMatchCtx(ip, port)
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)
}