-
Notifications
You must be signed in to change notification settings - Fork 706
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12059 from Mab879/validate_automatus_metadata
Validate Automatus Metadata
- Loading branch information
Showing
5 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...hysical/screen_locking/smart_card_login/smartcard_configure_crl/tests/missing_crl.fail.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
linux_os/guide/system/network/network-ufw/check_ufw_active/tests/correct.pass.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# package = ufw | ||
# packages = ufw | ||
|
||
systemctl enable --now ufw | ||
ufw allow ssh | ||
|
2 changes: 1 addition & 1 deletion
2
linux_os/guide/system/network/network-ufw/check_ufw_active/tests/incorrect.fail.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# package = ufw | ||
# packages = ufw | ||
# remediation = none | ||
|
||
systemctl enable --now ufw | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/python3 | ||
|
||
import argparse | ||
import os | ||
import glob | ||
import sys | ||
|
||
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'] | ||
|
||
|
||
def _parse_args() -> argparse.Namespace: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-r", "--root", required=False, default=SSG_ROOT, | ||
help="Root directory of the project") | ||
return parser.parse_args() | ||
|
||
|
||
def get_files(root: str): | ||
result = glob.glob("linux_os/**/tests/*.sh", recursive=True, root_dir=root) | ||
return result | ||
|
||
|
||
def _test_filename_valid(test_file: str) -> bool: | ||
filename = os.path.basename(test_file) | ||
end_state = filename.split('.') | ||
if len(end_state) == 3 and end_state[1] not in VALID_STATES: | ||
print(f"Invalid expected state '{end_state[1]}' 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) | ||
with open(full_path, "r") as f: | ||
for line in f: | ||
if not line.startswith("#"): | ||
break | ||
line = line.removeprefix('#') | ||
line = line.strip() | ||
parts = line.split('=') | ||
if len(parts) != 2: | ||
continue | ||
param_name = parts[0].strip() | ||
if param_name not in VALID_FIELDS: | ||
print(f"Invalid field '{param_name}' in {test_file}", file=sys.stderr) | ||
return False | ||
return True | ||
|
||
|
||
def main() -> int: | ||
args = _parse_args() | ||
test_files = get_files(args.root) | ||
return_value = 0 | ||
for test_file in test_files: | ||
if not _test_filename_valid(test_file): | ||
return_value = 1 | ||
if not _has_invalid_param(args.root, test_file): | ||
return_value = 1 | ||
return return_value | ||
|
||
|
||
if __name__ == "__main__": | ||
raise SystemExit(main()) |