def testUnencrypted(self): url, portnum = self.makeServer(False) client = pb.PBService(encrypted=False) client.startService() self.services.append(client) d = client.getReference(url) return d
def testUnauthenticated(self): url, portnum = self.makeServer(False) client = UnauthenticatedTub() client.startService() self.services.append(client) d = client.getReference(url) return d
def testHalfAuthenticated2(self): if not crypto_available: raise unittest.SkipTest("crypto not available") url, portnum = self.makeServer(False) client = Tub() client.startService() self.services.append(client) d = client.getReference(url) return d
def testHalfEncrypted2(self): if not crypto: raise unittest.SkipTest("crypto not available") url, portnum = self.makeServer(False) client = pb.PBService(encrypted=True) client.startService() self.services.append(client) d = client.getReference(url) return d
def _testNoConnection_1(self, res, url): self.services.remove(self.tub) client = pb.PBService(encrypted=False) client.startService() self.services.append(client) d = client.getReference(url) d.addCallbacks(lambda res: self.fail("this is supposed to fail"), self._testNoConnection_fail) return d
def _testNoConnection_1(self, res, url): self.services.remove(self.tub) client = UnauthenticatedTub() client.startService() self.services.append(client) d = client.getReference(url) d.addCallbacks(lambda res: self.fail("this is supposed to fail"), self._testNoConnection_fail) return d
def testClientTimeout(self): portnum = self.makeNullServer() client = pb.PBService(encrypted=False, options={'connect_timeout': 1}) client.startService() self.services.append(client) url = "pbu://localhost:%d/target" % portnum d = client.getReference(url) d.addCallbacks(lambda res: self.fail("hey! this is supposed to fail"), lambda f: f.trap(tokens.NegotiationError)) return d
def connect(self, url, encrypted=True): self.clientPhases = [] opts = {"debug_stall_second_connection": True, "debug_gatherPhases": self.clientPhases} self.client = client = pb.PBService(encrypted=encrypted, options=opts) client.startService() self.services.append(client) d = client.getReference(url) return d
def connect(self, url, encrypted=True): self.clientPhases = [] opts = { "debug_stall_second_connection": True, "debug_gatherPhases": self.clientPhases } self.client = client = pb.PBService(encrypted=encrypted, options=opts) client.startService() self.services.append(client) d = client.getReference(url) return d
def testVersusHTTPServerUnencrypted(self): portnum = self.makeHTTPServer() client = pb.PBService(encrypted=False) client.startService() self.services.append(client) url = "pbu://localhost:%d/target" % portnum d = client.getReference(url) d.addCallbacks(lambda res: self.fail("this is supposed to fail"), lambda f: f.trap(pb.BananaError)) d.addCallback(self.stall, 1) # same reason as above return d
def testClientTimeout(self): portnum = self.makeNullServer() # lower the connection timeout to 2 seconds client = UnauthenticatedTub(options={'connect_timeout': 1}) client.startService() self.services.append(client) url = "pbu://127.0.0.1:%d/target" % portnum d = client.getReference(url) d.addCallbacks(lambda res: self.fail("hey! this is supposed to fail"), lambda f: f.trap(tokens.NegotiationError)) return d
def testVersusHTTPServerUnauthenticated(self): portnum = self.makeHTTPServer() client = UnauthenticatedTub() client.startService() self.services.append(client) url = "pbu://127.0.0.1:%d/target" % portnum d = client.getReference(url) d.addCallbacks(lambda res: self.fail("this is supposed to fail"), lambda f: f.trap(BananaError)) d.addCallback(self.stall, 1) # same reason as above return d
def connect(self, url, authenticated=True): self.clientPhases = [] opts = {"debug_stall_second_connection": True, "debug_gatherPhases": self.clientPhases} if authenticated: self.client = client = Tub(options=opts) else: self.client = client = UnauthenticatedTub(options=opts) client.startService() self.services.append(client) d = client.getReference(url) return d
def testVersusHTTPServerEncrypted(self): if not crypto: raise unittest.SkipTest("crypto not available") portnum = self.makeHTTPServer() client = pb.PBService(encrypted=True) client.startService() self.services.append(client) url = "pb://1234@localhost:%d/target" % portnum d = client.getReference(url) d.addCallbacks(lambda res: self.fail("this is supposed to fail"), lambda f: f.trap(pb.BananaError)) d.addCallback(self.stall, 1) return d
def testFuture3(self): # same as testFuture1, but it is the listening server that # understands [1,2] self.requireCrypto() url, portnum = self.makeSpecificServer(certData_high, NegotiationVbig) client = Tub(certData=certData_low) client.startService() self.services.append(client) d = client.getReference(url) def _check_version(rref): ver = rref.tracker.broker._banana_decision_version self.failUnlessEqual(ver, MAX_HANDLED_VERSION) d.addCallback(_check_version) return d
def connect(self, url, authenticated=True): self.clientPhases = [] opts = { "debug_stall_second_connection": True, "debug_gatherPhases": self.clientPhases } if authenticated: self.client = client = Tub(options=opts) else: self.client = client = UnauthenticatedTub(options=opts) client.startService() self.services.append(client) d = client.getReference(url) return d
def testVersusHTTPServerAuthenticated(self): if not crypto_available: raise unittest.SkipTest("crypto not available") portnum = self.makeHTTPServer() client = Tub() client.startService() self.services.append(client) url = "pb://%[email protected]:%d/target" % (tubid_low, portnum) d = client.getReference(url) d.addCallbacks(lambda res: self.fail("this is supposed to fail"), lambda f: f.trap(BananaError)) # the HTTP server needs a moment to notice that the connection has # gone away. Without this, trial flunks the test because of the # leftover HTTP server socket. d.addCallback(self.stall, 1) return d
def testVersusHTTPServerEncrypted(self): if not crypto: raise unittest.SkipTest("crypto not available") portnum = self.makeHTTPServer() client = pb.PBService(encrypted=True) client.startService() self.services.append(client) url = "pb://1234@localhost:%d/target" % portnum d = client.getReference(url) d.addCallbacks(lambda res: self.fail("this is supposed to fail"), lambda f: f.trap(pb.BananaError)) # the HTTP server needs a moment to notice that the connection has # gone away. Without this, trial flunks the test because of the # leftover HTTP server socket. d.addCallback(self.stall, 1) return d
def testFuture2(self): # same as before, but the connecting Tub will have the higher tubID, # and thus make the negotiation decision self.requireCrypto() url, portnum = self.makeSpecificServer(certData_low) # the client client = Tub(certData=certData_high) client.negotiationClass = NegotiationVbig client.startService() self.services.append(client) d = client.getReference(url) def _check_version(rref): ver = rref.tracker.broker._banana_decision_version self.failUnlessEqual(ver, MAX_HANDLED_VERSION) d.addCallback(_check_version) return d
def testTooFarInFuture2(self): # same as before, but the connecting Tub will have the higher tubID, # and thus make the negotiation decision self.requireCrypto() url, portnum = self.makeSpecificServer(certData_low) client = Tub(certData=certData_high) client.negotiationClass = NegotiationVbigOnly client.startService() self.services.append(client) d = client.getReference(url) def _oops_succeeded(rref): self.fail("hey! this is supposed to fail") def _check_failure(f): f.trap(tokens.NegotiationError, tokens.RemoteNegotiationError) d.addCallbacks(_oops_succeeded, _check_failure) return d
def testTooFarInFuture4(self): # same as testTooFarInFuture2, but it is the listening server which # only understands [2] self.requireCrypto() url, portnum = self.makeSpecificServer(certData_low, NegotiationVbigOnly) client = Tub(certData=certData_high) client.startService() self.services.append(client) d = client.getReference(url) def _oops_succeeded(rref): self.fail("hey! this is supposed to fail") def _check_failure(f): f.trap(tokens.NegotiationError, tokens.RemoteNegotiationError) d.addCallbacks(_oops_succeeded, _check_failure) return d
def testFuture1(self): # when a peer that understands version=[1] that connects to a peer # that understands version=[1,2], they should pick version=1 # the listening Tub will have the higher tubID, and thus make the # negotiation decision self.requireCrypto() url, portnum = self.makeSpecificServer(certData_high) # the client client = Tub(certData=certData_low) client.negotiationClass = NegotiationVbig client.startService() self.services.append(client) d = client.getReference(url) def _check_version(rref): ver = rref.tracker.broker._banana_decision_version self.failUnlessEqual(ver, MAX_HANDLED_VERSION) d.addCallback(_check_version) return d
def testTooFarInFuture1(self): # when a peer that understands version=[1] that connects to a peer # that only understands version=[2], they should fail to negotiate # the listening Tub will have the higher tubID, and thus make the # negotiation decision self.requireCrypto() url, portnum = self.makeSpecificServer(certData_high) # the client client = Tub(certData=certData_low) client.negotiationClass = NegotiationVbigOnly client.startService() self.services.append(client) d = client.getReference(url) def _oops_succeeded(rref): self.fail("hey! this is supposed to fail") def _check_failure(f): f.trap(tokens.NegotiationError, tokens.RemoteNegotiationError) d.addCallbacks(_oops_succeeded, _check_failure) return d