Пример #1
0
 def testDeferredWrapperFail(self):
     from twisted.internet import defer
     from twisted.internet import reactor 
     d = defer.Deferred()
     f = lambda: d.errback(flow.Failure(IOError()))
     reactor.callLater(0, f)
     unittest.deferredError(d).trap(IOError)
Пример #2
0
 def testCallbackFailure(self):
     cb = flow.Callback()
     d = flow.Deferred(buildlist(cb))
     for x in range(3):
         cb.result(x)
     cb.errback(flow.Failure(IOError()))
     unittest.deferredError(d).trap(IOError)
Пример #3
0
 def testGoodFailedConnect(self):
     factory = pb.PBClientFactory()
     d = factory.getPerspective("guest", "guest", "test", perspectiveName="any")
     reactor.connectTCP("127.0.0.1", 69, factory)
     f = unittest.deferredError(d)
     from twisted.internet import error
     f.trap(error.ConnectError)
Пример #4
0
 def testBadUsername(self):
     db = checkers.PluggableAuthenticationModulesChecker()
     conv = self._makeConv({1:'password', 2:'entry', 3:''})
     creds = credentials.PluggableAuthenticationModules('baduser',
             conv)
     d = db.requestAvatarId(creds)
     f = unittest.deferredError(d)
     f.trap(error.UnauthorizedLogin)
Пример #5
0
 def testBadLogin(self):
     factory = pb.PBClientFactory()
     for username, password in [("nosuchuser", "pass"), ("user", "wrongpass")]:
         d = factory.login(credentials.UsernamePassword(username, password), "BRAINS!")
         c = reactor.connectTCP("127.0.0.1", self.portno, factory)
         p = unittest.deferredError(d)
         self.failUnless(p.check("twisted.cred.error.UnauthorizedLogin"))
         c.disconnect()
         reactor.iterate()
         reactor.iterate()
         reactor.iterate()
     from twisted.cred.error import UnauthorizedLogin
     log.flushErrors(UnauthorizedLogin)
Пример #6
0
    def testFailAndStop(self):
        def foo(x):
            lc.stop()
            raise TestException(x)

        lc = task.LoopingCall(foo, "bar")
        d = lc.start(0.1)
        err = unittest.deferredError(d)
        err.trap(TestException)

        # catch any possibly lingering issues
        reactor.iterate()
        reactor.iterate()
        reactor.iterate()
Пример #7
0
    def testHashedPasswords(self):
        def hash(u, p, s):
            return crypt(p, s)

        dbfile = self.mktemp()
        db = checkers.FilePasswordDB(dbfile, hash=hash)
        f = file(dbfile, 'w')
        for (u, p) in self.users:
            f.write('%s:%s\n' % (u, crypt(p, u[:2])))
        f.close()

        r = TestRealm()
        port = portal.Portal(r)
        port.registerChecker(db)

        for (u, p) in self.users:
            c = credentials.UsernamePassword(u, p)

            d = defer.maybeDeferred(db.requestAvatarId, c)
            self.assertEquals(unittest.deferredResult(d), u)

            d = port.login(c, None, ITestable)
            i, a, l = unittest.deferredResult(d)
            self.assertEquals(a.original.name, u)

            # It should fail if we pass the wrong password
            c = credentials.UsernamePassword(u, 'wrong password')
            d = port.login(c, None, ITestable)
            f = unittest.deferredError(d)
            f.trap(error.UnauthorizedLogin)

            # And it should fail for UsernameHashedPassword
            c = credentials.UsernameHashedPassword(u, crypt(p, u[:2]))
            d = port.login(c, None, ITestable)
            f = unittest.deferredError(d)
            f.trap(error.UnhandledCredentials)
Пример #8
0
 def testZipFailure(self):
     lhs = [(1,'a'),(2,'b'),(3,'c')]
     mrg = flow.Zip([1,2,flow.Cooperate(),3],badgen())
     d = flow.Deferred(mrg)
     unittest.deferredError(d).trap(ZeroDivisionError)
Пример #9
0
 def testDeferredFailure(self):
     d = flow.Deferred(badgen())
     unittest.deferredError(d).trap(ZeroDivisionError)
Пример #10
0
 def testNoContactLookup(self):
     self.register()
     url = sip.URL(username="******", host="bell.example.com")
     f = unittest.deferredError(self.proxy.locator.getAddress(url))
     f.trap(LookupError)
Пример #11
0
 def testWrongDomainLookup(self):
     self.register()
     url = sip.URL(username="******", host="foo.com")
     f = unittest.deferredError(self.proxy.locator.getAddress(url))
     f.trap(LookupError)