Ejemplo n.º 1
0
func TestInquisitorSourceReceiveOne(t *testing.T) {

	_, dispatcher, sniffer := SetupTestInquisitor()

	ip := layers.IPv4{
		SrcIP:    net.IP{1, 2, 3, 4},
		DstIP:    net.IP{2, 3, 4, 5},
		Version:  4,
		TTL:      64,
		Protocol: layers.IPProtocolTCP,
	}
	tcp := layers.TCP{
		Seq:     3,
		SYN:     false,
		SrcPort: 1,
		DstPort: 2,
	}
	flow := types.NewTcpIpFlowFromLayers(ip, tcp)
	p := types.PacketManifest{
		Timestamp: time.Now(),
		Flow:      flow,
		IP:        ip,
		TCP:       tcp,
		Payload:   []byte{1, 2, 3, 4, 5, 6, 7},
	}

	log.Print("before receive packet")
	dispatcher.ReceivePacket(&p)
	log.Print("after receive packet")
	connsChan := dispatcher.GetObservedConnectionsChan(1)
	log.Print("fu1")
	<-connsChan
	log.Print("fu2")
	log.Print("after connsChan receive")
	conns := dispatcher.Connections()
	log.Print("fu3")
	if len(conns) != 1 {
		t.Fatalf("number of connections %d is not 1", len(conns))
	}
	conn := conns[0]
	mockConn := conn.(*MockConnection)
	log.Print("listen to packet observer chan")
	<-mockConn.packetObserverChan
	sniffer.Stop()
}
Ejemplo n.º 2
0
func TestInquisitorResetTwice(t *testing.T) {

	_, dispatcher, sniffer := SetupTestInquisitor()

	startSeq := 3
	ip1 := layers.IPv4{
		SrcIP:    net.IP{1, 2, 3, 4},
		DstIP:    net.IP{2, 3, 4, 5},
		Version:  4,
		TTL:      64,
		Protocol: layers.IPProtocolTCP,
	}
	tcp1 := layers.TCP{
		Seq:     uint32(startSeq),
		SYN:     false,
		RST:     true,
		SrcPort: 1,
		DstPort: 2,
	}
	flow1 := types.NewTcpIpFlowFromLayers(ip1, tcp1)
	packet1 := types.PacketManifest{
		Timestamp: time.Now(),
		Flow:      flow1,
		IP:        ip1,
		TCP:       tcp1,
		Payload:   []byte{1, 2, 3, 4, 5, 6, 7},
	}

	ip2 := layers.IPv4{
		SrcIP:    net.IP{1, 2, 3, 4},
		DstIP:    net.IP{2, 3, 4, 5},
		Version:  4,
		TTL:      64,
		Protocol: layers.IPProtocolTCP,
	}
	tcp2 := layers.TCP{
		Seq:     uint32(startSeq + len(packet1.Payload)),
		SYN:     false,
		RST:     true,
		SrcPort: 1,
		DstPort: 2,
	}
	flow2 := types.NewTcpIpFlowFromLayers(ip2, tcp2)
	packet2 := types.PacketManifest{
		Timestamp: time.Now(),
		Flow:      flow2,
		IP:        ip2,
		TCP:       tcp2,
		Payload:   []byte{1, 2, 3, 4, 5, 6, 7},
	}
	connsChan := dispatcher.GetObservedConnectionsChan(1)
	dispatcher.ReceivePacket(&packet1)
	<-connsChan
	conns := dispatcher.Connections()
	if len(conns) != 1 {
		t.Fatalf("number of connections %d is not 1", len(conns))
	}
	conn := conns[0]
	mockConn := conn.(*MockConnection)
	<-mockConn.packetObserverChan
	conns = dispatcher.Connections()
	if len(conns) != 1 {
		t.Fatalf("number of connections %d is not 1", len(conns))
	}
	conn = conns[0]
	mockConn = conn.(*MockConnection)
	dispatcher.ReceivePacket(&packet2)
	<-mockConn.packetObserverChan
	sniffer.Stop()
}