network_service_matcher/ldap/ldap_test.go

114 lines
1.8 KiB
Go
Raw Normal View History

2017-12-04 07:27:08 +00:00
package ldap
import (
"crypto/tls"
"fmt"
cnsm "git.loafle.net/commons_go/network_service_matcher"
//"git.loafle.net/overflow/overflow_discovery/collector/discovery/scan/matcher/scaninfo"
//"git.loafle.net/overflow/overflow_discovery/collector/discovery/types"
"net"
"testing"
)
//func SetUp() {
// fmt.Println("SetUp")
//}
//
//func TearDown() {
// fmt.Println("TearDown")
//}
//func TestMain(m *testing.M) {
// SetUp()
// m.Run()
// TearDown()
//}
func TestAAAA(t *testing.T) {
///animals := []Animal{Dog{}, Cat{}, Llama{}, JavaProgrammer{}}
var ttt [][]int = make([][]int, 10)
var aaa []int
aaa = append(aaa, 111)
ttt = append(ttt, aaa)
fmt.Println(cap(ttt))
}
func ldapRun(client net.Conn, t *testing.T) {
lm := NewMatcher()
//port := types.NewPort("389", types.NewHost("192.168.1.215"), types.TYPE_TCP)
//scanInfo := scaninfo.NewServiceScanInfo(port)
//var ipport string
//ipport = port.Host.Ip + ":" + string(port.Port)
//
//fmt.Println(ipport)
//client, _ := net.Dial("tcp", ipport)
//defer client.Close()
fmt.Println(lm.PacketCount())
for ii := 0; ii < lm.PacketCount(); ii++ {
pack := lm.Packet(ii)
bytes := make([]byte, 1024)
client.Write(pack.Buffer)
read, _ := client.Read(bytes)
if read <= 0 {
bb := lm.HasResponse(ii)
if !bb {
t.Log("HasResponse good")
break
}
}
fmt.Println(bytes)
b := lm.Match(nil, ii, cnsm.NewPacket(bytes, read))
if b {
t.Log("Good")
}
}
}
func TestLdapTls(t *testing.T) {
conn, err := tls.Dial(
"tcp",
"192.168.1.15:636",
&tls.Config{
InsecureSkipVerify: true,
ServerName: "192.168.1.15",
},
)
if err != nil {
t.Fatal(err)
}
defer conn.Close()
ldapRun(conn, t)
}
func TestLdapNormal(t *testing.T) {
client, _ := net.Dial("tcp", "192.168.1.15:389")
defer client.Close()
ldapRun(client, t)
}