57 lines
823 B
Go
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")
|
|
}
|
|
|
|
}
|