def test_smtp_connection_remote_smtp_wrong_credentials(configuration): configuration["SMTP"]["PASSWORD"] = "******" with pytest.raises( ConfigurationException, match=r"SMTP authentication failed with user", ): validate(configuration, validate_remote=True)
def test_ldap_connection_remote_ldap_unreachable(configuration): configuration["LDAP"]["URI"] = "ldap://invalid-ldap.com" with pytest.raises( ConfigurationException, match=r"Could not connect to the LDAP server", ): validate(configuration, validate_remote=True)
def test_smtp_connection_remote_smtp_unreachable(configuration): configuration["SMTP"]["HOST"] = "smtp://invalid-smtp.com" with pytest.raises( ConfigurationException, match=r"Could not connect to the SMTP server", ): validate(configuration, validate_remote=True)
def test_ldap_connection_remote_ldap_wrong_credentials(configuration): configuration["LDAP"]["BIND_PW"] = "invalid-password" with pytest.raises( ConfigurationException, match=r"LDAP authentication failed with user", ): validate(configuration, validate_remote=True)
def test_no_public_key(configuration): configuration["JWT"]["PUBLIC_KEY"] = "invalid-path" with pytest.raises( ConfigurationException, match=r"Public key does not exist", ): validate(configuration)
def test_no_private_key(configuration): configuration["JWT"]["PRIVATE_KEY"] = "invalid-path" with pytest.raises( ConfigurationException, match=r"Private key does not exist", ): validate(configuration)
def check(): """ Check the configuration file. """ from canaille.configuration import validate, ConfigurationException try: validate(current_app.config, validate_remote=True) except ConfigurationException as exc: print(exc) sys.exit(1)
def test_ldap_cannot_create_groups(configuration): from canaille.models import Group def fake_init(*args, **kwarg): raise ldap.INSUFFICIENT_ACCESS with mock.patch.object(Group, "__init__", fake_init): with pytest.raises( ConfigurationException, match=r"cannot create groups at", ): validate(configuration, validate_remote=True)
def test_invalid_theme(configuration): validate(configuration, validate_remote=False) with pytest.raises( ConfigurationException, match=r"Cannot find theme", ): configuration["THEME"] = "invalid" validate(configuration, validate_remote=False) with pytest.raises( ConfigurationException, match=r"Cannot find theme", ): configuration["THEME"] = "/path/to/invalid" validate(configuration, validate_remote=False)
def test_ldap_connection_remote(configuration): validate(configuration, validate_remote=True)
def test_ldap_connection_no_remote(configuration): validate(configuration)