Esempio n. 1
0
    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)
Esempio n. 3
0
 def test_invalid_cc_address_unicode(self):
     # Invalid Cc: header such as no "@" is handled.
     message, test_handler = self.makeSentMessage("*****@*****.**", "*****@*****.**", cc="m\[email protected]")
     handleMail()
     self.assertEqual([], self.oopses)
     self.assertEqual(1, len(test_handler.handledMails))
     self.assertEqual("m\[email protected]", test_handler.handledMails[0]["Cc"])
Esempio n. 4
0
 def test_invalid_from_address_no_at(self):
     # Invalid From: header such as no "@" is handled.
     message, test_handler = self.makeSentMessage("me_at_eg.dom", "*****@*****.**")
     handleMail()
     self.assertEqual([], self.oopses)
     self.assertEqual(1, len(test_handler.handledMails))
     self.assertEqual("me_at_eg.dom", test_handler.handledMails[0]["From"])
 def test_invalid_from_address_unicode(self):
     # Invalid From: header such as no "@" is handled.
     message, test_handler = self.makeSentMessage('m\[email protected]',
                                                  '*****@*****.**')
     handleMail()
     self.assertEqual([], self.oopses)
     self.assertEqual(1, len(test_handler.handledMails))
     self.assertEqual('m\[email protected]', test_handler.handledMails[0]['From'])
Esempio n. 6
0
 def test_invalid_cc_address_no_at(self):
     # Invalid From: header such as no "@" is handled.
     message, test_handler = self.makeSentMessage(
         '*****@*****.**', '*****@*****.**', cc='me_at_eg.dom')
     handleMail()
     self.assertEqual([], self.oopses)
     self.assertEqual(1, len(test_handler.handledMails))
     self.assertEqual('me_at_eg.dom', test_handler.handledMails[0]['Cc'])
Esempio n. 7
0
 def main(self):
     try:
         handleMail(self.txn)
     except ComponentLookupError as lookup_error:
         if lookup_error.args[0] != IMailBox:
             raise
         raise LaunchpadScriptFailure(
             "No mail box is configured. "
             "Please see mailbox.txt for info on how to configure one.")
 def main(self):
     try:
         handleMail(self.txn)
     except ComponentLookupError as lookup_error:
         if lookup_error.args[0] != IMailBox:
             raise
         raise LaunchpadScriptFailure(
             "No mail box is configured. "
             "Please see mailbox.txt for info on how to configure one.")
Esempio n. 9
0
 def test_invalid_to_addresses(self):
     # Invalid To: header should not be handled as an OOPS.
     raw_mail = open(os.path.join(testmails_path, "invalid-to-header.txt")).read()
     # Due to the way handleMail works, even if we pass a valid To header
     # to the TestMailer, as we're doing here, it falls back to parse all
     # To and CC headers from the raw_mail. Also, TestMailer is used here
     # because MailController won't send an email with a broken To: header.
     TestMailer().send("*****@*****.**", "*****@*****.**", raw_mail)
     handleMail()
     self.assertEqual([], self.oopses)
Esempio n. 10
0
 def test_invalid_to_addresses(self):
     # Invalid To: header should not be handled as an OOPS.
     raw_mail = open(os.path.join(testmails_path,
                                  'invalid-to-header.txt')).read()
     # Due to the way handleMail works, even if we pass a valid To header
     # to the TestMailer, as we're doing here, it falls back to parse all
     # To and CC headers from the raw_mail. Also, TestMailer is used here
     # because MailController won't send an email with a broken To: header.
     TestMailer().send("*****@*****.**", "*****@*****.**", raw_mail)
     handleMail()
     self.assertEqual([], self.oopses)
Esempio n. 11
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)
Esempio n. 12
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)