Exemplo n.º 1
0
 def test_abuse_page_not_preview(self):
     """ Report page displays no warning"""
     mail = MailFactory(message=self.message)
     response = self.client.get('/abuse/report/{}/'.format(mail.identifier))
     self.assertEqual(response.status_code, 200)
     self.assertNotIn(
         "from a preview message", response.content.decode())
Exemplo n.º 2
0
 def test_form_validation(self):
     user = UserFactory()
     message = MessageFactory(author=user)
     mail = MailFactory(message=message)
     f = AbuseNotificationForm({
         'mail': mail.identifier,
         'comments': ''})
     self.assertFalse(f.is_valid())
Exemplo n.º 3
0
    def test_optout_page_not_preview(self):
        """ Unsubscribe page displays no warning"""
        mail = MailFactory(message=self.message)
        response = self.client.get('/h/subscriptions/{}/optout/'.format(
            mail.identifier))
        self.assertEqual(response.status_code, 200)

        self.assertNotIn("from a preview message", response.content.decode())
Exemplo n.º 4
0
 def test_abuse_url(self):
     user = UserFactory()
     message = MessageFactory(author=user)
     mail = MailFactory(message=message)
     self.assertEqual(
         mail.abuse_url,
         'http://test.munch.example.com/abuse/report/{}/'.format(
             mail.identifier))
Exemplo n.º 5
0
 def test_mail_resolution(self):
     user = UserFactory()
     message = MessageFactory(author=user)
     mail = MailFactory(message=message)
     f = AbuseNotificationForm({
         'mail': mail.identifier,
         'comments': 'test'})
     f.is_valid()
     f.save()
Exemplo n.º 6
0
    def test_web_version_links_can_no_track(self):
        self.message.track_clicks = False
        self.message.save()

        mail = MailFactory(message=self.message)
        web_key = WebKey.from_instance(mail.identifier)
        response = self.client.get('/archive/{}/?web_key={}'.format(
            self.message.identifier, web_key.token))

        self.assertNotIn(b'/t/clicks/w/', response.content)
Exemplo n.º 7
0
    def test_html_no_unsubscribe_or_viewonline_rewrite(self):
        self.message.track_clicks = True
        self.message.html = '<body><h1>Hi</h1>{}</body>'.format(
            settings.OPTOUTS['UNSUBSCRIBE_PLACEHOLDER'])
        with patch('munch.apps.spamcheck.SpamChecker.check',
                   side_effect=get_spam_result_mock):
            self.message.save()

        mail = MailFactory(message=self.message)
        content = self.message.to_mail(mail)
        self.assertNotIn('/clicks/m/', content.alternatives[0][0])
Exemplo n.º 8
0
    def test_new_optout_external_get(self):
        self.message.external_optout = True
        self.message.save()
        mail = MailFactory(message=self.message)

        self.assertFalse(
            OptOut.objects.filter(identifier=mail.identifier).exists())
        response = self.client.get('/h/subscriptions/{}/optout/'.format(
            mail.identifier))
        self.assertEqual(response.status_code, 200)
        self.assertIn('should get in touch with him',
                      response.content.decode())
Exemplo n.º 9
0
    def test_dont_rewrite_bodylink(self):
        text = """Hi

        Go to http://example.com
        """
        mail = MailFactory(message=self.message)
        out = rewrite_plaintext_links(text,
                                      app_url=self.message.get_app_url(),
                                      unsubscribe_url=mail.unsubscribe_url,
                                      mail_identifier=mail.identifier,
                                      links_map=self.message.msg_links)
        self.assertNotIn('/clicks/m', out)
Exemplo n.º 10
0
    def test_new_optout(self):
        """ OptOut when no other opptout exist for this email"""
        mail = MailFactory(message=self.message)

        self.assertFalse(
            OptOut.objects.filter(identifier=mail.identifier).exists())
        response = self.client.post('/h/subscriptions/{}/optout/'.format(
            mail.identifier))
        self.assertEqual(response.status_code, 302)

        o = OptOut.objects.get(identifier=mail.identifier)
        self.assertEqual(o.origin, OptOut.BY_WEB)
Exemplo n.º 11
0
 def test_abuse_makes_optout(self):
     """ An abuse should create an optout for the given mail """
     user = UserFactory()
     message = MessageFactory(author=user)
     mail = MailFactory(message=message)
     response = self.client.post(
         'http://test.munch.example.com/abuse/report/{}/'.format(
             mail.identifier),
         {'mail': mail.identifier, 'comments': 'test'})
     self.assertEqual(response.status_code, 302)
     optout = OptOut.objects.get(identifier=mail.identifier)
     self.assertEqual(optout.origin, OptOut.BY_ABUSE)
Exemplo n.º 12
0
    def test_html_non_generation(self):
        message = MessageFactory(
            author=self.user,
            track_open=False,
            html='<body><h1>Foo</h1>{}</body>'.format(
                settings.OPTOUTS['UNSUBSCRIBE_PLACEHOLDER']))
        with patch('munch.apps.spamcheck.SpamChecker.check',
                   side_effect=get_spam_result_mock):
            message.save()

        mail = MailFactory(message=message)
        content = message.to_mail(mail)
        self.assertNotIn('pixel.gif', content.alternatives[0][0])
Exemplo n.º 13
0
    def test_new_optout_external_post(self):
        self.message.external_optout = True
        self.message.save()
        mail = MailFactory(message=self.message)

        self.assertFalse(
            OptOut.objects.filter(identifier=mail.identifier).exists())
        response = self.client.post('/h/subscriptions/{}/optout/'.format(
            mail.identifier))
        self.assertEqual(response.status_code, 405)

        self.assertFalse(
            OptOut.objects.filter(identifier=mail.identifier).exists())
Exemplo n.º 14
0
 def setUp(self):
     self.user = UserFactory()
     self.message = MessageFactory(
         author=self.user,
         track_clicks=True,
         track_open=False,
         html=('<body><a href="http://example.com">'
               'Hi</a>{}</body>').format(
                   settings.OPTOUTS['UNSUBSCRIBE_PLACEHOLDER']))
     with patch('munch.apps.spamcheck.SpamChecker.check',
                side_effect=get_spam_result_mock):
         self.message.save()
     self.mail = MailFactory(message=self.message)
Exemplo n.º 15
0
    def test_reaction_time(self):
        with fake_time('2016-10-10 08:00:00'):
            message = MessageFactory(status='message_ok', author=self.user)
            mail = MailFactory(message=message)
            MailStatusFactory(mail=mail)
            MailStatusFactory(mail=mail, status=MailStatus.SENDING)
            MailStatusFactory(mail=mail, status=MailStatus.DELIVERED)
        with fake_time('2016-10-10 08:00:15'):
            self.client.get('/t/open/{}'.format(mail.identifier))
            records = TrackRecord.objects.filter(identifier=mail.identifier,
                                                 kind='read')

        self.assertEqual(records.first().properties['reaction_time'], '15')
Exemplo n.º 16
0
    def test_hosted_mail_with_key_works_tracks(self):
        mail = MailFactory(message=self.message)
        MailStatusFactory(mail=mail, status=MailStatus.QUEUED)
        MailStatusFactory(mail=mail, status=MailStatus.SENDING)
        MailStatusFactory(mail=mail, status=MailStatus.DELIVERED)

        wk = WebKey.from_instance(Mail.objects.first().identifier)
        response = self.client.get('/archive/{}/?web_key={}'.format(
            self.message.identifier, wk.token))
        self.assertEqual(response.status_code, 200)

        record = TrackRecord.objects.filter(kind='read').first()
        self.assertEqual(TrackRecord.objects.filter(kind='read').count(), 1)
        self.assertEqual(record.properties['source'], READ_BROWSER)
Exemplo n.º 17
0
    def test_mk_redirection(self):
        mail = MailFactory(message=self.message)
        url = 'http://example.com'
        redir_url = WebVersionLinksRewriter.rewrite(mail.identifier,
                                                    self.message.get_app_url(),
                                                    mail.message.msg_links,
                                                    url)

        # build local url from fully qualified url
        local_redir_url = redir_url.split('://')[1].split('/', 1)[1]

        resp = self.client.get('/' + local_redir_url)
        self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp['Location'], url)
Exemplo n.º 18
0
    def test_valid_unsubscribe(self):
        user = UserFactory()
        message = MessageFactory(author=user)
        mail = MailFactory(message=message)

        recipient = 'unsubscribe-{}@test.munch.example.com'.format(
            mail.identifier)
        unsubscribe = UNSUBSCRIBE_EMAIL.replace('||TO||', recipient)
        unsubscribe = unsubscribe.replace('||RETURNPATH||', recipient)
        message = email.message_from_string(unsubscribe)
        envelope = Envelope()
        envelope.parse_msg(message)
        envelope.recipients = [recipient]
        handler = UnsubscribeHandler(envelope, message)
        self.assertIsNotNone(handler.apply())
Exemplo n.º 19
0
    def test_valid_arf(self):
        user = UserFactory()
        message = MessageFactory(author=user)
        mail = MailFactory(message=message)

        recipient = 'return-{}@test.munch.example.com'.format(
            mail.identifier)
        arf = ARF_REPORT.replace('||TO||', '*****@*****.**')
        arf = arf.replace('||RETURNPATH||', recipient)
        message = email.message_from_string(arf)
        envelope = Envelope()
        envelope.parse_msg(message)
        envelope.recipients = [recipient]
        handler = ARFHandler(envelope, message)
        self.assertIsNotNone(handler.apply())
Exemplo n.º 20
0
    def test_html_generation_preserve_doctype(self):
        self.message.track_clicks = True
        self.message.html = (
            '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '
            '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
            '<html xmlns="http://www.w3.org/1999/xhtml">{}</html>').format(
                settings.OPTOUTS['UNSUBSCRIBE_PLACEHOLDER'])
        with patch('munch.apps.spamcheck.SpamChecker.check',
                   side_effect=get_spam_result_mock):
            self.message.save()

        mail = MailFactory(message=self.message)
        content = self.message.to_mail(mail)
        self.assertIn(
            ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//'
             'EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.'
             'dtd">'), content.alternatives[0][0])
Exemplo n.º 21
0
    def test_optout_again(self):
        """ OptOut when a previous optout exists:

        Keep it but change date and origin"""
        mail = MailFactory(message=self.message)
        first_optout = OptOutFactory(identifier=mail.identifier,
                                     address=mail.recipient,
                                     origin=OptOut.BY_MAIL)
        first_optout_date = first_optout.creation_date

        response = self.client.post('/h/subscriptions/{}/optout/'.format(
            mail.identifier))
        self.assertEqual(response.status_code, 302)

        o = OptOut.objects.get(identifier=mail.identifier)
        self.assertEqual(o, first_optout)
        self.assertEqual(o.origin, OptOut.BY_WEB)
        self.assertNotEqual(o.creation_date, first_optout_date)
Exemplo n.º 22
0
    def test_valid_tracker(self):
        with fake_time('2016-10-10 08:00:00'):
            message = MessageFactory(status='message_ok', author=self.user)
            mail = MailFactory(message=message)
            MailStatusFactory(mail=mail)
            MailStatusFactory(mail=mail, status=MailStatus.SENDING)
            MailStatusFactory(mail=mail, status=MailStatus.DELIVERED)
        with fake_time('2016-10-10 08:00:15'):
            resp = self.client.get('/t/open/{}'.format(mail.identifier))

        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp['Content-Type'], 'image/gif')
        self.assertEqual(resp.content, TRACKER_PIXEL)

        records = TrackRecord.objects.filter(identifier=mail.identifier,
                                             kind='read',
                                             properties__source=READ_MUA_PIXEL)

        self.assertEqual(records.count(), 1)
Exemplo n.º 23
0
    def test_mk_web_redirection(self):
        mail = MailFactory(message=self.message)
        url = 'http://example.com'
        redir_url = WebVersionLinksRewriter.rewrite(mail.identifier,
                                                    self.message.get_app_url(),
                                                    mail.message.msg_links,
                                                    url)

        # build local url from fully qualified url
        local_redir_url = redir_url.split('://')[1].split('/', 1)[1]

        self.assertEqual(LinkMap.objects.count(), 1)
        self.assertEqual(
            TrackRecord.objects.filter(kind='click',
                                       identifier=mail.identifier).count(), 0)
        resp = self.client.get('/' + local_redir_url)
        self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp['Location'], url)
        self.assertEqual(
            TrackRecord.objects.filter(kind='click',
                                       identifier=mail.identifier).count(), 1)
Exemplo n.º 24
0
 def setUp(self):
     self.user = UserFactory()
     self.message = MessageFactory(author=self.user)
     self.mail = MailFactory(message=self.message)
Exemplo n.º 25
0
 def test_web_versions_open_can_track(self):
     self.message.track_open = True
     self.message.save()
     mail = MailFactory(message=self.message)
     self.assertIn('web_key', mail.web_view_url)