def test_NonGPGAuthenticatedNewBug(self):
        """Mail authenticated other than by gpg can create bugs.

        The incoming mail layer is responsible for authenticating the mail,
        and setting the current principal to the sender of the mail, either
        weakly or non-weakly authenticated.  At the layer of the handler,
        which this class is testing, we shouldn't care by what mechanism we
        decided to act on behalf of the mail sender, only that we did.

        In bug 643219, Launchpad had a problem where the MaloneHandler code
        was puncturing that abstraction and directly looking at the GPG
        signature; this test checks it's fixed.
        """
        # NB SignedMessage by default isn't actually signed, it just has the
        # capability of knowing about signing.
        message = self.factory.makeSignedMessage(body='  affects malone\nhi!')
        self.assertEqual(message.signature, None)

        # Pretend that the mail auth has given us a logged-in user.
        handler = MaloneHandler()
        with person_logged_in(self.factory.makePerson()):
            mail_handled, add_comment_to_bug, commands = \
                handler.extractAndAuthenticateCommands(message,
                    '*****@*****.**')
        self.assertEqual(mail_handled, None)
        self.assertEqual(map(str, commands), [
            'bug new',
            'affects malone',
        ])
    def test_NonGPGAuthenticatedNewBug(self):
        """Mail authenticated other than by gpg can create bugs.

        The incoming mail layer is responsible for authenticating the mail,
        and setting the current principal to the sender of the mail, either
        weakly or non-weakly authenticated.  At the layer of the handler,
        which this class is testing, we shouldn't care by what mechanism we
        decided to act on behalf of the mail sender, only that we did.

        In bug 643219, Launchpad had a problem where the MaloneHandler code
        was puncturing that abstraction and directly looking at the GPG
        signature; this test checks it's fixed.
        """
        # NB SignedMessage by default isn't actually signed, it just has the
        # capability of knowing about signing.
        message = self.factory.makeSignedMessage(body='  affects malone\nhi!')
        self.assertEquals(message.signature, None)

        # Pretend that the mail auth has given us a logged-in user.
        handler = MaloneHandler()
        with person_logged_in(self.factory.makePerson()):
            mail_handled, add_comment_to_bug, commands = \
                handler.extractAndAuthenticateCommands(message,
                    '*****@*****.**')
        self.assertEquals(mail_handled, None)
        self.assertEquals(map(str, commands), [
            'bug new',
            'affects malone',
            ])
 def test_mailToHelpFromUnknownUser(self):
     """Mail from people of no account to help@ is simply dropped.
     """
     message = self.factory.makeSignedMessage(
         email_address='*****@*****.**')
     handler = MaloneHandler()
     mail_handled, add_comment_to_bug, commands = \
         handler.extractAndAuthenticateCommands(message,
             '*****@*****.**')
     self.assertTrue(mail_handled)
     self.assertEmailQueueLength(0)
 def test_mailToHelpFromUnknownUser(self):
     """Mail from people of no account to help@ is simply dropped.
     """
     message = self.factory.makeSignedMessage(
         email_address='*****@*****.**')
     handler = MaloneHandler()
     mail_handled, add_comment_to_bug, commands = \
         handler.extractAndAuthenticateCommands(message,
             '*****@*****.**')
     self.assertEquals(mail_handled, True)
     self.assertEquals(self.getSentMail(), [])
 def test_mailToHelp(self):
     """Mail to help@ generates a help command."""
     user = self.factory.makePerson(email='*****@*****.**')
     message = self.factory.makeSignedMessage(email_address='*****@*****.**')
     handler = MaloneHandler()
     with person_logged_in(user):
         mail_handled, add_comment_to_bug, commands = \
             handler.extractAndAuthenticateCommands(message,
                 '*****@*****.**')
     self.assertEqual(mail_handled, True)
     emails = self.assertEmailQueueLength(1)
     self.assertEqual(message['From'], emails[0]['X-Envelope-To'])
     self.assertEqual('Launchpad Bug Tracker Email Interface Help',
                      emails[0]['Subject'])
 def test_mailToHelpFromNonActiveUser(self):
     """Mail from people without a preferred email get a help message."""
     self.factory.makePerson(email='*****@*****.**',
                             email_address_status=EmailAddressStatus.NEW)
     message = self.factory.makeSignedMessage(email_address='*****@*****.**')
     handler = MaloneHandler()
     response = handler.extractAndAuthenticateCommands(
         message, '*****@*****.**')
     mail_handled, add_comment_to_bug, commands = response
     self.assertTrue(mail_handled)
     emails = self.assertEmailQueueLength(1)
     self.assertEqual('*****@*****.**', emails[0]['X-Envelope-To'])
     self.assertEqual('Launchpad Bug Tracker Email Interface Help',
                      emails[0]['Subject'])
 def test_mailToHelp(self):
     """Mail to help@ generates a help command."""
     user = self.factory.makePerson(email='*****@*****.**')
     message = self.factory.makeSignedMessage(email_address='*****@*****.**')
     handler = MaloneHandler()
     with person_logged_in(user):
         mail_handled, add_comment_to_bug, commands = \
             handler.extractAndAuthenticateCommands(message,
                 '*****@*****.**')
     self.assertEquals(mail_handled, True)
     emails = self.getSentMail()
     self.assertEquals(1, len(emails))
     self.assertEquals([message['From']], emails[0][1])
     self.assertTrue(
         'Subject: Launchpad Bug Tracker Email Interface' in emails[0][2])
 def test_mailToHelpFromNonActiveUser(self):
     """Mail from people without a preferred email get a help message."""
     self.factory.makePerson(
         email='*****@*****.**',
         email_address_status=EmailAddressStatus.NEW)
     message = self.factory.makeSignedMessage(email_address='*****@*****.**')
     handler = MaloneHandler()
     response = handler.extractAndAuthenticateCommands(
         message, '*****@*****.**')
     mail_handled, add_comment_to_bug, commands = response
     self.assertEquals(mail_handled, True)
     emails = self.getSentMail()
     self.assertEquals(1, len(emails))
     self.assertEquals(['*****@*****.**'], emails[0][1])
     self.assertTrue(
         'Subject: Launchpad Bug Tracker Email Interface' in emails[0][2])