示例#1
0
 def test_requestAvatarIdInvalidCredential(self):
     """
     If the passed credentials aren't handled by any registered checker,
     L{SSHProtocolChecker} should raise L{UnhandledCredentials}.
     """
     checker = checkers.SSHProtocolChecker()
     d = checker.requestAvatarId(UsernamePassword('test', 'test'))
     return self.assertFailure(d, UnhandledCredentials)
示例#2
0
 def test_registerChecker(self):
     """
     L{SSHProcotolChecker.registerChecker} should add the given checker to
     the list of registered checkers.
     """
     checker = checkers.SSHProtocolChecker()
     self.assertEqual(checker.credentialInterfaces, [])
     checker.registerChecker(checkers.SSHPublicKeyDatabase(), )
     self.assertEqual(checker.credentialInterfaces, [ISSHPrivateKey])
     self.assertIsInstance(checker.checkers[ISSHPrivateKey],
                           checkers.SSHPublicKeyDatabase)
示例#3
0
 def test_requestAvatarId(self):
     """
     L{SSHProtocolChecker.requestAvatarId} should defer to one if its
     registered checkers to authenticate a user.
     """
     checker = checkers.SSHProtocolChecker()
     passwordDatabase = InMemoryUsernamePasswordDatabaseDontUse()
     passwordDatabase.addUser(b'test', b'test')
     checker.registerChecker(passwordDatabase)
     d = checker.requestAvatarId(UsernamePassword(b'test', b'test'))
     def _callback(avatarId):
         self.assertEqual(avatarId, b'test')
     return d.addCallback(_callback)
示例#4
0
 def test_registerCheckerWithInterface(self):
     """
     If a apecific interface is passed into
     L{SSHProtocolChecker.registerChecker}, that interface should be
     registered instead of what the checker specifies in
     credentialIntefaces.
     """
     checker = checkers.SSHProtocolChecker()
     self.assertEqual(checker.credentialInterfaces, [])
     checker.registerChecker(checkers.SSHPublicKeyDatabase(),
                             IUsernamePassword)
     self.assertEqual(checker.credentialInterfaces, [IUsernamePassword])
     self.assertIsInstance(checker.checkers[IUsernamePassword],
                           checkers.SSHPublicKeyDatabase)
示例#5
0
    def test_requestAvatarIdWithNotEnoughAuthentication(self):
        """
        If the client indicates that it is never satisfied, by always returning
        False from _areDone, then L{SSHProtocolChecker} should raise
        L{NotEnoughAuthentication}.
        """
        checker = checkers.SSHProtocolChecker()
        def _areDone(avatarId):
            return False
        self.patch(checker, 'areDone', _areDone)

        passwordDatabase = InMemoryUsernamePasswordDatabaseDontUse()
        passwordDatabase.addUser(b'test', b'test')
        checker.registerChecker(passwordDatabase)
        d = checker.requestAvatarId(UsernamePassword(b'test', b'test'))
        return self.assertFailure(d, NotEnoughAuthentication)
示例#6
0
 def test_areDone(self):
     """
     The default L{SSHProcotolChecker.areDone} should simply return True.
     """
     self.assertEqual(checkers.SSHProtocolChecker().areDone(None), True)