forked from Github-Mirrors/canaille
backend fixture is parametrizable
This commit is contained in:
parent
422af73b89
commit
14ccb69762
9 changed files with 72 additions and 21 deletions
16
poetry.lock
generated
16
poetry.lock
generated
|
@ -1337,6 +1337,20 @@ files = [
|
|||
[package.dependencies]
|
||||
Werkzeug = ">=2.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "pytest-lazy-fixture"
|
||||
version = "0.6.3"
|
||||
description = "It helps to use fixtures in pytest.mark.parametrize"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "pytest-lazy-fixture-0.6.3.tar.gz", hash = "sha256:0e7d0c7f74ba33e6e80905e9bfd81f9d15ef9a790de97993e34213deb5ad10ac"},
|
||||
{file = "pytest_lazy_fixture-0.6.3-py3-none-any.whl", hash = "sha256:e0b379f38299ff27a653f03eaa69b08a6fd4484e46fd1c9907d984b9f9daeda6"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
pytest = ">=3.2.5"
|
||||
|
||||
[[package]]
|
||||
name = "python-dateutil"
|
||||
version = "2.8.2"
|
||||
|
@ -1925,4 +1939,4 @@ sentry = ["sentry-sdk"]
|
|||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = ">=3.8, <4"
|
||||
content-hash = "06c9386f1765bba769c90e910bbf15fab3cf57f0e59b0bc3a784c2f64886710f"
|
||||
content-hash = "228495329d8d66307450ea2518ec52432ac9d74973c5aa10cc3ef1647be087e2"
|
||||
|
|
|
@ -76,6 +76,7 @@ pytest-httpserver = "*"
|
|||
slapd = "*"
|
||||
smtpdfix = "*"
|
||||
pytest-flask = "^1.2.0"
|
||||
pytest-lazy-fixture = "^0.6.3"
|
||||
|
||||
[tool.poetry.group.demo]
|
||||
optional = true
|
||||
|
|
|
@ -7,6 +7,11 @@ from canaille.app.flask import set_parameter_in_url_query
|
|||
from flask_webtest import TestApp
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configuration(ldap_configuration):
|
||||
yield ldap_configuration
|
||||
|
||||
|
||||
def test_set_parameter_in_url_query():
|
||||
assert (
|
||||
set_parameter_in_url_query("https://auth.mydomain.tld", foo="bar")
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import pytest
|
||||
from canaille.backends.ldap.backend import LDAPBackend
|
||||
from tests.backends.ldap import CustomSlapdObject
|
||||
|
||||
|
||||
|
@ -22,3 +23,28 @@ def slapd_server():
|
|||
yield slapd
|
||||
finally:
|
||||
slapd.stop()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ldap_configuration(configuration, slapd_server):
|
||||
configuration["BACKENDS"] = {
|
||||
"LDAP": {
|
||||
"ROOT_DN": slapd_server.suffix,
|
||||
"URI": slapd_server.ldap_uri,
|
||||
"BIND_DN": slapd_server.root_dn,
|
||||
"BIND_PW": slapd_server.root_pw,
|
||||
"USER_BASE": "ou=users",
|
||||
"USER_FILTER": "(uid={login})",
|
||||
"GROUP_BASE": "ou=groups",
|
||||
"TIMEOUT": 0.1,
|
||||
},
|
||||
}
|
||||
yield configuration
|
||||
del configuration["BACKENDS"]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ldap_backend(slapd_server, ldap_configuration):
|
||||
backend = LDAPBackend(ldap_configuration)
|
||||
with backend.session():
|
||||
yield backend
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
import pytest
|
||||
from canaille import create_app
|
||||
from flask_webtest import TestApp
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configuration(slapd_server, ldap_configuration):
|
||||
yield ldap_configuration
|
||||
|
||||
|
||||
def test_ldap_connection_remote_ldap_unreachable(configuration):
|
||||
app = create_app(configuration)
|
||||
testclient = TestApp(app)
|
||||
|
|
|
@ -10,6 +10,11 @@ from flask_webtest import TestApp
|
|||
from . import CustomSlapdObject
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configuration(ldap_configuration):
|
||||
yield ldap_configuration
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def slapd_server():
|
||||
slapd = CustomSlapdObject()
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import pytest
|
||||
from canaille import create_app
|
||||
from canaille.app import models
|
||||
from canaille.backends.ldap.backend import LDAPBackend
|
||||
from flask_webtest import TestApp
|
||||
from pytest_lazyfixture import lazy_fixture
|
||||
from werkzeug.security import gen_salt
|
||||
|
||||
|
||||
|
@ -12,24 +12,12 @@ pytest_plugins = [
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def configuration(slapd_server, smtpd):
|
||||
def configuration(smtpd):
|
||||
smtpd.config.use_starttls = True
|
||||
conf = {
|
||||
"SECRET_KEY": gen_salt(24),
|
||||
"LOGO": "/static/img/canaille-head.png",
|
||||
"TIMEZONE": "UTC",
|
||||
"BACKENDS": {
|
||||
"LDAP": {
|
||||
"ROOT_DN": slapd_server.suffix,
|
||||
"URI": slapd_server.ldap_uri,
|
||||
"BIND_DN": slapd_server.root_dn,
|
||||
"BIND_PW": slapd_server.root_pw,
|
||||
"USER_BASE": "ou=users",
|
||||
"USER_FILTER": "(uid={login})",
|
||||
"GROUP_BASE": "ou=groups",
|
||||
"TIMEOUT": 0.1,
|
||||
},
|
||||
},
|
||||
"ACL": {
|
||||
"DEFAULT": {
|
||||
"READ": ["user_name", "groups"],
|
||||
|
@ -88,11 +76,9 @@ def configuration(slapd_server, smtpd):
|
|||
return conf
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def backend(slapd_server, configuration):
|
||||
backend = LDAPBackend(configuration)
|
||||
with backend.session():
|
||||
yield backend
|
||||
@pytest.fixture(params=[lazy_fixture("ldap_backend")])
|
||||
def backend(request):
|
||||
yield request.param
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
import os
|
||||
|
||||
import pytest
|
||||
from canaille import create_app
|
||||
from canaille.commands import cli
|
||||
from flask_webtest import TestApp
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configuration(ldap_configuration):
|
||||
yield ldap_configuration
|
||||
|
||||
|
||||
def test_install_keypair(configuration, tmpdir):
|
||||
keys_dir = os.path.join(tmpdir, "keys")
|
||||
os.makedirs(keys_dir)
|
||||
|
|
|
@ -14,7 +14,9 @@ from werkzeug.security import gen_salt
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def app(app):
|
||||
# For some reason all the params from the overriden fixture must be present here
|
||||
# https://github.com/pytest-dev/pytest/issues/11075
|
||||
def app(app, configuration, backend):
|
||||
os.environ["AUTHLIB_INSECURE_TRANSPORT"] = "true"
|
||||
yield app
|
||||
|
||||
|
|
Loading…
Reference in a new issue