def test_invalid_signature(self):
        """Invalid signature should not be handled as an OOPs.

        It should produce a message explaining to the user what went wrong.
        """
        person = self.factory.makePerson()
        transaction.commit()
        email_address = person.preferredemail.email
        invalid_body = ('-----BEGIN PGP SIGNED MESSAGE-----\n'
                        'Hash: SHA1\n\n'
                        'Body\n'
                        '-----BEGIN PGP SIGNATURE-----\n'
                        'Not a signature.\n'
                        '-----END PGP SIGNATURE-----\n')
        ctrl = MailController(email_address,
                              '*****@*****.**',
                              'subject',
                              invalid_body,
                              bulk=False)
        ctrl.send()
        handleMail()
        self.assertEqual([], self.oopses)
        [notification] = pop_notifications()
        body = notification.get_payload()[0].get_payload(decode=True)
        self.assertIn(
            "An error occurred while processing a mail you sent to "
            "Launchpad's email\ninterface.\n\n\n"
            "Error message:\n\nSignature couldn't be verified: "
            "(7, 58, u'No data')", body)
    def test_invalid_signature(self):
        """Invalid signature should not be handled as an OOPs.

        It should produce a message explaining to the user what went wrong.
        """
        person = self.factory.makePerson()
        transaction.commit()
        email_address = person.preferredemail.email
        invalid_body = (
            "-----BEGIN PGP SIGNED MESSAGE-----\n"
            "Hash: SHA1\n\n"
            "Body\n"
            "-----BEGIN PGP SIGNATURE-----\n"
            "Not a signature.\n"
            "-----END PGP SIGNATURE-----\n"
        )
        ctrl = MailController(email_address, "*****@*****.**", "subject", invalid_body, bulk=False)
        ctrl.send()
        handleMail()
        self.assertEqual([], self.oopses)
        [notification] = pop_notifications()
        body = notification.get_payload()[0].get_payload(decode=True)
        self.assertIn(
            "An error occurred while processing a mail you sent to "
            "Launchpad's email\ninterface.\n\n\n"
            "Error message:\n\nSignature couldn't be verified: "
            "(7, 58, u'No data')",
            body,
        )
Beispiel #3
0
 def test_MailController_into_timeline(self):
     """sendmail records stuff in the timeline."""
     fake_mailer = RecordingMailer()
     self.useFixture(ZopeUtilityFixture(fake_mailer, IMailDelivery, 'Mail'))
     to_addresses = ['*****@*****.**', '*****@*****.**']
     subject = self.getUniqueString('subject')
     with CaptureTimeline() as ctl:
         ctrl = MailController('*****@*****.**', to_addresses, subject,
                               'body', {'key': 'value'})
         ctrl.send()
     self.assertEqual(fake_mailer.from_addr, '*****@*****.**')
     self.assertEqual(fake_mailer.to_addr, to_addresses)
     self.checkTimelineHasOneMailAction(ctl.timeline, subject=subject)
 def test_MailController_into_timeline(self):
     """sendmail records stuff in the timeline."""
     fake_mailer = RecordingMailer()
     self.useFixture(ZopeUtilityFixture(
         fake_mailer, IMailDelivery, 'Mail'))
     to_addresses = ['*****@*****.**', '*****@*****.**']
     subject = self.getUniqueString('subject')
     with CaptureTimeline() as ctl:
         ctrl = MailController(
             '*****@*****.**', to_addresses,
             subject, 'body', {'key': 'value'})
         ctrl.send()
     self.assertEquals(fake_mailer.from_addr, '*****@*****.**')
     self.assertEquals(fake_mailer.to_addr, to_addresses)
     self.checkTimelineHasOneMailAction(ctl.timeline, subject=subject)
    def test_sendUsesRealTo(self):
        """MailController.envelope_to is provided as to_addrs."""
        ctrl = MailController('*****@*****.**', '*****@*****.**', 'subject',
                              'body', envelope_to=['*****@*****.**'])
        sendmail_kwargs = {}

        def fake_sendmail(message, to_addrs=None, bulk=True):
            sendmail_kwargs.update(locals())
        real_sendmail = sendmail.sendmail
        sendmail.sendmail = fake_sendmail
        try:
            ctrl.send()
        finally:
            sendmail.sendmail = real_sendmail
        self.assertEqual('*****@*****.**', sendmail_kwargs['message']['To'])
        self.assertEqual(['*****@*****.**'], sendmail_kwargs['to_addrs'])
    def test_mail_too_big(self):
        """Much-too-big mail should generate a bounce, not an OOPS.

        See <https://bugs.launchpad.net/launchpad/+bug/893612>.
        """
        person = self.factory.makePerson()
        transaction.commit()
        email_address = person.preferredemail.email
        fat_body = "\n".join(["some big mail with this line repeated many many times\n"] * 1000000)
        ctrl = MailController(email_address, "*****@*****.**", "subject", fat_body, bulk=False)
        ctrl.send()
        handleMail()
        self.assertEqual([], self.oopses)
        [notification] = pop_notifications()
        body = notification.get_payload()[0].get_payload(decode=True)
        self.assertIn("The mail you sent to Launchpad is too long.", body)
        self.assertIn("was 55 MB and the limit is 10 MB.", body)
Beispiel #7
0
    def test_sendUsesRealTo(self):
        """MailController.envelope_to is provided as to_addrs."""
        ctrl = MailController('*****@*****.**',
                              '*****@*****.**',
                              'subject',
                              'body',
                              envelope_to=['*****@*****.**'])
        sendmail_kwargs = {}

        def fake_sendmail(message, to_addrs=None, bulk=True):
            sendmail_kwargs.update(locals())

        real_sendmail = sendmail.sendmail
        sendmail.sendmail = fake_sendmail
        try:
            ctrl.send()
        finally:
            sendmail.sendmail = real_sendmail
        self.assertEqual('*****@*****.**', sendmail_kwargs['message']['To'])
        self.assertEqual(['*****@*****.**'], sendmail_kwargs['to_addrs'])
Beispiel #8
0
    def test_mail_too_big(self):
        """Much-too-big mail should generate a bounce, not an OOPS.

        See <https://bugs.launchpad.net/launchpad/+bug/893612>.
        """
        person = self.factory.makePerson()
        transaction.commit()
        email_address = person.preferredemail.email
        fat_body = '\n'.join(
            ['some big mail with this line repeated many many times\n']
            * 1000000)
        ctrl = MailController(
            email_address, '*****@*****.**', 'subject', fat_body,
            bulk=False)
        ctrl.send()
        handleMail()
        self.assertEqual([], self.oopses)
        [notification] = pop_notifications()
        body = notification.get_payload()[0].get_payload(decode=True)
        self.assertIn("The mail you sent to Launchpad is too long.", body)
        self.assertIn("was 55 MB and the limit is 10 MB.", body)