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()
def connectedServerAndClient(ServerClass=SimpleSymmetricProtocol, ClientClass=SimpleSymmetricProtocol, *a, **kw): """Returns a 3-tuple: (client, server, pump) """ return iosim.connectedServerAndClient(ServerClass, ClientClass, *a, **kw)
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)
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})
def connectedServerAndClient(ServerClass=SimpleSymmetricProtocol, ClientClass=SimpleSymmetricProtocol, *a, **kw): """Returns a 3-tuple: (client, server, pump) """ return iosim.connectedServerAndClient( ServerClass, ClientClass, *a, **kw)
def _clientAndServer(self, clientTimeout, serverTimeout, initialStorage=None): storage = initialStorage or {} return connectedServerAndClient( lambda: SlowServerProtocol(self.clock, serverTimeout, storage), lambda: redis.RedisProtocol(replyTimeout=clientTimeout))
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)
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)
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)
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))])
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))])