示例#1
0
    def test_get_interfaces_invalid_ap_argument(self):
        """
        Test get_interfaces method with a invalid AP argument
        """

        # create fake interfaces
        interface0 = interfaces.NetworkAdapter("wlan0")
        interface1 = interfaces.NetworkAdapter("wlan1")

        # make both interfaces support AP and monitor
        interface0.set_ap_support(True)
        interface1.set_ap_support(True)

        # add the interfaces to the list
        network_manager = interfaces.NetworkManager(None, "wlan3")
        network_manager._interfaces.append(interface0)
        network_manager._interfaces.append(interface1)

        self.assertRaises(interfaces.ApInterfaceInvalidError,
                          network_manager.get_interfaces)
示例#2
0
    def test_find_interface_automatically_case_4(self):
        """
        Test _find_interface_automatically method when two interfaces are
        given and both interfaces only support monitor mode.
        """

        # create fake interfaces
        interface0 = interfaces.NetworkAdapter("wlan0")
        interface1 = interfaces.NetworkAdapter("wlan1")

        # set AP and monitor support
        interface0.set_monitor_support(True)
        interface1.set_monitor_support(True)

        # add the interfaces to the list
        self.network_manager._interfaces.append(interface0)
        self.network_manager._interfaces.append(interface1)

        self.assertRaises(interfaces.NoApInterfaceFoundError,
                          self.network_manager._find_interface_automatically)
示例#3
0
    def test_get_interfaces_valid_argument(self):
        """
        Test get_interfaces method with a valid arguments for both jamming and
        AP arguments
        """

        # create fake interfaces
        interface0 = interfaces.NetworkAdapter("wlan0")
        interface1 = interfaces.NetworkAdapter("wlan1")

        # make both interfaces support AP and monitor
        interface0.set_monitor_support(True)
        interface1.set_ap_support(True)

        # add the interfaces to the list
        network_manager = interfaces.NetworkManager("wlan0", "wlan1")
        network_manager._interfaces.append(interface0)
        network_manager._interfaces.append(interface1)

        expected = ("wlan0", "wlan1")
        self.assertEqual(network_manager.get_interfaces(), expected)
示例#4
0
    def test_get_interfaces_valid_monitor_argument_no_ap(self):
        """
        Test get_interfaces method with a valid monitor argument but no
        interface with AP mode
        """

        # create fake interfaces
        interface0 = interfaces.NetworkAdapter("wlan0")
        interface1 = interfaces.NetworkAdapter("wlan1")

        # make both interfaces support AP and monitor
        interface0.set_monitor_support(True)
        interface1.set_monitor_support(True)

        # add the interfaces to the list
        network_manager = interfaces.NetworkManager("wlan0", None)
        network_manager._interfaces.append(interface0)
        network_manager._interfaces.append(interface1)

        self.assertRaises(interfaces.NoApInterfaceFoundError,
                          network_manager.get_interfaces)
示例#5
0
    def test_find_interface_no_monitor_interface(self):
        """
        Test _find_interface method asking for a interface with monitor support
        that does not exists
        """

        # create fake interface
        interface0 = interfaces.NetworkAdapter("wlan0")
        self.network_manager._interfaces.append(interface0)

        self.assertRaises(interfaces.NoApInterfaceFoundError,
                          self.network_manager._find_interface, [False, True])
示例#6
0
    def test_find_interface_automatically_case_3(self):
        """
        Test _find_interface_automatically method when two interfaces are
        given. one interfaces support AP and monitor mode while the other
        interface supports neither AP or monitor mode.
        """

        # create fake interfaces
        interface0 = interfaces.NetworkAdapter("wlan0")
        interface1 = interfaces.NetworkAdapter("wlan1")

        # set AP and monitor support
        interface0.set_ap_support(True)
        interface0.set_monitor_support(True)

        # add the interfaces to the list
        self.network_manager._interfaces.append(interface0)
        self.network_manager._interfaces.append(interface1)

        self.assertRaises(interfaces.NoMonitorInterfaceFoundError,
                          self.network_manager._find_interface_automatically)
示例#7
0
    def test_find_interface_automatically_no_monitor_interface(self):
        """
        Test _find_interface_automatically method when no monitor interfaces
        are present
        """

        # create a fake interface with AP mode
        interface = interfaces.NetworkAdapter("wlan0")
        interface.set_ap_support(True)
        self.network_manager._interfaces.append(interface)

        self.assertRaises(interfaces.NoMonitorInterfaceFoundError,
                          self.network_manager._find_interface_automatically)
示例#8
0
    def test_find_interface_ap_exists(self):
        """
        Test _find_interface method asking for a interface with AP support
        that exists
        """

        # create fake interface with AP support
        interface0 = interfaces.NetworkAdapter("wlan0")
        interface0.set_ap_support(True)
        self.network_manager._interfaces.append(interface0)

        actual = self.network_manager._find_interface(has_ap_mode=True)
        self.assertEqual(actual, interface0)
示例#9
0
    def test_find_interface_automatically_case_2(self):
        """
        Test _find_interface_automatically method when two interfaces are
        given. both interfaces support AP mode while only one interface
        supports AP mode.
        """

        # create fake interfaces
        interface0 = interfaces.NetworkAdapter("wlan0")
        interface1 = interfaces.NetworkAdapter("wlan1")

        # set AP and monitor support
        interface0.set_ap_support(True)
        interface0.set_monitor_support(True)
        interface1.set_ap_support(True)

        # add the interfaces to the list
        self.network_manager._interfaces.append(interface0)
        self.network_manager._interfaces.append(interface1)

        expected = (interface0, interface1)
        actual = self.network_manager._find_interface_automatically()

        self.assertEqual(actual, expected)
示例#10
0
    def test_check_compatibility_has_ap_no_monitor(self, mock_pyric):
        """
        Test _check_compatibility method while the interface has AP support
        but no monitor support
        """

        # create a interface
        interface = interfaces.NetworkAdapter("wlan0")

        # set the return value and call the method
        mock_pyric.getcard.return_value = None
        mock_pyric.devmodes.return_value = ["AP"]
        mock_pyric.winterfaces.return_value = ["wlan0"]
        self.network_manager._check_compatibility(interface)

        # check that values are correct
        self.assertTrue(interface.has_ap_mode())
        self.assertFalse(interface.has_monitor_mode())
示例#11
0
    def test_check_compatibility_no_ap_no_monitor(self, mock_iw):
        """
        Test _check_compatibility method while the interface has no AP support
        nor monitor support
        """

        # result to be used
        device_result = ("phy#1\n\tInterface wlan0\n\t\tifindex 4\n\t\twdev "
                         "0x100000001\n\t\taddr 00:c0:ca:81:e2:d8"
                         "\n\t\ttype managed\n")

        # create a interface
        interface = interfaces.NetworkAdapter("wlan0")

        # set the return value and call the method
        mock_iw.return_value = device_result
        self.network_manager._check_compatibility(interface)

        # check that values are correct
        self.assertFalse(interface.has_ap_mode())
        self.assertFalse(interface.has_monitor_mode())
示例#12
0
    def test_check_compatibility_no_ap_has_monitor(self, mock_iw):
        """
        Test _check_compatibility method while the interface doesn't have AP
        support but it has monitor support
        """

        # result to be used
        device_result = ("phy#1\n\tInterface wlan0\n\t\tifindex 4\n\t\twdev "
                         "0x100000001\n\t\taddr 00:c0:ca:81:e2:d8"
                         "\n\t\ttype managed\n")
        device_info = ("\t\t * IBSS\n\t\t * managed\n\t\t * monitor")

        # create a interface
        interface = interfaces.NetworkAdapter("wlan0")

        # set the return value and call the method
        mock_iw.side_effect = [device_result, device_info]
        self.network_manager._check_compatibility(interface)

        # check that values are correct
        self.assertFalse(interface.has_ap_mode())
        self.assertTrue(interface.has_monitor_mode())
示例#13
0
    def setUp(self):
        """ Set up the tests """

        self.adapter_name = "wlan0"
        self.obj = interfaces.NetworkAdapter(self.adapter_name)