From e74c434f9cf32a2a53439df8c408559240660b2c Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Tue, 27 Feb 2018 00:50:20 -0800 Subject: [PATCH 1/2] Removed SerialTestClass() by deleting `serialtestclass.py` * Removes imports from both tests files * Fixes test_serial use of the `SerialTestClass()` * Still fails TUN testing use of old `SerialTestClass()` --- tests/serialtestclass.py | 17 ----------------- tests/test_serial.py | 8 ++++---- tests/test_tun.py | 1 - 3 files changed, 4 insertions(+), 22 deletions(-) delete mode 100644 tests/serialtestclass.py diff --git a/tests/serialtestclass.py b/tests/serialtestclass.py deleted file mode 100644 index 8b53f19..0000000 --- a/tests/serialtestclass.py +++ /dev/null @@ -1,17 +0,0 @@ -# Testing serial ports - -# Import modules -import serial - - -class SerialTestClass(object): - """A mock serial port test class""" - def __init__(self): - """Creates a mock serial port which is a loopback object""" - self._port = "loop://" - self._timeout = 0 - self._baudrate = 115200 - self.serialPort = \ - serial.serial_for_url(url=self._port, - timeout=self._timeout, - baudrate=self._baudrate) diff --git a/tests/test_serial.py b/tests/test_serial.py index 837337c..5a715f4 100644 --- a/tests/test_serial.py +++ b/tests/test_serial.py @@ -3,15 +3,15 @@ import string from faradayio import faraday -from tests.serialtestclass import SerialTestClass +# from tests.serialtestclass import SerialTestClass def test_socketOne(): """Simple test to make sure loopback serial port created successfully""" - serialPort = SerialTestClass() + serialInstance = SerialTestClass() testStr = "Hello World!" - serialPort.serialPort.write(testStr.encode(encoding='utf_8')) - res = serialPort.serialPort.read(len(testStr)) + serialInstance.serialPort.write(testStr.encode(encoding='utf_8')) + res = serialInstance.serialPort.read(len(testStr)) assert res.decode("utf-8") == testStr diff --git a/tests/test_tun.py b/tests/test_tun.py index f636595..ce37e64 100644 --- a/tests/test_tun.py +++ b/tests/test_tun.py @@ -4,7 +4,6 @@ import threading from faradayio import faraday -from tests.serialtestclass import SerialTestClass from scapy.all import UDP, IP, sendp From f5eb1cc37dede4259b7a727fb2ae8513bbb1c469 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Tue, 27 Feb 2018 00:54:43 -0800 Subject: [PATCH 2/2] Fixed use of Serial Ports with removal of `serialtestclass.py` * Unit test code still used the `serialtestclass.py` which this now moved testing to `faradayio` module implementation. * Fixed various serial port calls throughout testing to use correct methodology. --- tests/test_serial.py | 6 +++--- tests/test_tun.py | 16 ++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/test_serial.py b/tests/test_serial.py index 5a715f4..30757c2 100644 --- a/tests/test_serial.py +++ b/tests/test_serial.py @@ -8,7 +8,7 @@ def test_socketOne(): """Simple test to make sure loopback serial port created successfully""" - serialInstance = SerialTestClass() + serialInstance = faraday.SerialTestClass() testStr = "Hello World!" serialInstance.serialPort.write(testStr.encode(encoding='utf_8')) res = serialInstance.serialPort.read(len(testStr)) @@ -36,7 +36,7 @@ def test_socketOne(): ]) def test_serialParamaterizedSynchSend(test_input): # Create class object necessary for test - serialInstance = SerialTestClass() + serialInstance = faraday.SerialTestClass() faradayRadio = faraday.Faraday(serialInstance.serialPort) # Create slip message to test against @@ -77,7 +77,7 @@ def test_serialParamaterizedSynchReceive(test_input): """ # Create class object necessary for test - serialInstance = SerialTestClass() + serialInstance = faraday.SerialTestClass() slip = sliplib.Driver() faradayRadio = faraday.Faraday(serialInstance.serialPort) diff --git a/tests/test_tun.py b/tests/test_tun.py index ce37e64..589a524 100644 --- a/tests/test_tun.py +++ b/tests/test_tun.py @@ -11,7 +11,8 @@ def test_tunSetup(): """Setup a Faraday TUN and check initialized values""" # Create a test serial port - serialPort = SerialTestClass() + serialInstance = faraday.SerialTestClass() + serialPort = serialInstance.serialPort # Create test TUN monitor which sets up a python-pytun TUN device at _TUN isRunning = threading.Event() @@ -32,7 +33,8 @@ def test_tunSend(): data and check that the IP payload is valid with scapy. """ # Create a test serial port - serialPort = SerialTestClass() + serialInstance = faraday.SerialTestClass() + serialPort = serialInstance.serialPort # Create test TUN monitor which sets up a python-pytun TUN device at _TUN isRunning = threading.Event() @@ -85,7 +87,8 @@ def test_tunSlipSend(): to TUN/IP nor IP to TUN data validation. """ # Create a test serial port - serialPort = SerialTestClass() + serialInstance = faraday.SerialTestClass() + serialPort = serialInstance.serialPort # Configure destination IP:port destHost = '10.0.0.2' @@ -94,7 +97,7 @@ def test_tunSlipSend(): # Start the monitor isRunning = threading.Event() isRunning.set() - TUNMonitor = faraday.Monitor(serialPort=serialPort.serialPort, + TUNMonitor = faraday.Monitor(serialPort=serialPort, isRunning=isRunning) # Create an IP packet to send from TUN IP:port (arbitrary) to dest IP:port @@ -145,7 +148,8 @@ def test_serialToTUN(): SLIP. Send it to the TUN and verify that the IP:PORT receives the message. """ # Create a test serial port for TUN Monitor class. Won't be used. - serialPort = SerialTestClass() + serialInstance = faraday.SerialTestClass() + serialPort = serialInstance.serialPort # Configure TUN IP:PORT and IP Packet source IP:PORT parameters for test sourceAddress = '10.0.0.2' @@ -155,7 +159,7 @@ def test_serialToTUN(): # Start a TUN Monitor class isRunning = threading.Event() isRunning.set() - TUNMonitor = faraday.Monitor(serialPort=serialPort.serialPort, + TUNMonitor = faraday.Monitor(serialPort=serialPort, isRunning=isRunning) # Open a socket for UDP packets and bind it to the TUN address:port