Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that platforms is valid in Automatus tests #12505

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# platform = multi_platform_slmicro5
# platform = multi_platform_slmicro

cat >/etc/pam.d/common-account <<CAPTC
account [success=1 new_authtok_reqd=done default=ignore] pam_unix.so
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# platform = multi_platform_slmicro5
# platform = multi_platform_slmicro

cat >/etc/pam.d/common-account <<CAPTC
account [success=1 new_authtok_reqd=done default=ignore] pam_unix.so
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# platform = multi_platform_slmicro5
# platform = multi_platform_slmicro

cat >/etc/pam.d/common-account <<CAPTC
account [success=1 new_authtok_reqd=done default=ignore] pam_unix.so
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# packages = policycoreutils-python-utils
# platform = multi_platform_slmicro5
# platform = multi_platform_slmicro

semanage fcontext -m -t faillog_t "/var/log/tallylog"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# packages = policycoreutils-python-utils
# platform = multi_platform_slmicro5
# platform = multi_platform_slmicro

semanage fcontext -m -t tmp_t "/var/log/tallylog"
restorecon -R -v "/var/log/tallylog"
22 changes: 20 additions & 2 deletions tests/validate_automatus_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
import glob
import sys

import ssg.constants

SSG_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
VALID_FIELDS = ['check', 'packages', 'platform', 'profiles', 'remediation', 'templates',
'variables']
VALID_STATES = ['pass', 'fail', 'notapplicable']

VALID_PLATFORMS = (list(ssg.constants.FULL_NAME_TO_PRODUCT_MAPPING.keys())
+ list(ssg.constants.MULTI_PLATFORM_MAPPING.keys())
+ ['multi_platform_all'])


def _parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
Expand All @@ -32,8 +38,17 @@ def _test_filename_valid(test_file: str) -> bool:
return True


def _validate_platform(param_value, test_file):
for platform in param_value.split(","):
if platform.strip() not in VALID_PLATFORMS:
print(f"Invalid platform '{platform}' in {test_file}", file=sys.stderr)
return False
return True


def _has_invalid_param(root: str, test_file: str) -> bool:
full_path = os.path.join(root, test_file)
has_no_errors = True
with open(full_path, "r") as f:
for line in f:
if not line.startswith("#"):
Expand All @@ -44,10 +59,13 @@ def _has_invalid_param(root: str, test_file: str) -> bool:
if len(parts) != 2:
continue
param_name = parts[0].strip()
param_value = parts[1].strip()
if param_name == 'platform':
has_no_errors = _validate_platform(param_value, test_file)
if param_name not in VALID_FIELDS:
print(f"Invalid field '{param_name}' in {test_file}", file=sys.stderr)
return False
return True
has_no_errors = False
return has_no_errors


def main() -> int:
Expand Down
Loading