def test_double_confirmation(self): # A join request comes in using both the -join address and the word # 'subscribe' in the first line of the body. This should produce just # one subscription request and one confirmation response. msg = mfs("""\ From: [email protected] To: [email protected] subscribe """) # Adding the subaddress to the metadata dictionary mimics what happens # when the above email message is first processed by the lmtp runner. # For convenience, we skip that step in this test. self._commandq.enqueue(msg, dict(listname='*****@*****.**', subaddress='join')) self._runner.run() # There will be two messages in the queue. The first one is a reply # to Anne notifying her of the status of her command email. The # second one is the confirmation message of her join request. messages = get_queue_messages('virgin', sort_on='subject') self.assertEqual(len(messages), 2) self.assertTrue(str(messages[1].msg['subject']).startswith('confirm')) self.assertEqual(messages[0].msg['subject'], 'The results of your email commands') # Search the contents of the results message. There should be just # one 'Confirmation email' line. confirmation_lines = [] in_results = False for line in body_line_iterator(messages[0].msg, decode=True): line = line.strip() if in_results: if line.startswith('- Done'): break if len(line) > 0: confirmation_lines.append(line) if line.strip() == '- Results:': in_results = True # There should be exactly one confirmation line. self.assertEqual(len(confirmation_lines), 1) # And the confirmation line should name Anne's email address. self.assertTrue('*****@*****.**' in confirmation_lines[0])
def test_double_confirmation(self): # 'confirm' in the Subject and in the To header should not try to # confirm the token twice. # # Clear out the virgin queue so that the test below only sees the # reply to the confirmation message. get_queue_messages('virgin') subject = 'Re: confirm {0}'.format(self._token) to = 'test-confirm+{0}@example.com'.format(self._token) msg = mfs("""\ From: Anne Person <*****@*****.**> """) msg['Subject'] = subject msg['To'] = to self._commandq.enqueue(msg, dict(listname='*****@*****.**', subaddress='confirm')) self._runner.run() # Anne is now a confirmed member so her user record and email address # should exist in the database. manager = getUtility(IUserManager) user = manager.get_user('*****@*****.**') self.assertEqual(list(user.addresses)[0].email, '*****@*****.**') # Make sure that the confirmation was not attempted twice. messages = get_queue_messages('virgin') self.assertEqual(len(messages), 1) # Search the contents of the results message. There should be just # one 'Confirmation email' line. confirmation_lines = [] in_results = False for line in body_line_iterator(messages[0].msg, decode=True): line = line.strip() if in_results: if line.startswith('- Done'): break if len(line) > 0: confirmation_lines.append(line) if line.strip() == '- Results:': in_results = True self.assertEqual(len(confirmation_lines), 1) self.assertFalse('did not match' in confirmation_lines[0])
def test_join_when_already_a_member(self): anne = getUtility(IUserManager).create_user('*****@*****.**') self._mlist.subscribe(list(anne.addresses)[0]) # When someone tries to join by email and they are already a member, # ignore the request. msg = mfs("""\ From: [email protected] To: [email protected] Subject: join """) self._commandq.enqueue(msg, dict(listname='*****@*****.**')) self._runner.run() # There will be one message in the queue - a reply to Anne notifying # her of the status of her command email. Because Anne is already # subscribed to the list, she gets and needs no confirmation. messages = get_queue_messages('virgin') self.assertEqual(len(messages), 1) self.assertEqual(messages[0].msg['subject'], 'The results of your email commands') # Search the contents of the results message. There should be just # one 'Confirmation email' line. confirmation_lines = [] in_results = False for line in body_line_iterator(messages[0].msg, decode=True): line = line.strip() if in_results: if line.startswith('- Done'): break if len(line) > 0: confirmation_lines.append(line) if line.strip() == '- Results:': in_results = True # There should be exactly one confirmation line. self.assertEqual(len(confirmation_lines), 1) # And the confirmation line should name Anne's email address. self.assertTrue('*****@*****.**' in confirmation_lines[0])