~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/codehosting/tests/test_sftp.py

  • Committer: Jonathan Lange
  • Date: 2007-05-21 08:37:41 UTC
  • mto: This revision was merged to the branch mainline in revision 4258.
  • Revision ID: jml@canonical.com-20070521083741-clqmkaj6jxyr6ax7
Add test to catch incorrect use of ConchError.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from twisted.cred.error import UnauthorizedLogin
19
19
from twisted.cred.portal import IRealm, Portal
20
20
 
 
21
from twisted.conch.error import ConchError
21
22
from twisted.conch.checkers import SSHPublicKeyDatabase
22
23
from twisted.conch.ssh.transport import SSHServerTransport
23
24
from twisted.conch.ssh import keys, userauth
197
198
        bytes, language, empty = getNS(payload, 2)
198
199
        self.assertEqual(bytes.decode('UTF8'), u"test\r\nmessage\r\n")
199
200
 
 
201
    def test_requestRaisesConchError(self):
 
202
        # ssh_USERAUTH_REQUEST should raise a ConchError if tryAuth returns
 
203
        # None. Added to catch a bug noticed by pyflakes.
 
204
        # Whitebox test.
 
205
        def mock_try_auth(kind, user, data):
 
206
            return None
 
207
        def mock_eb_bad_auth(reason):
 
208
            reason.trap(ConchError)
 
209
        tryAuth, self.user_auth.tryAuth = self.user_auth.tryAuth, mock_try_auth
 
210
        _ebBadAuth, self.user_auth._ebBadAuth = (self.user_auth._ebBadAuth,
 
211
                                                 mock_eb_bad_auth)
 
212
        self.user_auth.serviceStarted()
 
213
        try:
 
214
            packet = NS('jml') + NS('foo') + NS('public_key') + NS('data')
 
215
            self.user_auth.ssh_USERAUTH_REQUEST(packet)
 
216
        finally:
 
217
            self.user_auth.serviceStopped()
 
218
            self.user_auth.tryAuth = tryAuth
 
219
            self.user_auth._ebBadAuth = _ebBadAuth
 
220
 
200
221
 
201
222
class MockChecker(SSHPublicKeyDatabase):
202
223
    """A very simple public key checker which rejects all offered credentials.