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, timeout=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() del client.session del client.sock 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)
def test_agent_auth_fake_success(self): def _agent_auth(): return client = SSHClient(self.host, port=self.port, pkey=self.user_key, num_retries=1, allow_agent=True, identity_auth=False) client.session.disconnect() client.pkey = None client._connect(self.host, self.port) client._agent_auth = _agent_auth self.assertIsNone(client.auth())
def test_agent_auth_failure(self): class UnknownError(Exception): pass def _agent_auth_unk(): raise UnknownError def _agent_auth_agent_err(): raise AuthenticationDenied client = SSHClient(self.host, port=self.port, pkey=self.user_key, num_retries=1, allow_agent=True, identity_auth=False) client.session.disconnect() client.pkey = None client._connect(self.host, self.port) client._agent_auth = _agent_auth_unk self.assertRaises(AuthenticationError, client.auth) client._agent_auth = _agent_auth_agent_err self.assertRaises(AuthenticationError, client.auth)