2022-06-20 12:16:55 +02:00
|
|
|
""" tests the config file things """
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
import sys
|
|
|
|
import toml
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from kanidm.types import KanidmClientConfig
|
|
|
|
from kanidm.utils import load_config
|
|
|
|
|
|
|
|
|
2022-10-02 03:28:58 +02:00
|
|
|
EXAMPLE_CONFIG_FILE = "../examples/config"
|
2022-09-29 02:08:15 +02:00
|
|
|
|
2022-06-20 12:16:55 +02:00
|
|
|
|
|
|
|
def test_load_config_file() -> None:
|
2022-09-29 02:08:15 +02:00
|
|
|
"""tests that the file loads"""
|
2022-06-20 12:16:55 +02:00
|
|
|
if not Path(EXAMPLE_CONFIG_FILE).expanduser().resolve().exists():
|
|
|
|
print("Can't find client config file", file=sys.stderr)
|
|
|
|
pytest.skip()
|
|
|
|
config = load_config(EXAMPLE_CONFIG_FILE)
|
|
|
|
kanidm_config = KanidmClientConfig.parse_obj(config)
|
2022-09-29 02:08:15 +02:00
|
|
|
assert kanidm_config.uri == "https://idm.example.com/"
|
2022-06-20 12:16:55 +02:00
|
|
|
print(f"{kanidm_config.uri=}")
|
|
|
|
print(kanidm_config)
|
|
|
|
|
|
|
|
|
|
|
|
def test_radius_groups() -> None:
|
2022-09-29 02:08:15 +02:00
|
|
|
"""testing loading a config file with radius groups defined"""
|
2022-06-20 12:16:55 +02:00
|
|
|
|
|
|
|
config_toml = """
|
|
|
|
radius_groups = [
|
2022-10-02 03:28:58 +02:00
|
|
|
{ spn = "hello world", "vlan" = 1234 },
|
2022-06-20 12:16:55 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
"""
|
|
|
|
config_parsed = toml.loads(config_toml)
|
|
|
|
print(config_parsed)
|
|
|
|
kanidm_config = KanidmClientConfig.parse_obj(config_parsed)
|
|
|
|
for group in kanidm_config.radius_groups:
|
2022-10-02 03:28:58 +02:00
|
|
|
print(group.spn)
|
|
|
|
assert group.spn == "hello world"
|
2022-06-20 12:16:55 +02:00
|
|
|
|
2022-09-29 02:08:15 +02:00
|
|
|
|
2022-06-20 12:16:55 +02:00
|
|
|
def test_radius_clients() -> None:
|
2022-09-29 02:08:15 +02:00
|
|
|
"""testing loading a config file with radius groups defined"""
|
2022-06-20 12:16:55 +02:00
|
|
|
|
|
|
|
config_toml = """
|
|
|
|
radius_clients = [ { name = "hello world", ipaddr = "10.0.0.5", secret = "cr4bj0oz" },
|
|
|
|
]
|
|
|
|
|
|
|
|
"""
|
|
|
|
config_parsed = toml.loads(config_toml)
|
|
|
|
print(config_parsed)
|
|
|
|
kanidm_config = KanidmClientConfig.parse_obj(config_parsed)
|
|
|
|
client = kanidm_config.radius_clients[0]
|
|
|
|
print(client.name)
|
|
|
|
assert client.name == "hello world"
|
|
|
|
assert client.ipaddr == "10.0.0.5"
|
|
|
|
assert client.secret == "cr4bj0oz"
|