mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 23:08:06 +02:00
Optimized LDAP implementation for Snipe-IT and implemented Mobilizon draft
This commit is contained in:
@@ -27,6 +27,8 @@ class TestDockerRoleImagesConfiguration(unittest.TestCase):
|
||||
|
||||
try:
|
||||
config = yaml.safe_load(cfg_file.read_text("utf-8")) or {}
|
||||
main_file = role_path / "vars" / "main.yml"
|
||||
main = yaml.safe_load(main_file.read_text("utf-8")) or {}
|
||||
except yaml.YAMLError as e:
|
||||
errors.append(f"{role_path.name}: YAML parse error: {e}")
|
||||
continue
|
||||
@@ -50,20 +52,33 @@ class TestDockerRoleImagesConfiguration(unittest.TestCase):
|
||||
r'image:\s*["\']\{\{\s*applications\[application_id\]\.images\.' + re.escape(key) + r'\s*\}\}["\']'
|
||||
)
|
||||
|
||||
found = False
|
||||
# innerhalb Deines Loops
|
||||
pattern2 = (
|
||||
r'image:\s*["\']\{\{\s*' # image: "{{
|
||||
r'applications\[\s*application_id\s*\]\.images' # applications[ application_id ].images
|
||||
r'\[\s*application_id\s*\]\s*' # [ application_id ]
|
||||
r'\}\}["\']' # }}" oder }}"
|
||||
)
|
||||
|
||||
|
||||
for tmpl_file in [
|
||||
role_path / "templates" / "docker-compose.yml.j2",
|
||||
role_path / "templates" / "env.j2"
|
||||
role_path / "templates" / "env.j2",
|
||||
]:
|
||||
if tmpl_file.exists():
|
||||
content = tmpl_file.read_text("utf-8")
|
||||
if re.search(pattern, content):
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
if not tmpl_file.exists():
|
||||
continue
|
||||
content = tmpl_file.read_text("utf-8")
|
||||
if re.search(pattern, content):
|
||||
break
|
||||
if key == main.get('application_id') and re.search(pattern2, content):
|
||||
break
|
||||
else:
|
||||
# Dieser Block wird nur ausgeführt, wenn kein `break` ausgelöst wurde
|
||||
errors.append(
|
||||
f"{role_path.name}: image key '{key}' is not referenced as "
|
||||
f'image: \"{{{{ applications[application_id].images.{key} }}}}\" in docker-compose.yml.j2 or env.j2'
|
||||
f"image: \"{{{{ applications[application_id].images.{key} }}}}\" or "
|
||||
f"\"{{{{ applications[application_id].images[application_id] }}}}\" "
|
||||
"in docker-compose.yml.j2 or env.j2"
|
||||
)
|
||||
|
||||
|
||||
|
58
tests/integration/test_oauth2_proxy_ports.py
Normal file
58
tests/integration/test_oauth2_proxy_ports.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import unittest
|
||||
import yaml
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class TestOAuth2ProxyPorts(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
# Set up root paths and load oauth2_proxy ports mapping
|
||||
cls.ROOT = Path(__file__).parent.parent.parent.resolve()
|
||||
cls.PORTS_FILE = cls.ROOT / 'group_vars' / 'all' / '08_ports.yml'
|
||||
with cls.PORTS_FILE.open() as f:
|
||||
data = yaml.safe_load(f)
|
||||
cls.oauth2_ports = (
|
||||
data.get('ports', {})
|
||||
.get('localhost', {})
|
||||
.get('oauth2_proxy', {})
|
||||
)
|
||||
|
||||
def test_oauth2_feature_has_port_mapping(self):
|
||||
# Iterate over each role directory
|
||||
roles_dir = self.ROOT / 'roles'
|
||||
for role_path in roles_dir.iterdir():
|
||||
if not role_path.is_dir():
|
||||
continue
|
||||
with self.subTest(role=role_path.name):
|
||||
# Check for configuration.yml
|
||||
config_file = role_path / 'vars' / 'configuration.yml'
|
||||
if not config_file.exists():
|
||||
self.skipTest(f"No configuration.yml for role {role_path.name}")
|
||||
|
||||
config = yaml.safe_load(config_file.read_text()) or {}
|
||||
if not config.get('features', {}).get('oauth2', False):
|
||||
self.skipTest(f"OAuth2 not enabled for role {role_path.name}")
|
||||
|
||||
# Load application_id from vars/main.yml
|
||||
main_file = role_path / 'vars' / 'main.yml'
|
||||
if not main_file.exists():
|
||||
self.fail(f"Missing vars/main.yml in role {role_path.name}")
|
||||
main = yaml.safe_load(main_file.read_text()) or {}
|
||||
app_id = main.get('application_id')
|
||||
if not app_id:
|
||||
self.fail(f"application_id not set in {main_file}")
|
||||
|
||||
# Validate oauth2_ports structure
|
||||
self.assertIsInstance(self.oauth2_ports, dict,
|
||||
"oauth2_proxy ports mapping is not a dict")
|
||||
|
||||
# Assert port mapping exists for the application
|
||||
if app_id not in self.oauth2_ports:
|
||||
self.fail(
|
||||
f"Missing oauth2_proxy port mapping for application '{app_id}' "
|
||||
f"in group_vars/all/08_ports.yml"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user