probe/discovery/service/service-tcp_test.go
2018-08-31 21:56:36 +09:00

183 lines
4.1 KiB
Go

package service
import (
"encoding/json"
"net"
"reflect"
"testing"
omd "git.loafle.net/overflow/model/discovery"
omm "git.loafle.net/overflow/model/meta"
osm "git.loafle.net/overflow/service_matcher-go"
"git.loafle.net/overflow_scanner/probe/discovery/session"
"git.loafle.net/overflow_scanner/probe/discovery/types"
)
func Test_scanTCP(t *testing.T) {
s := session.NewMockDiscoverySession(
"testRequester",
types.DiscoveryRequestTypeHost,
&omd.Zone{
Network: "192.168.1.0/24",
Iface: "enp3s0",
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
Address: "192.168.1.101",
Mac: "44:8a:5b:f1:f1:f3",
},
&omd.DiscoverHost{
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
FirstScanRange: "192.168.1.1",
LastScanRange: "192.168.1.254",
DiscoveryConfig: &omd.DiscoveryConfig{},
DiscoverPort: &omd.DiscoverPort{
FirstScanRange: 1,
LastScanRange: 1024,
IncludeTCP: true,
DiscoverService: &omd.DiscoverService{},
},
},
)
targetHost := &omd.Host{
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
Name: "atGame",
Address: "192.168.1.1",
Mac: "00:11:32:7f:20:61",
Zone: s.Zone(),
}
targetPort80 := &omd.Port{
MetaPortType: omm.ToMetaPortType(omm.MetaPortTypeEnumTCP),
PortNumber: json.Number("80"),
Host: targetHost,
}
targetPort139 := &omd.Port{
MetaPortType: omm.ToMetaPortType(omm.MetaPortTypeEnumTCP),
PortNumber: json.Number("139"),
Host: targetHost,
}
targetPort443 := &omd.Port{
MetaPortType: omm.ToMetaPortType(omm.MetaPortTypeEnumTCP),
PortNumber: json.Number("443"),
Host: targetHost,
}
targetPort445 := &omd.Port{
MetaPortType: omm.ToMetaPortType(omm.MetaPortTypeEnumTCP),
PortNumber: json.Number("445"),
Host: targetHost,
}
targetPort548 := &omd.Port{
MetaPortType: omm.ToMetaPortType(omm.MetaPortTypeEnumTCP),
PortNumber: json.Number("548"),
Host: targetHost,
}
type args struct {
discoverySession session.DiscoverySession
targetPort *omd.Port
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "80",
args: args{
discoverySession: s,
targetPort: targetPort80,
},
wantErr: false,
},
{
name: "139",
args: args{
discoverySession: s,
targetPort: targetPort139,
},
wantErr: false,
},
{
name: "443",
args: args{
discoverySession: s,
targetPort: targetPort443,
},
wantErr: false,
},
{
name: "445",
args: args{
discoverySession: s,
targetPort: targetPort445,
},
wantErr: false,
},
{
name: "548",
args: args{
discoverySession: s,
targetPort: targetPort548,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := scanTCP(tt.args.discoverySession, tt.args.targetPort); (err != nil) != tt.wantErr {
t.Errorf("scanTCP() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func Test_hadlePrePacket(t *testing.T) {
type args struct {
info osm.MatchInfo
_connector connector
conn net.Conn
packet *osm.Packet
}
tests := []struct {
name string
args args
want osm.Matcher
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := hadlePrePacket(tt.args.info, tt.args._connector, tt.args.conn, tt.args.packet); !reflect.DeepEqual(got, tt.want) {
t.Errorf("hadlePrePacket() = %v, want %v", got, tt.want)
}
})
}
}
func Test_hadlePostPacket(t *testing.T) {
type args struct {
info osm.MatchInfo
_connector connector
targetPort *omd.Port
limitedMatchers []osm.Matcher
}
tests := []struct {
name string
args args
want osm.Matcher
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := hadlePostPacket(tt.args.info, tt.args._connector, tt.args.targetPort, tt.args.limitedMatchers); !reflect.DeepEqual(got, tt.want) {
t.Errorf("hadlePostPacket() = %v, want %v", got, tt.want)
}
})
}
}