package mongodb import ( "crypto/tls" "git.loafle.net/overflow/overflow_discovery/service/matcher" "net" "testing" ) 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 := NewMongoDBMatcher() 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(i, p, nil) { t.Log("MongoDB found") return } t.Error("MongoDB not found") } }