2023-06-03 17:47:05 +00:00
|
|
|
import pytest
|
2023-05-20 15:17:46 +00:00
|
|
|
from canaille import create_app
|
|
|
|
from flask_webtest import TestApp
|
2022-05-08 14:31:17 +00:00
|
|
|
|
2021-12-06 20:49:38 +00:00
|
|
|
|
2023-06-03 17:47:05 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def configuration(slapd_server, ldap_configuration):
|
|
|
|
yield ldap_configuration
|
|
|
|
|
|
|
|
|
2023-05-20 15:17:46 +00:00
|
|
|
def test_ldap_connection_remote_ldap_unreachable(configuration):
|
|
|
|
app = create_app(configuration)
|
|
|
|
testclient = TestApp(app)
|
|
|
|
|
|
|
|
app.config["BACKENDS"]["LDAP"]["URI"] = "ldap://invalid-ldap.com"
|
|
|
|
|
|
|
|
app.config["DEBUG"] = True
|
2021-12-06 20:49:38 +00:00
|
|
|
res = testclient.get("/", status=500, expect_errors=True)
|
2023-03-16 15:25:14 +00:00
|
|
|
res.mustcontain("Could not connect to the LDAP server")
|
2021-12-06 20:49:38 +00:00
|
|
|
|
2023-05-20 15:17:46 +00:00
|
|
|
app.config["DEBUG"] = False
|
2021-12-06 20:49:38 +00:00
|
|
|
res = testclient.get("/", status=500, expect_errors=True)
|
2023-03-16 15:25:14 +00:00
|
|
|
res.mustcontain(no="Could not connect to the LDAP server")
|
2021-12-06 20:49:38 +00:00
|
|
|
|
|
|
|
|
2023-05-20 15:17:46 +00:00
|
|
|
def test_ldap_connection_remote_ldap_wrong_credentials(configuration):
|
|
|
|
app = create_app(configuration)
|
|
|
|
testclient = TestApp(app)
|
2022-05-08 14:31:17 +00:00
|
|
|
|
2023-05-20 15:17:46 +00:00
|
|
|
app.config["BACKENDS"]["LDAP"]["BIND_PW"] = "invalid-password"
|
2021-12-06 20:49:38 +00:00
|
|
|
|
2023-05-20 15:17:46 +00:00
|
|
|
app.config["DEBUG"] = True
|
2021-12-06 20:49:38 +00:00
|
|
|
res = testclient.get("/", status=500, expect_errors=True)
|
2023-03-16 15:25:14 +00:00
|
|
|
res.mustcontain("LDAP authentication failed with user")
|
2021-12-06 20:49:38 +00:00
|
|
|
|
2023-05-20 15:17:46 +00:00
|
|
|
app.config["DEBUG"] = False
|
2021-12-06 20:49:38 +00:00
|
|
|
res = testclient.get("/", status=500, expect_errors=True)
|
2023-03-16 15:25:14 +00:00
|
|
|
res.mustcontain(no="LDAP authentication failed with user")
|