Exemplo n.º 1
0
 def __init__(self, host='', port=0, methods={c.AUTH_ANONYMOUS: ()}):
     self.host = host
     self.port = port
     self.methods = methods
     self.reason = None
     self.accum = proto_helpers.AccumulatingProtocol()
     self.expectingReason = False
Exemplo n.º 2
0
 def makeProto(self):
     wrappedProto = proto_helpers.AccumulatingProtocol()
     proto = I2PServerTunnelProtocol(wrappedProto, None)
     transport = proto_helpers.StringTransport()
     transport.abortConnection = lambda: None
     proto.makeConnection(transport)
     return proto
Exemplo n.º 3
0
 def __init__(self, host='', port=0, user=''):
     self.host = host
     self.port = port
     self.user = user
     self.reason = None
     self.accum = proto_helpers.AccumulatingProtocol()
     self.expectingReason = False
Exemplo n.º 4
0
 def test_getSession_newNickname_withoutEndpoint(self):
     proto = proto_helpers.AccumulatingProtocol()
     samEndpoint = FakeEndpoint()
     samEndpoint.deferred = defer.succeed(None)
     samEndpoint.facDeferred = defer.succeed(
         ('3.1', 'STREAM', 'nick', proto, TEST_B64, None))
     self.assertRaises(ValueError, session.getSession, 'nick')
Exemplo n.º 5
0
 def makeProto(self):
     wrappedProto = proto_helpers.AccumulatingProtocol()
     proto = I2PClientTunnelProtocol(wrappedProto, None, TEST_B64)
     proto.factory = FakeDisconnectingFactory()
     transport = proto_helpers.StringTransportWithDisconnection()
     transport.abortConnection = lambda: None
     transport.protocol = proto
     proto.makeConnection(transport)
     return proto
Exemplo n.º 6
0
 def test_testAPI(self):
     proto = proto_helpers.AccumulatingProtocol()
     samEndpoint = FakeEndpoint()
     samEndpoint.deferred = defer.succeed(None)
     samEndpoint.facDeferred = defer.succeed(True)
     d = session.testAPI(samEndpoint)
     s = self.successResultOf(d)
     self.assertEqual(1, samEndpoint.called)
     self.assertEqual(True, s)
Exemplo n.º 7
0
 def test_generateDestination(self):
     proto = proto_helpers.AccumulatingProtocol()
     samEndpoint = FakeEndpoint()
     samEndpoint.deferred = defer.succeed(None)
     samEndpoint.facDeferred = defer.succeed(I2PAddress(TEST_B64))
     d = session.generateDestination('', samEndpoint)
     s = self.successResultOf(d)
     self.assertEqual(1, samEndpoint.called)
     self.assertEqual(I2PAddress(TEST_B64), s)
Exemplo n.º 8
0
 def test_getSession_existingNickname_withoutEndpoint(self):
     proto = proto_helpers.AccumulatingProtocol()
     samEndpoint = FakeEndpoint()
     samEndpoint.deferred = defer.succeed(None)
     samEndpoint.facDeferred = defer.succeed(
         ('3.1', 'STREAM', 'nick', proto, TEST_B64, None))
     d = session.getSession('nick', samEndpoint)
     s = self.successResultOf(d)
     d2 = session.getSession('nick')
     s2 = self.successResultOf(d2)
     self.assertEqual(1, samEndpoint.called)
     self.assertEqual(s, s2)
Exemplo n.º 9
0
 def test_peerDataWrapped_allAtOnce(self):
     fac, proto = self.makeProto()
     fac.streamAcceptIncoming = Mock()
     fac.session = Mock()
     fac.session.id = 'foo'
     fac.forwardPort = 1337
     proto.receiver.wrappedProto = proto_helpers.AccumulatingProtocol()
     # Shortcut to end of SAM stream accept protocol
     proto.receiver.currentRule = 'State_readData'
     proto._parser._setupInterp()
     proto.dataReceived('%s FROM_PORT=34444 TO_PORT=0\nEgg and spam' %
                        TEST_B64)
     self.assertEquals('Egg and spam', proto.receiver.wrappedProto.data)
Exemplo n.º 10
0
 def test_getSession_newNickname_withPort(self):
     proto = proto_helpers.AccumulatingProtocol()
     samEndpoint = FakeEndpoint()
     samEndpoint.deferred = defer.succeed(None)
     samEndpoint.facDeferred = defer.succeed(
         ('3.2', 'STREAM', 'nick', proto, TEST_B64, 81))
     d = session.getSession('nick', samEndpoint)
     s = self.successResultOf(d)
     self.assertEqual(1, samEndpoint.called)
     self.assertEqual('nick', s.nickname)
     self.assertEqual('nick', s.id)
     self.assertEqual(proto, s._proto)
     self.assertEqual(TEST_B64, s.address.destination)
     self.assertEqual(81, s.address.port)
Exemplo n.º 11
0
    def _createProtocolWithHost(self, host):
        """Mock a Protocol which has a ``host`` attribute.

        We don't currently use any of the ``IProtocol`` methods of the
        returned ``twisted.test.proto_helpers.AccumulatingProtocol``, and so
        this could be any class, although a mocked ``IProtocol`` implementer
        was chosen for completeness and realism's sakes.

        :param str host: A domain name or IP address.
        :rtype: :api:`twisted.test.proto_helpers.AccumulatingProtocol`
        :returns: A Protocol instance which has its ``host`` attribute set to
            the given **host**, so that an :api:`twisted.mail.smtp.User` can
            be constructed with it.
        """
        self.proto = proto_helpers.AccumulatingProtocol()
        self.proto.host = host
Exemplo n.º 12
0
 def cbCollectBody(response):
     protocol = proto_helpers.AccumulatingProtocol()
     response.deliverBody(protocol)
     d = protocol.closedDeferred = defer.Deferred()
     d.addCallback(lambda _: (protocol, response))
     return d