geneva/tests/test_trace.py

38 lines
1.1 KiB
Python
Raw Permalink Normal View History

2019-12-14 21:08:14 +01:00
import sys
import pytest
2019-12-14 21:08:14 +01:00
# Include the root of the project
sys.path.append("..")
import actions.trace
2020-06-24 14:20:51 +02:00
import layers.packet
import actions.strategy
2019-12-14 21:08:14 +01:00
import actions.utils
import evolve
2019-12-14 21:08:14 +01:00
from scapy.all import IP, TCP
2019-12-14 21:08:14 +01:00
def test_trace(logger):
2019-12-14 21:08:14 +01:00
"""
Tests the trace action primitive.
2019-12-14 21:08:14 +01:00
"""
trace = actions.trace.TraceAction(start_ttl=1, end_ttl=3)
assert str(trace) == "trace{1:3}", "Trace returned incorrect string representation: %s" % str(trace)
2020-06-24 14:20:51 +02:00
packet = layers.packet.Packet(IP(src="127.0.0.1", dst="127.0.0.1")/TCP(sport=2222, dport=3333, seq=100, ack=100, flags="S"))
trace.run(packet, logger)
print("Testing that trace will not run twice:")
assert trace.run(packet, logger) == (None, None)
trace = actions.trace.TraceAction(start_ttl=1, end_ttl=3)
2020-06-24 14:20:51 +02:00
packet = layers.packet.Packet(TCP())
assert trace.run(packet, logger) == (packet, None)
s = "[TCP:flags:PA]-trace{1:3}-| \/ "
assert str(actions.utils.parse(s, logger)) == s
assert not trace.parse("10:4", logger)
assert not trace.parse("10:hi", logger)
assert not trace.parse("", logger)