diff --git a/tests/integration/test_oidc_oauth2_mutual_exclusive.py b/tests/integration/test_oidc_oauth2_mutual_exclusive.py new file mode 100644 index 0000000000..0276e7295d --- /dev/null +++ b/tests/integration/test_oidc_oauth2_mutual_exclusive.py @@ -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()