def test_no_cert(self):
        """
        Assert that certificates are not required.
        """
        config = get_basic_config(**{})

        # This should not raise an Exception
        configuration._validate_ssl_cert(config, constants.CONFIG_SSL_AUTH_CA_CERT)
    def test_no_cert(self):
        """
        Assert that certificates are not required.
        """
        config = get_basic_config(**{})

        # This should not raise an Exception
        configuration._validate_ssl_cert(config,
                                         constants.CONFIG_SSL_AUTH_CA_CERT)
    def test_bad_cert(self):
        """
        Assert that a bad cert raises an error.
        """
        config = get_basic_config(**{constants.CONFIG_SSL_AUTH_CA_CERT: 'You cannot be serious.'})

        try:
            configuration._validate_ssl_cert(config, constants.CONFIG_SSL_AUTH_CA_CERT)
            self.fail('The validator should have raised an Exception, but it did not.')
        except configuration_utils.ValidationError, e:
            self.assertEqual(str(e), 'The SSL certificate <ssl_auth_ca_cert> is not a valid certificate.')
    def test_good_cert(self, validate_cert):
        """
        Assert that a good cert passes the check.
        """
        cert = 'Good Cert (well, once mock is done with it!)'
        config = get_basic_config(**{constants.CONFIG_SSL_AUTH_CA_CERT: cert})

        # This should not raise an Exception
        configuration._validate_ssl_cert(config, constants.CONFIG_SSL_AUTH_CA_CERT)

        # Make sure the mock was called
        validate_cert.assert_called_once_with(cert)
    def test_good_cert(self, validate_cert):
        """
        Assert that a good cert passes the check.
        """
        cert = 'Good Cert (well, once mock is done with it!)'
        config = get_basic_config(**{constants.CONFIG_SSL_AUTH_CA_CERT: cert})

        # This should not raise an Exception
        configuration._validate_ssl_cert(config,
                                         constants.CONFIG_SSL_AUTH_CA_CERT)

        # Make sure the mock was called
        validate_cert.assert_called_once_with(cert)
    def test_bad_cert(self):
        """
        Assert that a bad cert raises an error.
        """
        config = get_basic_config(
            **{constants.CONFIG_SSL_AUTH_CA_CERT: 'You cannot be serious.'})

        try:
            configuration._validate_ssl_cert(config,
                                             constants.CONFIG_SSL_AUTH_CA_CERT)
            self.fail(
                'The validator should have raised an Exception, but it did not.'
            )
        except configuration_utils.ValidationError, e:
            self.assertEqual(
                str(e),
                'The SSL certificate <ssl_auth_ca_cert> is not a valid certificate.'
            )