57 lines
830 B
Go
57 lines
830 B
Go
package mongodb
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"net"
|
|
"testing"
|
|
|
|
"git.loafle.net/overflow/overflow_discovery/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 := matcher.NewPacket(bytes, n)
|
|
|
|
if m.Match(nil, i, p) {
|
|
t.Log("MongoDB found")
|
|
return
|
|
}
|
|
|
|
t.Error("MongoDB not found")
|
|
}
|
|
|
|
}
|