75 lines
1.1 KiB
Go
75 lines
1.1 KiB
Go
package cassandra
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"net"
|
|
"testing"
|
|
|
|
"git.loafle.net/overflow/overflow_discovery/service/matcher"
|
|
)
|
|
|
|
func TestCassandra(t *testing.T) {
|
|
|
|
m := NewMatcher()
|
|
|
|
conn, err := net.Dial("tcp", "192.168.1.16:19042")
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
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 := matcher.NewPacket(bytes, n)
|
|
|
|
if m.Match(nil, i, p) {
|
|
t.Log("Cassandra found")
|
|
return
|
|
}
|
|
|
|
t.Error("Cassandra not found")
|
|
}
|
|
|
|
}
|
|
|
|
func TestCassandraTLS(t *testing.T) {
|
|
|
|
m := NewMatcher()
|
|
|
|
conn, err := tls.Dial(
|
|
"tcp",
|
|
"192.168.1.16:19042",
|
|
&tls.Config{
|
|
InsecureSkipVerify: true,
|
|
ServerName: "192.168.1.16",
|
|
},
|
|
)
|
|
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 := matcher.NewPacket(bytes, n)
|
|
|
|
if m.Match(nil, i, p) {
|
|
t.Log("Cassandra found")
|
|
return
|
|
}
|
|
|
|
t.Error("Cassandra not found")
|
|
}
|
|
|
|
}
|