probe/discovery/protocol/arp/arp_test.go

145 lines
3.1 KiB
Go
Raw Normal View History

2018-08-31 05:15:46 +00:00
package arp
import (
"net"
"reflect"
"testing"
omd "git.loafle.net/overflow/model/discovery"
omm "git.loafle.net/overflow/model/meta"
"git.loafle.net/overflow_scanner/probe/discovery/session"
"git.loafle.net/overflow_scanner/probe/discovery/types"
"git.loafle.net/overflow_scanner/probe/internal/pcap"
"github.com/google/gopacket/layers"
)
func TestScan(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{},
},
)
type args struct {
discoverySession session.DiscoverySession
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "1",
args: args{
discoverySession: s,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := Scan(tt.args.discoverySession); (err != nil) != tt.wantErr {
t.Errorf("Scan() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func Test_sendARP(t *testing.T) {
type args struct {
ps pcap.PCapScanner
zone *omd.Zone
targetHosts []net.IP
}
tests := []struct {
name string
args args
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := sendARP(tt.args.ps, tt.args.zone, tt.args.targetHosts); (err != nil) != tt.wantErr {
t.Errorf("sendARP() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func Test_handlePacketARP(t *testing.T) {
type args struct {
zone *omd.Zone
targetHosts []net.IP
hosts map[string]*omd.Host
packet *layers.ARP
}
tests := []struct {
name string
args args
want *omd.Host
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := handlePacketARP(tt.args.zone, tt.args.targetHosts, tt.args.hosts, tt.args.packet); !reflect.DeepEqual(got, tt.want) {
t.Errorf("handlePacketARP() = %v, want %v", got, tt.want)
}
})
}
}
func Test_makePacketEthernet(t *testing.T) {
type args struct {
hw net.HardwareAddr
}
tests := []struct {
name string
args args
want layers.Ethernet
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := makePacketEthernet(tt.args.hw); !reflect.DeepEqual(got, tt.want) {
t.Errorf("makePacketEthernet() = %v, want %v", got, tt.want)
}
})
}
}
func Test_makePacketARP(t *testing.T) {
type args struct {
hw net.HardwareAddr
ip net.IP
}
tests := []struct {
name string
args args
want layers.ARP
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := makePacketARP(tt.args.hw, tt.args.ip); !reflect.DeepEqual(got, tt.want) {
t.Errorf("makePacketARP() = %v, want %v", got, tt.want)
}
})
}
}