162 lines
3.1 KiB
Go
162 lines
3.1 KiB
Go
package service
|
|
|
|
import (
|
|
"net"
|
|
"reflect"
|
|
"testing"
|
|
|
|
omd "git.loafle.net/overflow/model/discovery"
|
|
osm "git.loafle.net/overflow/service_matcher-go"
|
|
"git.loafle.net/overflow_scanner/probe/__test"
|
|
"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,
|
|
__test.Zone(),
|
|
__test.DiscoverHost(
|
|
__test.DiscoveryConfig(),
|
|
1,
|
|
254,
|
|
__test.DiscoverPort(
|
|
nil,
|
|
1,
|
|
65535,
|
|
true,
|
|
false,
|
|
__test.DiscoverService(
|
|
nil,
|
|
),
|
|
),
|
|
),
|
|
)
|
|
|
|
targetHost := __test.Host(
|
|
"atGame",
|
|
"99",
|
|
"00:25:b3:fa:ca:9b",
|
|
)
|
|
|
|
type args struct {
|
|
discoverySession session.DiscoverySession
|
|
targetPort *omd.Port
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "80",
|
|
args: args{
|
|
discoverySession: s,
|
|
targetPort: __test.Port(
|
|
targetHost,
|
|
"9100",
|
|
),
|
|
},
|
|
wantErr: false,
|
|
},
|
|
// {
|
|
// name: "139",
|
|
// args: args{
|
|
// discoverySession: s,
|
|
// targetPort: __test.Port(
|
|
// targetHost,
|
|
// "139",
|
|
// ),
|
|
// },
|
|
// wantErr: false,
|
|
// },
|
|
// {
|
|
// 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,
|
|
// },
|
|
}
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|