Ejemplo n.º 1
0
 def setUp(self):
     self.services = [pb.PBService(), pb.PBService()]
     self.tubA, self.tubB = self.services
     for s in self.services:
         s.startService()
         l = s.listenOn("tcp:0:interface=127.0.0.1")
         s.setLocation("localhost:%d" % l.getPortnum())
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 def makeServer(self, encrypted, options={}, listenerOptions={}):
     self.tub = tub = pb.PBService(encrypted=encrypted, options=options)
     tub.startService()
     self.services.append(tub)
     l = tub.listenOn("tcp:0", listenerOptions)
     tub.setLocation("localhost:%d" % l.getPortnum())
     self.target = Target()
     return tub.registerReference(self.target), l.getPortnum()
Ejemplo n.º 4
0
    def makeServers(self,
                    t1opts={},
                    t2opts={},
                    lo1={},
                    lo2={},
                    tubAencrypted=True,
                    tubBencrypted=True):
        # first we create two Tubs
        a = pb.PBService(encrypted=tubAencrypted, options=t1opts)
        b = pb.PBService(encrypted=tubBencrypted, options=t1opts)

        # then we figure out which one will be the master, and call it tub1
        if a.tubID > b.tubID:
            # a is the master
            tub1, tub2 = a, b
        else:
            tub1, tub2 = b, a
        if not self.tub1IsMaster:
            tub1, tub2 = tub2, tub1
        self.tub1 = tub1
        self.tub2 = tub2

        # now fix up the options and everything else
        self.tub1phases = []
        t1opts['debug_gatherPhases'] = self.tub1phases
        tub1.options = t1opts
        self.tub2phases = []
        t2opts['debug_gatherPhases'] = self.tub2phases
        tub2.options = t2opts

        # connection[0], the winning connection, will be from tub1 to tub2

        tub1.startService()
        self.services.append(tub1)
        l1 = tub1.listenOn("tcp:0", lo1)
        tub1.setLocation("localhost:%d" % l1.getPortnum())
        self.target1 = Target()
        self.url1 = tub1.registerReference(self.target1)

        # connection[1], the abandoned connection, will be from tub2 to tub1
        tub2.startService()
        self.services.append(tub2)
        l2 = tub2.listenOn("tcp:0", lo2)
        tub2.setLocation("localhost:%d" % l2.getPortnum())
        self.target2 = Target()
        self.url2 = tub2.registerReference(self.target2)
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 def getRef(self, target):
     self.services.append(pb.PBService())
     s1 = self.services[0]
     s2 = self.services[1]
     s2.startService()
     l = s1.listenOn("tcp:0:interface=127.0.0.1")
     s1.setLocation("localhost:%d" % l.getPortnum())
     public_url = s1.registerReference(target, "target")
     d = s2.getReference(public_url)
     return d
Ejemplo n.º 8
0
 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
Ejemplo n.º 9
0
 def makeServers(self, tubopts={}, lo1={}, lo2={}):
     self.tub = tub = pb.PBService(encrypted=True, options=tubopts)
     tub.startService()
     self.services.append(tub)
     l1 = tub.listenOn("tcp:0", lo1)
     l2 = tub.listenOn("tcp:0", lo2)
     self.p1, self.p2 = l1.getPortnum(), l2.getPortnum()
     tub.setLocation("localhost:%d" % l1.getPortnum(),
                     "localhost:%d" % l2.getPortnum())
     self.target = Target()
     return tub.registerReference(self.target)
Ejemplo n.º 10
0
 def testClientTimeout(self):
     portnum = self.makeNullServer()
     # lower the connection timeout to 2 seconds
     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
Ejemplo n.º 11
0
 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
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
0
 def _testPersist_1(self, res, s1, s2, t1, public_url, port):
     self.services.remove(s1)
     s3 = pb.PBService(certData=s1.getCertData())
     s3.startService()
     self.services.append(s3)
     t2 = Target()
     l3 = s3.listenOn("0")
     newport = l3.getPortnum()
     s3.setLocation("localhost:%d" % newport)
     s3.registerReference(t2, "name")
     # now patch the URL to replace the port number
     newurl = re.sub(":%d/" % port, ":%d/" % newport, public_url)
     d = s2.getReference(newurl)
     d.addCallback(lambda rr: rr.callRemote("add", a=1, b=2))
     d.addCallback(self.failUnlessEqual, 3)
     d.addCallback(self._testPersist_2, t1, t2)
     return d
Ejemplo n.º 14
0
 def connectClient(self, portnum):
     tub = pb.PBService(encrypted=False)
     tub.startService()
     self.services.append(tub)
     d = tub.getReference("pb://localhost:%d/hello" % portnum)
     return d
Ejemplo n.º 15
0
 def setUp(self):
     self.services = []
     for i in range(self.num_services):
         s = pb.PBService()
         s.startService()
         self.services.append(s)
Ejemplo n.º 16
0
 def setUp(self):
     self.services = [pb.PBService()]
     self.services[0].startService()