network_service_matcher/mongodb/mongodb_test.go
crusader ac4d422cd9 ing
2017-12-04 16:27:08 +09:00

57 lines
823 B
Go

package mongodb
import (
"crypto/tls"
"net"
"testing"
cnsm "git.loafle.net/commons_go/network_service_matcher"
)
func TestMongoNor(t *testing.T) {
conn, _ := net.Dial("tcp", "192.168.1.16:37017")
defer conn.Close()
MongoRun(conn, t)
}
func TestMongoTLS(t *testing.T) {
conn, _ := tls.Dial(
"tcp",
"192.168.1.16:47017",
&tls.Config{
InsecureSkipVerify: true,
ServerName: "192.168.1.16",
},
)
defer conn.Close()
MongoRun(conn, t)
}
func MongoRun(conn net.Conn, t *testing.T) {
m := NewMatcher()
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("MongoDB found")
return
}
t.Error("MongoDB not found")
}
}