mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 22:37:29 +00:00
Add OIDC and OAuth2 mutual exclusion test
This commit is contained in:
1 file changed
+46
@@ -0,0 +1,46 @@
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
ROLES_DIR = Path(__file__).resolve().parent.parent.parent / "roles"
|
||||
|
||||
|
||||
class TestOidcOauth2MutualExclusion(unittest.TestCase):
|
||||
def test_oidc_and_oauth2_are_not_enabled_at_the_same_time(self):
|
||||
failures = []
|
||||
|
||||
for role_path in sorted(ROLES_DIR.iterdir()):
|
||||
config_file = role_path / "config" / "main.yml"
|
||||
if not config_file.exists():
|
||||
continue
|
||||
|
||||
try:
|
||||
with config_file.open("r", encoding="utf-8") as handle:
|
||||
data = yaml.safe_load(handle) or {}
|
||||
except yaml.YAMLError as error:
|
||||
failures.append(f"{config_file}: failed to parse YAML ({error})")
|
||||
continue
|
||||
|
||||
services = data.get("compose", {}).get("services", {})
|
||||
oidc_enabled = services.get("oidc", {}).get("enabled") is True
|
||||
oauth2_enabled = services.get("oauth2", {}).get("enabled") is True
|
||||
|
||||
if oidc_enabled and oauth2_enabled:
|
||||
failures.append(
|
||||
f"{config_file}: compose.services.oidc.enabled and "
|
||||
"compose.services.oauth2.enabled are both true. "
|
||||
"Enable only one of them, because using both at the same time is redundant."
|
||||
)
|
||||
|
||||
if failures:
|
||||
self.fail(
|
||||
"OIDC and OAuth2 must not be enabled at the same time in role configs. "
|
||||
"Enable only one of them, because using both is redundant.\n\n"
|
||||
+ "\n".join(failures)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user