2018-08-31 12:56:36 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
omd "git.loafle.net/overflow/model/discovery"
|
|
|
|
osm "git.loafle.net/overflow/service_matcher-go"
|
2018-09-01 06:07:15 +00:00
|
|
|
"git.loafle.net/overflow_scanner/probe/__test"
|
2018-08-31 12:56:36 +00:00
|
|
|
"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,
|
2018-09-01 06:07:15 +00:00
|
|
|
__test.Zone(),
|
|
|
|
__test.DiscoverHost(
|
|
|
|
__test.DiscoveryConfig(),
|
|
|
|
1,
|
|
|
|
254,
|
|
|
|
__test.DiscoverPort(
|
|
|
|
nil,
|
|
|
|
1,
|
|
|
|
65535,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
__test.DiscoverService(
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2018-08-31 12:56:36 +00:00
|
|
|
)
|
|
|
|
|
2018-09-01 06:07:15 +00:00
|
|
|
targetHost := __test.Host(
|
|
|
|
"atGame",
|
2018-09-03 10:33:20 +00:00
|
|
|
"99",
|
|
|
|
"00:25:b3:fa:ca:9b",
|
2018-09-01 06:07:15 +00:00
|
|
|
)
|
2018-08-31 12:56:36 +00:00
|
|
|
|
|
|
|
type args struct {
|
|
|
|
discoverySession session.DiscoverySession
|
|
|
|
targetPort *omd.Port
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
2018-09-03 10:33:20 +00:00
|
|
|
name: "80",
|
2018-08-31 12:56:36 +00:00
|
|
|
args: args{
|
|
|
|
discoverySession: s,
|
2018-09-01 06:07:15 +00:00
|
|
|
targetPort: __test.Port(
|
|
|
|
targetHost,
|
2024-05-29 11:39:11 +00:00
|
|
|
9100,
|
2018-09-01 06:07:15 +00:00
|
|
|
),
|
2018-08-31 12:56:36 +00:00
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
2018-09-03 07:59:17 +00:00
|
|
|
// {
|
2018-09-03 10:33:20 +00:00
|
|
|
// name: "139",
|
|
|
|
// args: args{
|
|
|
|
// discoverySession: s,
|
|
|
|
// targetPort: __test.Port(
|
|
|
|
// targetHost,
|
|
|
|
// "139",
|
|
|
|
// ),
|
|
|
|
// },
|
|
|
|
// wantErr: false,
|
|
|
|
// },
|
|
|
|
// {
|
2018-09-03 07:59:17 +00:00
|
|
|
// name: "443",
|
|
|
|
// args: args{
|
|
|
|
// discoverySession: s,
|
|
|
|
// targetPort: __test.Port(
|
|
|
|
// targetHost,
|
|
|
|
// "443",
|
|
|
|
// ),
|
|
|
|
// },
|
|
|
|
// wantErr: false,
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// name: "445",
|
|
|
|
// args: args{
|
|
|
|
// discoverySession: s,
|
|
|
|
// targetPort: __test.Port(
|
|
|
|
// targetHost,
|
|
|
|
// "445",
|
|
|
|
// ),
|
|
|
|
// },
|
|
|
|
// wantErr: false,
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// name: "548",
|
|
|
|
// args: args{
|
|
|
|
// discoverySession: s,
|
|
|
|
// targetPort: __test.Port(
|
|
|
|
// targetHost,
|
|
|
|
// "548",
|
|
|
|
// ),
|
|
|
|
// },
|
|
|
|
// wantErr: false,
|
|
|
|
// },
|
2018-08-31 12:56:36 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|