~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/mail/tests/test_handler.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-27 00:31:39 UTC
  • mfrom: (14033.1.3 non-active-user-bug-mail)
  • Revision ID: launchpad@pqm.canonical.com-20110927003139-qypu9zoto51d6epv
[r=benji][bug=38162] Do not permit users without preferred email
        addresses to use bug mail.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from canonical.config import config
20
20
from canonical.database.sqlbase import commit
21
21
from canonical.launchpad.ftests import import_secret_test_key
 
22
from canonical.launchpad.interfaces.emailaddress import EmailAddressStatus
22
23
from canonical.launchpad.webapp.authorization import LaunchpadSecurityPolicy
23
24
from canonical.testing.layers import (
24
25
    LaunchpadFunctionalLayer,
111
112
            'affects malone',
112
113
            ])
113
114
 
 
115
    def test_mailToHelpFromNonActiveUser(self):
 
116
        """Mail from people without a preferred email get a help message."""
 
117
        self.factory.makePerson(
 
118
            email='non@eg.dom',
 
119
            email_address_status=EmailAddressStatus.NEW)
 
120
        message = self.factory.makeSignedMessage(email_address='non@eg.dom')
 
121
        handler = MaloneHandler()
 
122
        response = handler.extractAndAuthenticateCommands(
 
123
            message, 'help@bugs.launchpad.net')
 
124
        mail_handled, add_comment_to_bug, commands = response
 
125
        self.assertEquals(mail_handled, True)
 
126
        emails = self.getSentMail()
 
127
        self.assertEquals(1, len(emails))
 
128
        self.assertEquals(['non@eg.dom'], emails[0][1])
 
129
        self.assertTrue(
 
130
            'Subject: Launchpad Bug Tracker Email Interface' in emails[0][2])
 
131
 
114
132
    def test_mailToHelpFromUnknownUser(self):
115
133
        """Mail from people of no account to help@ is simply dropped.
116
134
        """
117
 
        message = self.factory.makeSignedMessage()
 
135
        message = self.factory.makeSignedMessage(
 
136
            email_address='unregistered@eg.dom')
118
137
        handler = MaloneHandler()
119
138
        mail_handled, add_comment_to_bug, commands = \
120
139
            handler.extractAndAuthenticateCommands(message,
124
143
 
125
144
    def test_mailToHelp(self):
126
145
        """Mail to help@ generates a help command."""
127
 
        message = self.factory.makeSignedMessage()
 
146
        user = self.factory.makePerson(email='user@dom.eg')
 
147
        message = self.factory.makeSignedMessage(email_address='user@dom.eg')
128
148
        handler = MaloneHandler()
129
 
        with person_logged_in(self.factory.makePerson()):
 
149
        with person_logged_in(user):
130
150
            mail_handled, add_comment_to_bug, commands = \
131
151
                handler.extractAndAuthenticateCommands(message,
132
152
                    'help@bugs.launchpad.net')
133
153
        self.assertEquals(mail_handled, True)
134
 
        self.assertEquals(len(self.getSentMail()), 1)
135
 
        # TODO: Check the right mail was sent. -- mbp 20100923
 
154
        emails = self.getSentMail()
 
155
        self.assertEquals(1, len(emails))
 
156
        self.assertEquals([message['From']], emails[0][1])
 
157
        self.assertTrue(
 
158
            'Subject: Launchpad Bug Tracker Email Interface' in emails[0][2])
136
159
 
137
160
    def getSentMail(self):
138
161
        # Sending mail is (unfortunately) a side effect of parsing the