2022-11-17 16:44:54 +00:00
|
|
|
import warnings
|
|
|
|
|
2022-12-24 01:40:50 +00:00
|
|
|
import pytest
|
2024-03-15 18:58:06 +00:00
|
|
|
|
2023-04-09 13:52:55 +00:00
|
|
|
from canaille.app.configuration import ConfigurationException
|
|
|
|
from canaille.app.configuration import validate
|
2022-11-17 16:44:54 +00:00
|
|
|
from canaille.oidc.oauth import get_issuer
|
|
|
|
|
|
|
|
|
|
|
|
def test_issuer(testclient):
|
|
|
|
with warnings.catch_warnings(record=True):
|
2023-04-10 14:24:43 +00:00
|
|
|
testclient.app.config["OIDC"]["JWT"]["ISS"] = "https://anyauth.mydomain.tld"
|
2022-11-17 16:44:54 +00:00
|
|
|
testclient.app.config["SERVER_NAME"] = "https://otherauth.mydomain.tld"
|
|
|
|
with testclient.app.test_request_context("/"):
|
|
|
|
assert get_issuer() == "https://anyauth.mydomain.tld"
|
|
|
|
|
2023-04-10 14:24:43 +00:00
|
|
|
del testclient.app.config["OIDC"]["JWT"]["ISS"]
|
2022-11-17 16:44:54 +00:00
|
|
|
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/"
|
2022-12-24 01:06:28 +00:00
|
|
|
|
|
|
|
|
2023-07-01 16:46:11 +00:00
|
|
|
def test_no_private_key(testclient, configuration):
|
|
|
|
del configuration["OIDC"]["JWT"]["PRIVATE_KEY"]
|
2022-12-24 01:06:28 +00:00
|
|
|
with pytest.raises(
|
|
|
|
ConfigurationException,
|
2023-07-01 16:46:11 +00:00
|
|
|
match=r"No private key has been set",
|
2022-12-24 01:06:28 +00:00
|
|
|
):
|
|
|
|
validate(configuration)
|
|
|
|
|
|
|
|
|
2023-07-01 16:46:11 +00:00
|
|
|
def test_no_public_key(testclient, configuration):
|
|
|
|
del configuration["OIDC"]["JWT"]["PUBLIC_KEY"]
|
2022-12-24 01:06:28 +00:00
|
|
|
with pytest.raises(
|
|
|
|
ConfigurationException,
|
2023-07-01 16:46:11 +00:00
|
|
|
match=r"No public key has been set",
|
2022-12-24 01:06:28 +00:00
|
|
|
):
|
|
|
|
validate(configuration)
|