Пример #1
0
    def test_identity_auth(self):
        class _SSHClient(SSHClient):
            IDENTITIES = (self.user_key, )

        client = SSHClient(self.host,
                           port=self.port,
                           pkey=self.user_key,
                           num_retries=1,
                           allow_agent=False)
        client.disconnect()
        client.pkey = None
        del client.session
        del client.sock
        client._connect(self.host, self.port)
        client._init_session()
        client.IDENTITIES = (self.user_key, )
        # Default identities auth only should succeed
        client._identity_auth()
        client.disconnect()
        client._connect(self.host, self.port)
        client._init_session()
        # Auth should succeed
        self.assertIsNone(client.auth())
        # Standard init with custom identities
        client = _SSHClient(self.host,
                            port=self.port,
                            num_retries=1,
                            allow_agent=False)
        self.assertIsInstance(client, SSHClient)
Пример #2
0
 def test_manual_auth(self):
     client = SSHClient(self.host,
                        port=self.port,
                        pkey=self.user_key,
                        num_retries=1,
                        allow_agent=False)
     client.session.disconnect()
     del client.session
     del client.sock
     client._connect(self.host, self.port)
     client._init_session()
     # Identity auth
     client.pkey = None
     client.session.disconnect()
     del client.session
     del client.sock
     client._connect(self.host, self.port)
     client.session = Session()
     client.session.handshake(client.sock)
     self.assertRaises(AuthenticationException, client.auth)