2020-02-13 21:51:00 +01:00
|
|
|
from scapy.all import IP, TCP
|
2020-05-17 16:15:16 +02:00
|
|
|
import evolve
|
2020-02-13 21:51:00 +01:00
|
|
|
import actions.utils
|
|
|
|
import actions.strategy
|
2020-06-24 14:20:51 +02:00
|
|
|
import layers.packet
|
2020-02-13 21:51:00 +01:00
|
|
|
import actions.sleep
|
|
|
|
import sys
|
|
|
|
# Include the root of the project
|
|
|
|
sys.path.append("..")
|
|
|
|
|
|
|
|
|
2020-05-17 16:15:16 +02:00
|
|
|
def test_basic_sleep(logger):
|
2020-02-13 21:51:00 +01:00
|
|
|
"""
|
|
|
|
Tests the sleep action primitive
|
|
|
|
"""
|
|
|
|
sleep = actions.sleep.SleepAction(.5)
|
|
|
|
assert str(sleep) == "sleep{0.5}", "Sleep returned incorrect string representation: %s" % str(sleep)
|
|
|
|
|
2020-06-24 14:20:51 +02:00
|
|
|
packet = layers.packet.Packet(IP(src="127.0.0.1", dst="127.0.0.1")/TCP()/("data"))
|
2020-02-13 21:51:00 +01:00
|
|
|
packet1, packet2 = sleep.run(packet, logger)
|
|
|
|
|
|
|
|
assert packet1.sleep == .5, "Packet had wrong sleep value"
|
|
|
|
|
2020-05-17 16:15:16 +02:00
|
|
|
def test_sleep_str_parse(logger):
|
2020-02-13 21:51:00 +01:00
|
|
|
"""
|
|
|
|
Tests stringing and parsing a sleep action with a float sleep time
|
|
|
|
"""
|
|
|
|
strat = actions.utils.parse("[TCP:flags:A]-sleep{0.5}-|", logger)
|
|
|
|
|
|
|
|
assert strat.out_actions[0].action_root.time == .5
|
|
|
|
assert "0.5" in str(strat)
|