Пример #1
0
 def testEmptyPASS(self):
     dummy = DummyPOP3()
     client = LineSendingProtocol(["PASS ", "QUIT"])
     expected_output = '+OK <moshez>\r\n-ERR USER required before PASS\r\n+OK \r\n'
     loopback.loopback(dummy, client)
     self.failUnlessEqual(expected_output,
                          '\r\n'.join(client.response) + '\r\n')
     dummy.connectionLost(
         failure.Failure(Exception("Test harness disconnect")))
Пример #2
0
    def testAuthListing(self):
        p = DummyPOP3()
        p.factory = internet.protocol.Factory()
        p.factory.challengers = {'Auth1': None, 'secondAuth': None, 'authLast': None}
        client = LineSendingProtocol([
            "AUTH",
            "QUIT",
        ])

        d = loopback.loopbackAsync(p, client)
        return d.addCallback(self._cbTestAuthListing, client)
Пример #3
0
 def testMessages(self):
     client = LineSendingProtocol([
         'APOP [email protected] world',
         'UIDL',
         'RETR 1',
         'QUIT',
     ])
     server =  MyVirtualPOP3()
     server.service = self.factory
     def check(ignored):
         output = '\r\n'.join(client.response) + '\r\n'
         self.assertEqual(output, self.expectedOutput)
     return loopback.loopbackTCP(server, client).addCallback(check)
Пример #4
0
 def runTest(self, lines):
     dummy = DummyPOP3()
     client = LineSendingProtocol([
         "APOP moshez dummy",
         "LIST",
         "UIDL",
         "RETR 1",
         "RETR 2",
         "DELE 1",
         "RETR 1",
         "QUIT",
     ])
     d = loopback.loopbackAsync(dummy, client)
     return d.addCallback(self._cbRunTest, client, dummy)
Пример #5
0
    def test_authListing(self):
        """
        L{pop3.POP3} responds to an I{AUTH} command with a list of supported
        authentication types based on its factory's C{challengers}.
        """
        p = DummyPOP3()
        p.factory = internet.protocol.Factory()
        p.factory.challengers = {b"Auth1": None, b"secondAuth": None, b"authLast": None}
        client = LineSendingProtocol(
            [
                b"AUTH",
                b"QUIT",
            ]
        )

        d = loopback.loopbackAsync(p, client)
        return d.addCallback(self._cbTestAuthListing, client)
Пример #6
0
    def testAuthListing(self):
        p = DummyPOP3()
        p.factory = internet.protocol.Factory()
        p.factory.challengers = {
            'Auth1': None,
            'secondAuth': None,
            'authLast': None
        }
        client = LineSendingProtocol([
            "AUTH",
            "QUIT",
        ])

        loopback.loopback(p, client)
        self.failUnless(client.response[1].startswith('+OK'))
        self.assertEquals(client.response[2:6],
                          ["AUTH1", "SECONDAUTH", "AUTHLAST", "."])
Пример #7
0
    def test_messages(self):
        """
        Messages can be downloaded over a loopback TCP connection.
        """
        client = LineSendingProtocol([
            b"APOP [email protected] world",
            b"UIDL",
            b"RETR 1",
            b"QUIT",
        ])
        server = MyVirtualPOP3()
        server.service = self.factory

        def check(ignored):
            output = b"\r\n".join(client.response) + b"\r\n"
            self.assertEqual(output, self.expectedOutput)

        return loopback.loopbackTCP(server, client).addCallback(check)
Пример #8
0
    def runTest(self, lines, expectedOutput):
        """
        Assert that when C{lines} are delivered to L{pop3.POP3} it responds
        with C{expectedOutput}.

        @param lines: A sequence of L{bytes} representing lines to deliver to
            the server.

        @param expectedOutput: A sequence of L{bytes} representing the
            expected response from the server.

        @return: A L{Deferred} that fires when the lines have been delivered
            and the output checked.
        """
        dummy = DummyPOP3()
        client = LineSendingProtocol(lines)
        d = loopback.loopbackAsync(dummy, client)
        return d.addCallback(self._cbRunTest, client, dummy, expectedOutput)
Пример #9
0
 def runTest(self, lines, expected):
     dummy = DummyPOP3()
     client = LineSendingProtocol([
         "APOP moshez dummy",
         "LIST",
         "UIDL",
         "RETR 1",
         "RETR 2",
         "DELE 1",
         "RETR 1",
         "QUIT",
     ])
     expected_output = '+OK <moshez>\r\n+OK Authentication succeeded\r\n+OK 1\r\n1 44\r\n.\r\n+OK \r\n1 0\r\n.\r\n+OK 44\r\nFrom: moshe\r\nTo: moshe\r\n\r\nHow are you, friend?\r\n.\r\n-ERR Bad message number argument\r\n+OK \r\n-ERR message deleted\r\n+OK \r\n'
     loopback.loopback(dummy, client)
     self.failUnlessEqual(expected_output,
                          '\r\n'.join(client.response) + '\r\n')
     dummy.connectionLost(
         failure.Failure(Exception("Test harness disconnect")))
Пример #10
0
    def test_filtering(self):
        """
        Check that L{TurtleProxyRequest.process} filters urls that
        it doesn't know.
        """
        class FakeThrottler(object):
            called_run = False
            called_run_asap = False
            def run(self, fun, *args, **kwargs):
                self.called_run = True
                return defer.maybeDeferred(fun, *args, **kwargs)

            def runasap(self, fun, *args, **kwargs):
                self.called_run_asap = True
                return defer.maybeDeferred(fun, *args, **kwargs)


        transport = StringTransportWithDisconnection()
        transport.protocol = LineSendingProtocol([], False)
        channel = DummyChannel(transport)
        reactor = FakeReactor()

        throttler = FakeThrottler()
        urlmap = {'delicious.com': throttler}
        proxy_factory = proxy.TurtleHTTPFactory(urlmap, True, reactor)
        channel.factory = proxy_factory

        request = proxy.TurtleProxyRequest(channel, False, reactor)
        request.gotLength(0)
        request.requestReceived('GET', 'http://example.com:1234/foo/bar',
                                'HTTP/1.0')

        # That should create one connection, with the port parsed from the URL
        self.assertEquals(len(reactor.connect), 0)


        request = proxy.TurtleProxyRequest(channel, False, reactor)
        request.gotLength(0)
        request.requestReceived('GET', 'http://delicious.com:1234/foo/bar',
                                'HTTP/1.0')

        # That should create one connection, with the port parsed from the URL
        self.assertEquals(len(reactor.connect), 1)
        self.assertEquals(reactor.connect[-1][0], "delicious.com")
        self.assertEquals(reactor.connect[-1][1], 1234)
        self.assertEquals(throttler.called_run, True)
        self.assertEquals(throttler.called_run_asap, False)




        request = proxy.TurtleProxyRequest(channel, False, reactor)
        request.gotLength(0)
        request.requestHeaders.addRawHeader('x-priority', 'interactive')
        request.requestReceived('GET', 'http://delicious.com:1234/foo/bar',
                                'HTTP/1.0')

        # That should create one connection, with the port parsed from the URL
        self.assertEquals(len(reactor.connect), 2)
        self.assertEquals(reactor.connect[-1][0], "delicious.com")
        self.assertEquals(reactor.connect[-1][1], 1234)
        self.assertEquals(throttler.called_run_asap, True)
Пример #11
0
 def testEmptyPASS(self):
     dummy = DummyPOP3()
     client = LineSendingProtocol(["PASS ", "QUIT"])
     d = loopback.loopbackAsync(dummy, client)
     return d.addCallback(self._cbTestEmptyPASS, client, dummy)
Пример #12
0
 def runTest(self, lines, expectedOutput):
     dummy = DummyPOP3()
     client = LineSendingProtocol(lines)
     d = loopback.loopbackAsync(dummy, client)
     return d.addCallback(self._cbRunTest, client, dummy, expectedOutput)
Пример #13
0
 def test_IllegalPASS(self):
     dummy = DummyPOP3()
     client = LineSendingProtocol([b"PASS fooz", b"QUIT"])
     d = loopback.loopbackAsync(dummy, client)
     return d.addCallback(self._cbTestIllegalPASS, client, dummy)