canaille-globuzma/tests/oidc/test_configuration.py

42 lines
1.4 KiB
Python
Raw Normal View History

import warnings
import pytest
2023-04-09 13:52:55 +00:00
from canaille.app.configuration import ConfigurationException
from canaille.app.configuration import validate
from canaille.oidc.oauth import get_issuer
def test_issuer(testclient):
with warnings.catch_warnings(record=True):
testclient.app.config["OIDC"]["JWT"]["ISS"] = "https://anyauth.mydomain.tld"
testclient.app.config["SERVER_NAME"] = "https://otherauth.mydomain.tld"
with testclient.app.test_request_context("/"):
assert get_issuer() == "https://anyauth.mydomain.tld"
del testclient.app.config["OIDC"]["JWT"]["ISS"]
with testclient.app.test_request_context("/"):
assert get_issuer() == "https://otherauth.mydomain.tld"
testclient.app.config["SERVER_NAME"] = None
with testclient.app.test_request_context("/"):
assert get_issuer() == "http://localhost/"
2023-07-01 16:46:11 +00:00
def test_no_private_key(testclient, configuration):
del configuration["OIDC"]["JWT"]["PRIVATE_KEY"]
with pytest.raises(
ConfigurationException,
2023-07-01 16:46:11 +00:00
match=r"No private key has been set",
):
validate(configuration)
2023-07-01 16:46:11 +00:00
def test_no_public_key(testclient, configuration):
del configuration["OIDC"]["JWT"]["PUBLIC_KEY"]
with pytest.raises(
ConfigurationException,
2023-07-01 16:46:11 +00:00
match=r"No public key has been set",
):
validate(configuration)