def _create_mocked_method_raising(exception: Exception = None):
        def mock(*args, **kwargs):
            if exception == None:
                pass
            else:
                raise exception

        check = smtpcheck.SMTPCheck()
        check._verify_connection = mock

        return check
Example #2
0
    def test_connection_without_encryption_failures_when_credentials_are_invalid(
            self):
        self._start_container(self._create_container().with_env(
            'SMTP_USE_TLS', 'false'))

        status, txt, err = smtpcheck.SMTPCheck().main("localhost", 2525,
                                                      "invalid", "invalid", '',
                                                      5)

        self.assertFalse(status)
        self.assertEqual('Authentication failed', txt)
Example #3
0
    def test_connection_without_encryption_success_when_credentials_are_correct(
            self):
        self._start_container(self._create_container().with_env(
            'SMTP_USE_TLS', 'false'))

        status, txt, err = smtpcheck.SMTPCheck().main("localhost", 2525,
                                                      "durruti", "durruti", '',
                                                      15)

        self.assertTrue(status)
        self.assertEqual('Success', txt)
Example #4
0
    def test_connects_to_tls(self):
        self._start_container(
            self._create_container().with_env('SMTP_USE_TLS', 'true').with_env(
                'SMTPD_TLS_CERT_FILE',
                '/keys/bakunin.example.org.crt').with_env(
                    'SMTPD_TLS_KEY_FILE',
                    '/keys/bakunin.example.org.key').with_env(
                        'SMTP_TLS_CA_FILE', '/keys/cacert.pem').with_env(
                            'ENABLE_DKIM', 'false').with_volume_mapping(
                                os.path.dirname(os.path.realpath(__file__)) +
                                '/files/keys',
                                '/keys',
                                mode='ro'))

        status, txt, err = smtpcheck.SMTPCheck().main("127.0.0.1", 2525,
                                                      "durruti", "durruti",
                                                      'starttls_self_signed',
                                                      5)
        self.assertTrue(status)
Example #5
0
    def test_does_not_connect_to_starttls_if_self_signed_certificate_is_not_allowed(
            self):
        self._start_container(
            self._create_container().with_env('SMTP_USE_TLS', 'true').with_env(
                'SMTPD_TLS_CERT_FILE',
                '/keys/bakunin.example.org.crt').with_env(
                    'SMTPD_TLS_KEY_FILE',
                    '/keys/bakunin.example.org.key').with_env(
                        'SMTP_TLS_CA_FILE', '/keys/cacert.pem').with_env(
                            'ENABLE_DKIM', 'false').with_volume_mapping(
                                os.path.dirname(os.path.realpath(__file__)) +
                                '/files/keys',
                                '/keys',
                                mode='ro'))

        status, txt, err = smtpcheck.SMTPCheck().main("127.0.0.1", 2525,
                                                      "durruti", "durruti",
                                                      'starttls', 5)
        self.assertIn(
            '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed',
            str(err))
        self.assertFalse(status)
Example #6
0
 def test_connection_refused_when_invalid_port_entered(self):
     status, txt, err = smtpcheck.SMTPCheck().main("127.0.0.1", 2529,
                                                   "durruti", "durruti", '',
                                                   2)
     self.assertFalse(status)
     self.assertEqual('Connection refused', txt)