network_service_matcher/mysql/mysql_test.go

72 lines
1.1 KiB
Go
Raw Permalink Normal View History

2017-12-04 07:27:08 +00:00
package mysql
import (
"crypto/tls"
"net"
"testing"
cnsm "git.loafle.net/commons_go/network_service_matcher"
)
func TestMySql(t *testing.T) {
m := NewMatcher()
/*
192.168.1.103:3306 - normal
192.168.1.105:8306 - ssl
192.168.1.203:3306 - mysql with error code
*/
conn, _ := net.Dial("tcp", "192.168.1.15:33068")
defer conn.Close()
bytes := make([]byte, 1024)
n, _ := conn.Read(bytes)
p := cnsm.NewPacket(bytes, n)
if m.Match(nil, 0, p) {
t.Log(m.ServiceName())
return
}
t.Error("MySQL not found")
}
func TestCassandraTLS(t *testing.T) {
m := NewMatcher()
conn, err := tls.Dial(
"tcp",
"192.168.1.105:8306",
&tls.Config{
InsecureSkipVerify: true,
ServerName: "192.168.1.105",
},
)
if err != nil {
t.Fatal(err)
}
defer conn.Close()
for i := 0; i < m.PacketCount(); i++ {
pack := m.Packet(i)
conn.Write(pack.Buffer)
bytes := make([]byte, 1024)
n, _ := conn.Read(bytes)
p := cnsm.NewPacket(bytes, n)
if m.Match(nil, i, p) {
t.Log(m.ServiceName())
return
}
t.Error("MySQL not found")
}
}