コード例 #1
0
 def setUp(self):
     AgentTestBase.setUp(self)
     self.client, self.server, self.pump = iosim.connectedServerAndClient(
         CorruptServer, agent.SSHAgentClient)
     # the server's end of the protocol is stateful and we store it on the
     # factory, for which we only need a mock
     self.server.factory = StubFactory()
コード例 #2
0
ファイル: test_amp.py プロジェクト: adde88/python2.7_mana
def connectedServerAndClient(ServerClass=SimpleSymmetricProtocol,
                             ClientClass=SimpleSymmetricProtocol,
                             *a,
                             **kw):
    """Returns a 3-tuple: (client, server, pump)
    """
    return iosim.connectedServerAndClient(ServerClass, ClientClass, *a, **kw)
コード例 #3
0
 def setUp(self):
     AgentTestBase.setUp(self)
     self.client, self.server, self.pump = iosim.connectedServerAndClient(
         CorruptServer, agent.SSHAgentClient)
     # the server's end of the protocol is stateful and we store it on the
     # factory, for which we only need a mock
     self.server.factory = StubFactory()
コード例 #4
0
ファイル: helpers.py プロジェクト: derwolfe/vertex
    def connectQ2Q(self, fromAddress, toAddress,
                   protocolName, protocolFactory,
                   chooser=lambda x: x and [x[0]]):
        # XXX update this when q2q is updated to return a connector rather than
        # a Deferred.

        # XXX this isn't really dealing with the multiple-connectors use case
        # now.  sigma doesn't need this functionality, but we will need to
        # update this class to do it properly before using it to test other Q2Q
        # code.

        listener, description = self.listeners.get((toAddress, protocolName))
        if listener is None:
            print 'void listener', fromAddress, toAddress, self.listeners, self.listener
            reason = Failure(KeyError())
            protocolFactory.clientConnectionFailed(None, reason)
            return defer.fail(reason)
        else:
            def makeFakeClient(c):
                ft = FakeQ2QTransport(c, False, fromAddress, toAddress)
                return ft

            def makeFakeServer(s):
                ft = FakeQ2QTransport(s, True, toAddress, fromAddress)
                return ft

            client, server, pump = connectedServerAndClient(
                lambda: listener.buildProtocol(fromAddress),
                lambda: protocolFactory.buildProtocol(toAddress),
                makeFakeClient,
                makeFakeServer)
            self.pumps.append(pump)

            return defer.succeed(client)
コード例 #5
0
ファイル: helpers.py プロジェクト: zhp1254/vertex
    def connectQ2Q(self, fromAddress, toAddress,
                   protocolName, protocolFactory,
                   chooser=lambda x: x and [x[0]]):
        # XXX update this when q2q is updated to return a connector rather than
        # a Deferred.

        # XXX this isn't really dealing with the multiple-connectors use case
        # now.  sigma doesn't need this functionality, but we will need to
        # update this class to do it properly before using it to test other Q2Q
        # code.

        listener, description = self.listeners.get((toAddress, protocolName))
        if listener is None:
            print 'void listener', fromAddress, toAddress, self.listeners, self.listener
            reason = Failure(KeyError())
            protocolFactory.clientConnectionFailed(None, reason)
            return defer.fail(reason)
        else:
            def makeFakeClient(c):
                ft = FakeQ2QTransport(c, False, fromAddress, toAddress)
                return ft

            def makeFakeServer(s):
                ft = FakeQ2QTransport(s, True, toAddress, fromAddress)
                return ft

            client, server, pump = connectedServerAndClient(
                lambda: listener.buildProtocol(fromAddress),
                lambda: protocolFactory.buildProtocol(toAddress),
                makeFakeClient,
                makeFakeServer)
            self.pumps.append(pump)

            return defer.succeed(client)
コード例 #6
0
ファイル: test_identity.py プロジェクト: washort/vertex
    def test_handshake(self):
        """
        Verify that starting TLS and succeeding at handshaking sends all the
        notifications to all the right places.
        """
        cli, svr, p = connectedServerAndClient(
            ServerClass=SecurableProto,
            ClientClass=SecurableProto)

        okc = OKCert()
        svr.certFactory = lambda : okc

        cli.callRemote(
            amp.StartTLS, tls_localCertificate=okc,
            tls_verifyAuthorities=[PretendRemoteCertificateAuthority()])

        # let's buffer something to be delivered securely
        L = []
        cli.callRemote(SecuredPing).addCallback(L.append)
        p.flush()
        # once for client once for server
        self.assertEqual(okc.verifyCount, 2)
        L = []
        cli.callRemote(SecuredPing).addCallback(L.append)
        p.flush()
        self.assertEqual(L[0], {'pinged': True})
コード例 #7
0
def connectedServerAndClient(ServerClass=SimpleSymmetricProtocol,
                             ClientClass=SimpleSymmetricProtocol,
                             *a, **kw):
    """Returns a 3-tuple: (client, server, pump)
    """
    return iosim.connectedServerAndClient(
        ServerClass, ClientClass,
        *a, **kw)
コード例 #8
0
 def _clientAndServer(self,
                      clientTimeout,
                      serverTimeout,
                      initialStorage=None):
     storage = initialStorage or {}
     return connectedServerAndClient(
         lambda: SlowServerProtocol(self.clock, serverTimeout, storage),
         lambda: redis.RedisProtocol(replyTimeout=clientTimeout))
コード例 #9
0
    def setUp(self):
        # wire up our client <-> server
        self.client, self.server, self.pump = iosim.connectedServerAndClient(agent.SSHAgentServer, agent.SSHAgentClient)

        # the server's end of the protocol is stateful and we store it on the
        # factory, for which we only need a mock
        self.server.factory = StubFactory()

        # pub/priv keys of each kind
        self.rsaPrivate = keys.Key.fromString(keydata.privateRSA_openssh)
        self.dsaPrivate = keys.Key.fromString(keydata.privateDSA_openssh)

        self.rsaPublic = keys.Key.fromString(keydata.publicRSA_openssh)
        self.dsaPublic = keys.Key.fromString(keydata.publicDSA_openssh)
コード例 #10
0
ファイル: test_protocol.py プロジェクト: stmcginnis/flocker
 def test_periodic_noops(self):
     """
     When connected, the protocol sends ``NoOp`` commands at a fixed
     interval.
     """
     expected_pings = 3
     reactor = Clock()
     locator = _NoOpCounter()
     peer = AMP(locator=locator)
     protocol = self.build_protocol(reactor)
     pump = connectedServerAndClient(lambda: protocol, lambda: peer)[2]
     for i in range(expected_pings):
         reactor.advance(PING_INTERVAL.total_seconds())
         pump.flush()
     self.assertEqual(locator.noops, expected_pings)
コード例 #11
0
    def setUp(self):
        # wire up our client <-> server
        self.client, self.server, self.pump = iosim.connectedServerAndClient(
            agent.SSHAgentServer, agent.SSHAgentClient)

        # the server's end of the protocol is stateful and we store it on the
        # factory, for which we only need a mock
        self.server.factory = StubFactory()

        # pub/priv keys of each kind
        self.rsaPrivate = keys.Key.fromString(keydata.privateRSA_openssh)
        self.dsaPrivate = keys.Key.fromString(keydata.privateDSA_openssh)

        self.rsaPublic = keys.Key.fromString(keydata.publicRSA_openssh)
        self.dsaPublic = keys.Key.fromString(keydata.publicDSA_openssh)
コード例 #12
0
 def test_periodic_noops(self):
     """
     When connected, the protocol sends ``NoOp`` commands at a fixed
     interval.
     """
     expected_pings = 3
     reactor = Clock()
     locator = _NoOpCounter()
     peer = AMP(locator=locator)
     protocol = self.build_protocol(reactor)
     pump = connectedServerAndClient(lambda: protocol, lambda: peer)[2]
     for i in range(expected_pings):
         reactor.advance(PING_INTERVAL.total_seconds())
         pump.flush()
     self.assertEqual(locator.noops, expected_pings)
コード例 #13
0
    def test_basicProtocol(self):
        """
        This is an integration test which combines Twisted's pop3 client and server
        byte-level protocol logic and the server to verify that the protocol
        exposed to the client lists the same UIDs that the server
        implementation expects to export.
        """
        from twisted.internet.base import DelayedCall
        DelayedCall.debug = True
        c, s, p = connectedServerAndClient(
            ServerClass=lambda: POP3ServerFactory(self.portal).buildProtocol(
                None),
            ClientClass=POP3Client)
        s.callLater = lambda f, *a, **k: None  # squelch timeouts
        r = self.mailbox._realize()
        L = []

        def doItSynchronously(iterator):
            inner = Deferred()
            ir = list(iterator)
            L.append((inner, ir))
            return inner

        def flushSync():
            for (inner, results) in L:
                inner.callback(results)

        s.schedule = doItSynchronously
        r.coiterate = doItSynchronously
        p.flush()
        d1 = c.login("*****@*****.**", "asdfjkl;")
        p.flush()
        d = c.listUID()
        p.flush()
        flushSync()
        p.flush()
        self.assertEquals(len(d.result), len(self.messageTexts))
        self.assertEquals(
            d.result, [r.getUidl(n) for n in range(len(self.messageTexts))])
コード例 #14
0
ファイル: test_popout.py プロジェクト: pombredanne/quotient
 def test_basicProtocol(self):
     """
     This is an integration test which combines Twisted's pop3 client and server
     byte-level protocol logic and the server to verify that the protocol
     exposed to the client lists the same UIDs that the server
     implementation expects to export.
     """
     from twisted.internet.base import DelayedCall
     DelayedCall.debug = True
     c, s, p = connectedServerAndClient(
         ServerClass=lambda :
         POP3ServerFactory(self.portal).buildProtocol(None),
         ClientClass=POP3Client)
     s.callLater = lambda f, *a, **k: None # squelch timeouts
     r = self.mailbox._realize()
     L = []
     def doItSynchronously(iterator):
         inner = Deferred()
         ir = list(iterator)
         L.append((inner, ir))
         return inner
     def flushSync():
         for (inner, results) in L:
             inner.callback(results)
     s.schedule = doItSynchronously
     r.coiterate = doItSynchronously
     p.flush()
     d1 = c.login("*****@*****.**", "asdfjkl;")
     p.flush()
     d = c.listUID()
     p.flush()
     flushSync()
     p.flush()
     self.assertEquals(len(d.result), len(self.messageTexts))
     self.assertEquals(d.result,
                       [r.getUidl(n)
                        for n in range(len(self.messageTexts))])