Exemple #1
0
    def test_spf(self, field, message):
        if field:
            if settings.CMS_TEST_SPF:
                from cubane.lib.spfcheck import SPFCheck
                check = SPFCheck()
                check.check_local_ips(field)

                if not check.test_pass:
                    msg = mark_safe(
                        message +
                        '<a href="https://en.wikipedia.org/wiki/Sender_Policy_Framework" target="_blank">Sender Policy Framework</a> (SPF).'
                        + check.html_results)

                    if settings.DEBUG or settings.CMS_SOFTFAIL_SPF or 'cubane.enquiry' not in settings.INSTALLED_APPS:
                        # soft fail in development or otherwise...
                        messages.error(self._request, msg)
                    else:
                        # hard fail in production.
                        raise forms.ValidationError(msg)

        return field
Exemple #2
0
    def test_should_accummulate_tests(self):
        spf = SPFCheck()
        spf.check('176.58.117.208', '*****@*****.**')
        spf.check('1.2.3.4', '*****@*****.**')
        self.assertEqual(2, len(spf.results))

        html = spf.html_results
        self.assertIn('sender SPF authorized', html)
        self.assertIn('domain owner discourages use of this host', html)
Exemple #3
0
class LibSPFCheckTestCase(CubaneTestCase):
    def setUp(self):
        self.spf = SPFCheck()

    def test_check_spf_should_pass_for_valid_ipv4_with_spf_resord_present(
            self):
        self.assertEqual(
            ('176.58.117.208', 'pass', 250, 'sender SPF authorized'),
            self.spf.check('176.58.117.208', '*****@*****.**'))
        self.assertTrue(self.spf.test_pass)

    def test_check_spf_should_fail_for_valid_ipv4_with_spf_resord_present(
            self):
        self.assertEqual(('1.2.3.4', 'softfail', 250,
                          'domain owner discourages use of this host'),
                         self.spf.check('1.2.3.4', '*****@*****.**'))
        self.assertFalse(self.spf.test_pass)

    def test_check_spf_should_pass_for_valid_ipv6_with_spf_record_present(
            self):
        self.assertEqual(
            ('2001:4860:4000:aaaa:bbbb:cccc:dddd:eeee', 'pass', 250,
             'sender SPF authorized'),
            self.spf.check('2001:4860:4000:aaaa:bbbb:cccc:dddd:eeee',
                           '*****@*****.**'))
        self.assertTrue(self.spf.test_pass)

    def test_check_spf_should_fail_for_valid_ipv6_with_spf_record_present(
            self):
        self.assertEqual(
            ('1234:1234:1234:aaaa:bbbb:cccc:dddd:eeee', 'softfail', 250,
             'domain owner discourages use of this host'),
            self.spf.check('1234:1234:1234:aaaa:bbbb:cccc:dddd:eeee',
                           '*****@*****.**'))
        self.assertFalse(self.spf.test_pass)

    def test_check_local_ips_should_fail(self):
        self.spf.check_local_ips('*****@*****.**')
        self.assertFalse(self.spf.test_pass)
Exemple #4
0
 def test_new_instance_should_have_no_test_results(self):
     self.assertEqual(0, len(SPFCheck().results))
Exemple #5
0
 def setUp(self):
     self.spf = SPFCheck()
Exemple #6
0
 def test_instance_with_no_checks_should_render_empty_html_results(self):
     self.assertEqual('', SPFCheck().html_results)
Exemple #7
0
 def test_instance_with_no_checks_should_fail_spf_check(self):
     self.assertFalse(SPFCheck().test_pass)