Beispiel #1
0
 def _parse_userauth_failure(self, m):
     authlist = m.get_list()
     partial = m.get_boolean()
     if partial:
         self._log(INFO, 'Authentication continues...')
         self._log(DEBUG, 'Methods: ' + str(authlist))
         self.transport.saved_exception = PartialAuthentication(authlist)
     elif self.auth_method not in authlist:
         for msg in (
             'Authentication type ({}) not permitted.'.format(
                 self.auth_method
             ),
             'Allowed methods: {}'.format(authlist),
         ):
             self._log(DEBUG, msg)
         self.transport.saved_exception = BadAuthenticationType(
             'Bad authentication type', authlist
         )
     else:
         self._log(
             INFO,
             'Authentication ({}) failed.'.format(self.auth_method)
         )
     self.authenticated = False
     self.username = None
     if self.auth_event is not None:
         self.auth_event.set()
Beispiel #2
0
 def _parse_userauth_failure(self, m):
     authlist = m.get_list()
     partial = m.get_boolean()
     if partial:
         self._log(INFO, "Authentication continues...")
         self._log(DEBUG, "Methods: " + str(authlist))
         self.transport.saved_exception = PartialAuthentication(authlist)
     elif self.auth_method not in authlist:
         for msg in (
             "Authentication type ({}) not permitted.".format(
                 self.auth_method
             ),
             "Allowed methods: {}".format(authlist),
         ):
Beispiel #3
0
import pickle

import pytest

from paramiko import RSAKey
from paramiko.ssh_exception import (
    BadAuthenticationType,
    PartialAuthentication,
    ChannelException,
    BadHostKeyException,
    ProxyCommandFailure,
)


@pytest.mark.parametrize(['exc'], [
    (BadAuthenticationType("Bad authentication type", ["ok", "also-ok"]), ),
    (PartialAuthentication(["ok", "also-ok"]), ),
    (BadHostKeyException("myhost", RSAKey.generate(2048),
                         RSAKey.generate(2048)), ),
    (ProxyCommandFailure("nc servername 22", 1), ),
    (ChannelException(17, "whatever"), ),
])
def test_ssh_exception_strings(exc):
    assert isinstance(str(exc), str)
    assert isinstance(repr(exc), str)
    if type(exc) != BadHostKeyException:
        ne = pickle.loads(pickle.dumps(exc))
        assert type(ne) == type(exc)
Beispiel #4
0
 def test_PartialAuthentication(self):
     exc = PartialAuthentication(["ok", "also-ok"])
     expected = "Partial authentication; allowed types: ['ok', 'also-ok']"
     assert str(exc) == expected