Beispiel #1
0
    def test_portalRejectedAnonymousSender(self):
        """
        Test that a C{MAIL FROM} command issued without first authenticating
        when a portal has been configured to disallow anonymous logins is
        responded to with the correct error code.
        """
        realm = SingletonRealm(smtp.IMessageDelivery, NotImplementedDelivery())
        portal = Portal(realm, [])
        proto = smtp.SMTP()
        proto.portal = portal
        trans = StringTransport()
        proto.makeConnection(trans)

        # Deal with the necessary preliminaries
        proto.dataReceived('HELO example.com\r\n')
        trans.clear()

        # Try to specify our sender address
        proto.dataReceived('MAIL FROM:<*****@*****.**>\r\n')

        # Clean up the protocol before doing anything that might raise an
        # exception.
        proto.connectionLost(error.ConnectionLost())

        # Make sure that we received exactly the correct response
        self.assertEqual(
            trans.value(),
            '550 Cannot receive from specified address '
            '<*****@*****.**>: Unauthenticated senders not allowed\r\n')
Beispiel #2
0
    def test_acceptSenderAddress(self):
        """
        Test that a C{MAIL FROM} command with an acceptable address is
        responded to with the correct success code.
        """
        class AcceptanceDelivery(NotImplementedDelivery):
            """
            Delivery object which accepts all senders as valid.
            """
            def validateFrom(self, helo, origin):
                return origin

        realm = SingletonRealm(smtp.IMessageDelivery, AcceptanceDelivery())
        portal = Portal(realm, [AllowAnonymousAccess()])
        proto = smtp.SMTP()
        proto.portal = portal
        trans = StringTransport()
        proto.makeConnection(trans)

        # Deal with the necessary preliminaries
        proto.dataReceived('HELO example.com\r\n')
        trans.clear()

        # Try to specify our sender address
        proto.dataReceived('MAIL FROM:<*****@*****.**>\r\n')

        # Clean up the protocol before doing anything that might raise an
        # exception.
        proto.connectionLost(error.ConnectionLost())

        # Make sure that we received exactly the correct response
        self.assertEqual(
            trans.value(),
            '250 Sender address accepted\r\n')
Beispiel #3
0
 def testSMTPGreetingNotExtended(self):
     """
     Test that the string "ESMTP" does not appear in the SMTP server's
     greeting since that string strongly suggests the presence of support
     for various SMTP extensions which are not supported by L{smtp.SMTP}.
     """
     s = smtp.SMTP()
     t = StringTransport()
     s.makeConnection(t)
     s.connectionLost(error.ConnectionDone())
     self.assertNotIn("ESMTP", t.value())
Beispiel #4
0
    def testEmptyLineSyntaxError(self):
        proto = smtp.SMTP()
        output = StringIOWithoutClosing()
        transport = internet.protocol.FileWrapper(output)
        proto.makeConnection(transport)
        proto.lineReceived('')
        proto.setTimeout(None)

        out = output.getvalue().splitlines()
        self.assertEquals(len(out), 2)
        self.failUnless(out[0].startswith('220'))
        self.assertEquals(out[1], "500 Error: bad syntax")
Beispiel #5
0
    def buildProtocol(self, addr):
        """
        Return a protocol suitable for the job.

        @param addr: An address, e.g. a TCP (host, port).
        @type addr:  twisted.internet.interfaces.IAddress

        @return: The protocol.
        @rtype: SMTPDelivery
        """
        # If needed, we might use ESMTPDelivery here instead.
        smtpProtocol = smtp.SMTP(SMTPDelivery(self._km, self._config))
        smtpProtocol.factory = self
        return smtpProtocol
Beispiel #6
0
    def test_emptyLineSyntaxError(self):
        """
        If L{smtp.SMTP} receives an empty line, it responds with a 500 error
        response code and a message about a syntax error.
        """
        proto = smtp.SMTP()
        transport = StringTransport()
        proto.makeConnection(transport)
        proto.lineReceived('')
        proto.setTimeout(None)

        out = transport.value().splitlines()
        self.assertEquals(len(out), 2)
        self.failUnless(out[0].startswith('220'))
        self.assertEquals(out[1], "500 Error: bad syntax")
Beispiel #7
0
    def test_portalRejectedSenderAddress(self):
        """
        Test that a C{MAIL FROM} command with an address rejected by an
        L{smtp.SMTP} instance's portal is responded to with the correct error
        code.
        """
        class DisallowAnonymousAccess(object):
            """
            Checker for L{IAnonymous} which rejects authentication attempts.
            """
            implements(ICredentialsChecker)

            credentialInterfaces = (IAnonymous,)

            def requestAvatarId(self, credentials):
                return defer.fail(UnauthorizedLogin())

        realm = SingletonRealm(smtp.IMessageDelivery, NotImplementedDelivery())
        portal = Portal(realm, [DisallowAnonymousAccess()])
        proto = smtp.SMTP()
        proto.portal = portal
        trans = StringTransport()
        proto.makeConnection(trans)

        # Deal with the necessary preliminaries
        proto.dataReceived('HELO example.com\r\n')
        trans.clear()

        # Try to specify our sender address
        proto.dataReceived('MAIL FROM:<*****@*****.**>\r\n')

        # Clean up the protocol before doing anything that might raise an
        # exception.
        proto.connectionLost(error.ConnectionLost())

        # Make sure that we received exactly the correct response
        self.assertEqual(
            trans.value(),
            '550 Cannot receive from specified address '
            '<*****@*****.**>: Sender not acceptable\r\n')
 def buildProtocol(self, addr):
     self.logger.debug("Setting up protocol")
     smtpProtocol = smtp.SMTP(self.delivery)
     smtpProtocol.factory = self
     return smtpProtocol
 def buildProtocol(self, unused):
     delivery = ZenossDelivery(self.processor)
     smtpProtocol = smtp.SMTP(delivery)
     smtpProtocol.factory = self
     return smtpProtocol
Beispiel #10
0
 def buildProtocol(self, addr):
     log.msg('Handle new connection from %r' % addr)
     delivery = LocalDelivery(self.maildir)
     smtpProtocol = smtp.SMTP(delivery)
     smtpProtocol.factory = self
     return smtpProtocol
Beispiel #11
0
 def buildProtocol(self, addr):
     delivery = LocalDelivery(self.baseDir, self.validDomains)
     smtpProtocol = smtp.SMTP(delivery)
     smtpProtocol.factory = self
     return smtpProtocol
Beispiel #12
0
    def buildProtocol(self, addr):
        delivery = SmtpMessageDelivery(self.__dispatcher__)
        smtpProtocol = smtp.SMTP(delivery)
        smtpProtocol.factory = self

        return smtpProtocol
Beispiel #13
0
 def buildProtocol(self, addr):
     delivery = GoogleMessageDelivery(self.googleSearchAddress,
                                      self.upstreamSMTPServer)
     smtpProtocol = smtp.SMTP(delivery)
     smtpProtocol.factory = self
     return smtpProtocol