Exemplo n.º 1
0
    def test_str(self):
        scheme = Scheme('wlan0', 'test')
        assert str(scheme) == 'iface wlan0-test inet dhcp\n'

        scheme = Scheme('wlan0', 'test', {
            'wpa-ssid': 'workwifi',
        })

        self.assertEqual(
            str(scheme), 'iface wlan0-test inet dhcp\n    wpa-ssid workwifi\n')
Exemplo n.º 2
0
    def setUp(self):
        self.tempfile, interfaces = tempfile.mkstemp()

        with open(interfaces, 'w') as f:
            f.write(NETWORK_INTERFACES_FILE)

        self.Scheme = Scheme.for_file(interfaces)
Exemplo n.º 3
0
    def setUp(self):
        self.tempfile, interfaces = tempfile.mkstemp()

        with open(interfaces, 'w') as f:
            f.write(NETWORK_INTERFACES_FILE)

        self.Scheme = Scheme.for_file(interfaces)
Exemplo n.º 4
0
    def test_unencrypted(self):
        cell = Cell()
        cell.ssid = 'SSID'
        cell.encrypted = False

        scheme = Scheme.for_cell('wlan0', 'test', cell)

        self.assertEqual(scheme.options, {
            'wireless-essid': 'SSID',
            'wireless-channel': 'auto',
        })
Exemplo n.º 5
0
    def test_unencrypted(self):
        cell = Cell()
        cell.ssid = 'SSID'
        cell.encrypted = False

        scheme = Scheme.for_cell('wlan0', 'test', cell)

        self.assertEqual(scheme.options, {
            'wireless-essid': 'SSID',
            'wireless-channel': 'auto',
        })
Exemplo n.º 6
0
    def test_wep(self):
        cell = Cell()
        cell.ssid = 'SSID'
        cell.encrypted = True
        cell.encryption_type = 'wep'

        scheme = Scheme.for_cell('wlan0', 'test', cell, 'passkey')

        self.assertEqual(scheme.options, {
            'wireless-essid': 'SSID',
            'wireless-key': 'passkey',
        })
Exemplo n.º 7
0
    def test_wep(self):
        cell = Cell()
        cell.ssid = 'SSID'
        cell.encrypted = True
        cell.encryption_type = 'wep'

        scheme = Scheme.for_cell('wlan0', 'test', cell, 'passkey')

        self.assertEqual(scheme.options, {
            'wireless-essid': 'SSID',
            'wireless-key': 'passkey',
        })
Exemplo n.º 8
0
    def test_wpa(self):
        cell = Cell()
        cell.ssid = 'SSID'
        cell.encrypted = True
        cell.encryption_type = 'wpa'

        scheme = Scheme.for_cell('wlan0', 'test', cell, 'passkey')

        self.assertEqual(scheme.options, {
            'wpa-ssid': 'SSID',
            'wpa-psk': 'ea1548d4e8850c8d94c5ef9ed6fe483981b64c1436952cb1bf80c08a68cdc763',
            'wireless-channel': 'auto',
        })
Exemplo n.º 9
0
    def test_wpa(self):
        cell = Cell()
        cell.ssid = 'SSID'
        cell.encrypted = True
        cell.encryption_type = 'wpa'

        scheme = Scheme.for_cell('wlan0', 'test', cell, 'passkey')

        self.assertEqual(scheme.options, {
            'wpa-ssid': 'SSID',
            'wpa-psk': 'ea1548d4e8850c8d94c5ef9ed6fe483981b64c1436952cb1bf80c08a68cdc763',
            'wireless-channel': 'auto',
        })
Exemplo n.º 10
0
    def test_unencrypted(self):
        cell = Cell()
        cell.ssid = "SSID"
        cell.encrypted = False

        scheme = Scheme.for_cell("wlan0", "test", cell)

        self.assertEqual(
            scheme.options,
            {
                "wireless-essid": ["SSID"],
                "wireless-channel": ["auto"],
            },
        )
Exemplo n.º 11
0
    def test_wep_ascii(self):
        cell = Cell()
        cell.ssid = 'SSID'
        cell.encrypted = True
        cell.encryption_type = 'wep'

        # ascii key lengths: 5, 13, 16, 29
        ascii_keys = ('a' * 5, 'a' * 13, 'a' * 16, 'a' * 29)
        for key in ascii_keys:
            scheme = Scheme.for_cell('wlan0', 'test', cell, key)

            self.assertEqual(scheme.options, {
                'wireless-essid': 'SSID',
                'wireless-key': 's:' + key
            })
Exemplo n.º 12
0
    def test_wep_hex(self):
        cell = Cell()
        cell.ssid = 'SSID'
        cell.encrypted = True
        cell.encryption_type = 'wep'

        # hex key lengths: 10, 26, 32, 58
        hex_keys = ("01234567ab", "0123456789abc" * 2, "0123456789abcdef" * 2, "0123456789abc" * 2 + "0123456789abcdef" * 2)
        for key in hex_keys:
            scheme = Scheme.for_cell('wlan0', 'test', cell, key)

            self.assertEqual(scheme.options, {
                'wireless-essid': ['SSID'],
                'wireless-key': [key]
            })
Exemplo n.º 13
0
    def test_wep_hex(self):
        cell = Cell()
        cell.ssid = 'SSID'
        cell.encrypted = True
        cell.encryption_type = 'wep'

        # hex key lengths: 10, 26, 32, 58
        hex_keys = ("01234567ab", "0123456789abc" * 2, "0123456789abcdef" * 2, "0123456789abc" * 2 + "0123456789abcdef" * 2)
        for key in hex_keys:
            scheme = Scheme.for_cell('wlan0', 'test', cell, key)

            self.assertEqual(scheme.options, {
                'wireless-essid': 'SSID',
                'wireless-key': key
            })
Exemplo n.º 14
0
    def test_wep_ascii(self):
        cell = Cell()
        cell.ssid = 'SSID'
        cell.encrypted = True
        cell.encryption_type = 'wep'

        # ascii key lengths: 5, 13, 16, 29
        ascii_keys = ('a' * 5, 'a' * 13, 'a' * 16, 'a' * 29)
        for key in ascii_keys:
            scheme = Scheme.for_cell('wlan0', 'test', cell, key)

            self.assertEqual(scheme.options, {
                'wireless-essid': 'SSID',
                'wireless-key': 's:' + key
            })
Exemplo n.º 15
0
 def test_activate_is_called_with_good_args(self):
     args = ['sudo', '/sbin/ifdown', 'wlan0']
     kwargs = {'stderr': subprocess.STDOUT}
     scheme = Scheme('wlan0', 'test')
     with patch.object(subprocess,
                       'check_output',
                       return_value=SUCCESSFUL_IFUP_OUTPUT):
         scheme.activate(sudo=True)
         subprocess.check_output.assert_any_call(args, **kwargs)
         args = ['/sbin/ifdown', 'wlan0']
         scheme.activate()
         subprocess.check_output.assert_any_call(args, **kwargs)
Exemplo n.º 16
0
    def test_wpa(self):
        cell = Cell()
        cell.ssid = "SSID"
        cell.encrypted = True
        cell.encryption_type = "wpa"

        scheme = Scheme.for_cell("wlan0", "test", cell, "passkey")

        self.assertEqual(
            scheme.options,
            {
                "wpa-ssid": ["SSID"],
                "wpa-psk": [
                    "ea1548d4e8850c8d94c5ef9ed6fe483981b64c1436952cb1bf80c08a68cdc763"
                ],
                "wireless-channel": ["auto"],
            },
        )
Exemplo n.º 17
0
    def test_wep_ascii(self):
        cell = Cell()
        cell.ssid = "SSID"
        cell.encrypted = True
        cell.encryption_type = "wep"

        # ascii key lengths: 5, 13, 16, 29
        ascii_keys = ("a" * 5, "a" * 13, "a" * 16, "a" * 29)
        for key in ascii_keys:
            scheme = Scheme.for_cell("wlan0", "test", cell, key)

            self.assertEqual(
                scheme.options,
                {
                    "wireless-essid": ["SSID"],
                    "wireless-key": ["s:" + key]
                },
            )
Exemplo n.º 18
0
    def test_wep_hex(self):
        cell = Cell()
        cell.ssid = "SSID"
        cell.encrypted = True
        cell.encryption_type = "wep"

        # hex key lengths: 10, 26, 32, 58
        hex_keys = (
            "01234567ab",
            "0123456789abc" * 2,
            "0123456789abcdef" * 2,
            "0123456789abc" * 2 + "0123456789abcdef" * 2,
        )
        for key in hex_keys:
            scheme = Scheme.for_cell("wlan0", "test", cell, key)

            self.assertEqual(scheme.options, {
                "wireless-essid": ["SSID"],
                "wireless-key": [key]
            })
Exemplo n.º 19
0
    def test_find(self):
        work = Scheme.find('wlan0', 'work')

        assert work.options['wpa-ssid'] == 'workwifi'
Exemplo n.º 20
0
 def test_successful_connection(self):
     scheme = Scheme('wlan0', 'test')
     connection = scheme.parse_ifup_output(SUCCESSFUL_IFUP_OUTPUT)
     self.assertEqual(connection.scheme, scheme)
     self.assertEqual(connection.ip_address, '192.168.1.113')
Exemplo n.º 21
0
 def test_delete(self):
     work = Scheme.find('wlan0', 'work')
     work.delete()
     self.assertIsNone(Scheme.find('wlan0', 'work'))
     assert Scheme.find('wlan0', 'coffee')
Exemplo n.º 22
0
    def test_find(self):
        work = Scheme.find('wlan0', 'work')

        assert work.options['wpa-ssid'] == 'workwifi'
Exemplo n.º 23
0
    def test_save(self):
        scheme = Scheme('wlan0', 'test')
        scheme.save()

        assert Scheme.find('wlan0', 'test')
Exemplo n.º 24
0
    def test_save(self):
        scheme = Scheme('wlan0', 'test')
        scheme.save()

        assert Scheme.find('wlan0', 'test')
Exemplo n.º 25
0
 def test_failed_connection(self):
     scheme = Scheme('wlan0', 'test')
     self.assertRaises(ConnectionError, scheme.parse_ifup_output,
                       FAILED_IFUP_OUTPUT)
Exemplo n.º 26
0
 def test_successful_connection(self):
     scheme = Scheme('wlan0', 'test')
     connection = scheme.parse_ifup_output(SUCCESSFUL_IFUP_OUTPUT)
     self.assertEqual(connection.scheme, scheme)
     self.assertEqual(connection.ip_address, '192.168.1.113')