Esempio n. 1
0
 def test_auth_keyfiles_exception(self, mock_get_key, mock_auth_public_key):
     key = paramiko.PKey()
     mock_get_key.side_effect = paramiko.ssh_exception.PasswordRequiredException
     device_handler = JunosDeviceHandler({'name': 'junos'})
     obj = SSHSession(device_handler)
     obj._transport = paramiko.Transport(MagicMock())
     self.assertRaises(AuthenticationError,
         obj._auth,'user', None, ["key_file_name"], False, True)
Esempio n. 2
0
 def test_auth_agent_exception(self, mock_get_key, mock_auth_public_key):
     key = paramiko.PKey()
     mock_get_key.return_value = [key]
     mock_auth_public_key.side_effect = paramiko.ssh_exception.AuthenticationException
     device_handler = JunosDeviceHandler({'name': 'junos'})
     obj = SSHSession(device_handler)
     obj._transport = paramiko.Transport(MagicMock())
     self.assertRaises(AuthenticationError,
         obj._auth,'user', None, [], True, False)
Esempio n. 3
0
 def test_auth_keyfiles(self, mock_get_key, mock_auth_public_key):
     key = paramiko.PKey()
     mock_get_key.return_value = key
     device_handler = JunosDeviceHandler({'name': 'junos'})
     obj = SSHSession(device_handler)
     obj._transport = paramiko.Transport(MagicMock())
     obj._auth('user', 'password', ["key_file_name"], False, True)
     self.assertEqual(
         (mock_auth_public_key.call_args_list[0][0][1]).__repr__(),
         key.__repr__())
Esempio n. 4
0
 def test_auth_agent(self, mock_get_key, mock_auth_public_key):
     key = paramiko.PKey(msg="hello")
     mock_get_key.return_value = [key]
     device_handler = JunosDeviceHandler({'name': 'junos'})
     obj = SSHSession(device_handler)
     obj._transport = paramiko.Transport(MagicMock())
     obj._auth('user', 'password', [], True, True)
     self.assertEqual(
         (mock_auth_public_key.call_args_list[0][0][1]).__repr__(),
         key.__repr__())
Esempio n. 5
0
    def test_auth_default_keyfiles_exception(self, mock_get_key,
                                             mock_auth_public_key, mock_is_file):
        key = paramiko.PKey()
        mock_is_file.return_value = True
        mock_get_key.side_effect = paramiko.ssh_exception.PasswordRequiredException
        device_handler = JunosDeviceHandler({'name': 'junos'})
        obj = SSHSession(device_handler)
        obj._transport = paramiko.Transport(None)
        self.assertRaises(AuthenticationError,
			              obj._auth,'user', None, [], False, True)
Esempio n. 6
0
    def setUp(self):
        hostname = "localhost"
        port = 22
        path = expanduser("~") + "/.ssh/"
        with open(path+"id_rsa.pub") as f:
            data = f.read()
        key = data
        ssh = paramiko.SSHClient()
        sshkey = paramiko.PKey(data=key)
        try:
            ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            ssh.connect(hostname, pkey=sshkey, port=port)
            ssh.close()
        except:
           print "No local SSH-Connection allowed, skipping"
           use_ssh = False

        cluster = Cluster.objects.create(hostname=hostname, port=port, key=key)