From 67dc10707a4360f7914354ab4a522584533b8930 Mon Sep 17 00:00:00 2001 From: Rahul Rahul Date: Thu, 21 Jul 2016 16:18:05 -0700 Subject: [PATCH] autotests: test1AP - added new tests and config files APShutdownTest - shutdown the AP after network connection. This will be replaced when hwsim supports signal strength modification InvalidPassphraseTest - Provide an invalid passphrase. --- autotests/test1AP/APShutdownTest.py | 95 +++++++++++++++++++ autotests/test1AP/IntelWIFI_CCMP.conf | 11 +++ .../{IntelWIFI.conf => IntelWIFI_TKIP.conf} | 0 autotests/test1AP/README.txt | 13 +++ autotests/test1AP/invalidPassphrase.conf | 10 ++ autotests/test1AP/invalidPassphraseTest.py | 79 +++++++++++++++ 6 files changed, 208 insertions(+) create mode 100755 autotests/test1AP/APShutdownTest.py create mode 100755 autotests/test1AP/IntelWIFI_CCMP.conf rename autotests/test1AP/{IntelWIFI.conf => IntelWIFI_TKIP.conf} (100%) create mode 100755 autotests/test1AP/invalidPassphrase.conf create mode 100755 autotests/test1AP/invalidPassphraseTest.py diff --git a/autotests/test1AP/APShutdownTest.py b/autotests/test1AP/APShutdownTest.py new file mode 100755 index 00000000..51ea4362 --- /dev/null +++ b/autotests/test1AP/APShutdownTest.py @@ -0,0 +1,95 @@ +#!/usr/bin/python3 + +#built-in python libraries +import unittest +from gi.repository import GLib +import dbus +import time +import logging +import os +from subprocess import Popen, PIPE, STDOUT, call, check_output +import sys +sys.path.append('../utility') #needed to import all the utility modules +import utility +import pty +import signal + +class TestAPShutdown(unittest.TestCase): + def doConnectDisconnect(self): + objectList = utility.getObjectList(bus) + + # start simpleAgent + master, slave = pty.openpty() + proc = Popen([sys.executable, '../utility/simpleAgent.py'], + stdin=PIPE, stdout=slave, close_fds=True) + stdout_handle = os.fdopen(master) + if stdout_handle.readline().rstrip() == "AGENT_REGISTERED": + logger.debug("Agent Registered") + else: + logger.debug("Agent failed to register") + + # close the handles + stdout_handle.close() + os.close(slave) + + networkToConnect = utility.getNetworkToConnectTo(objectList) + # check if networkToConnect is not null. If yes, restart program + # so that the network list is updated. Alternatively, we can scan + # for networks. + if (networkToConnect == ""): + time.sleep(2) + logger.debug("RESTART PROGRAM") + os.execl(sys.executable, sys.executable, * sys.argv) + + self.assertNotEqual(networkToConnect, "") + network = dbus.Interface(bus.get_object(utility.IWD_SERVICE, + networkToConnect), + utility.IWD_NETWORK_INTERFACE) + + status = utility.connect(networkToConnect, self, mainloop, bus) + + if status == False: + #terminate proc + proc.terminate() + return + logger.info("Currently connected to: %s", + utility.getCurrentlyConnectedNetworkName()) + self.assertEqual(utility.getCurrentlyConnectedNetworkName(), + "IntelWIFI") + + #kill AP + pid_bytes = check_output("pgrep hostapd", shell=True) + pid = pid_bytes.decode('utf-8') + logger.debug("shutting down AP with pid: %s", pid) + os.system("kill %d"%int(pid)) + + #should not be connected to any network after AP shutdown + logger.info("After AP shutdown, connected to: %s", + utility.getCurrentlyConnectedNetworkName()) + self.assertEqual(utility.getCurrentlyConnectedNetworkName(), + "") + #terminate proc + proc.terminate() + + # connect to network A. Wait for 2 seconds. Disconnect. + def test_APShutdown(self): + logger.info(sys._getframe().f_code.co_name) + while (True): + if bus.name_has_owner(utility.IWD_SERVICE) == True: + break + self.doConnectDisconnect() + + @classmethod + def setUpClass(cls): + global logger, bus, mainloop + utility.initLogger() + logger = logging.getLogger(__name__) + bus = dbus.SystemBus() + mainloop = GLib.MainLoop() + + @classmethod + def tearDownClass(cls): + mainloop.quit() + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/test1AP/IntelWIFI_CCMP.conf b/autotests/test1AP/IntelWIFI_CCMP.conf new file mode 100755 index 00000000..a6950530 --- /dev/null +++ b/autotests/test1AP/IntelWIFI_CCMP.conf @@ -0,0 +1,11 @@ +interface=wln0 +driver=nl80211 + +hw_mode=g +channel=1 +ssid=IntelWIFI + +wpa=2 +wpa_key_mgmt=WPA-PSK +wpa_pairwise=CCMP +wpa_passphrase=EasilyGuessedPassword diff --git a/autotests/test1AP/IntelWIFI.conf b/autotests/test1AP/IntelWIFI_TKIP.conf similarity index 100% rename from autotests/test1AP/IntelWIFI.conf rename to autotests/test1AP/IntelWIFI_TKIP.conf diff --git a/autotests/test1AP/README.txt b/autotests/test1AP/README.txt index 8be1838b..0f4ba977 100644 --- a/autotests/test1AP/README.txt +++ b/autotests/test1AP/README.txt @@ -1,8 +1,21 @@ scanNetworkTest: This test checks that we find the right AP, as specified in the hostapd conf file. + conf file: IntelWIFI_CCMP.conf, IntelWIFI_TKIP.conf connectDisconnectTest: Connect and disconnect from a network as specified in the hostapd conf file. + conf file: IntelWIFI_CCMP.conf, IntelWIFI_TKIP.conf + +invalidPassphraseTest: Try to connect to a network with an + invalid passphrase. The connection is + unsuccessful. + conf file: invalidPassphrase.conf + +APShutdownTest: Connect to a network. Shutdown the AP. The + connection is lost. + conf file: IntelWIFI_CCMP.conf, IntelWIFI_TKIP.conf + NOTE: Test will be removed once hwsim supports + the ability to modify signal strength. Pre-requisites: 1. Ensure you have hostapd installed. diff --git a/autotests/test1AP/invalidPassphrase.conf b/autotests/test1AP/invalidPassphrase.conf new file mode 100755 index 00000000..9f9afdb9 --- /dev/null +++ b/autotests/test1AP/invalidPassphrase.conf @@ -0,0 +1,10 @@ +interface=wln0 +driver=nl80211 + +hw_mode=g +channel=1 +ssid=IntelWIFI + +wpa=1 +wpa_pairwise=TKIP +wpa_passphrase=WrongPassword diff --git a/autotests/test1AP/invalidPassphraseTest.py b/autotests/test1AP/invalidPassphraseTest.py new file mode 100755 index 00000000..6245655d --- /dev/null +++ b/autotests/test1AP/invalidPassphraseTest.py @@ -0,0 +1,79 @@ +#!/usr/bin/python3 + +#built-in python libraries +import unittest +from gi.repository import GLib +import dbus +import time +import logging +import os +from subprocess import Popen, PIPE, STDOUT +import sys +sys.path.append('../utility') #needed to import all the utility modules +import utility +import pty + +class TestInvalidPassphrase(unittest.TestCase): + def doConnectDisconnect(self): + objectList = utility.getObjectList(bus) + + # start simpleAgent + master, slave = pty.openpty() + proc = Popen([sys.executable, '../utility/simpleAgent.py'], + stdin=PIPE, stdout=slave, close_fds=True) + stdout_handle = os.fdopen(master) + if stdout_handle.readline().rstrip() == "AGENT_REGISTERED": + logger.debug("Agent Registered") + else: + logger.debug("Agent failed to register") + + # close the handles + stdout_handle.close() + os.close(slave) + + networkToConnect = utility.getNetworkToConnectTo(objectList) + # check if networkToConnect is not null. If yes, restart program + # so that the network list is updated. Alternatively, we can scan + # for networks. + if (networkToConnect == ""): + time.sleep(2) + logger.debug("RESTART PROGRAM") + os.execl(sys.executable, sys.executable, * sys.argv) + + self.assertNotEqual(networkToConnect, "") + network = dbus.Interface(bus.get_object(utility.IWD_SERVICE, + networkToConnect), + utility.IWD_NETWORK_INTERFACE) + try: + network.Connect() + except: + errorMsg = "Could not connect to network %s", networkToConnect + logger.debug(errorMsg) + + self.assertEqual(utility.getCurrentlyConnectedNetworkName(), + "") + #terminate proc + proc.terminate() + + # connect to network A. Wait for 2 seconds. Disconnect. + def test_invalidPassphrase(self): + logger.info(sys._getframe().f_code.co_name) + while (True): + if bus.name_has_owner(utility.IWD_SERVICE) == True: + break + self.doConnectDisconnect() + + @classmethod + def setUpClass(cls): + global logger, bus, mainloop + utility.initLogger() + logger = logging.getLogger(__name__) + bus = dbus.SystemBus() + mainloop = GLib.MainLoop() + + @classmethod + def tearDownClass(cls): + mainloop.quit() + +if __name__ == '__main__': + unittest.main(exit=True)