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

Fix Automatus traceback #11111

Merged
merged 3 commits into from
Sep 13, 2023
Merged

Conversation

jan-cerny
Copy link
Collaborator

@jan-cerny jan-cerny commented Sep 12, 2023

This commit tries to fix a traceback that happens when evaluating a SLE15 data stream on a container back end when the test scenarios require to install a package into the back end.

Resolves:

[jcerny@fedora scap-security-guide{master}]$ tests/test_rule_in_container.sh --no-remove-machine-only --dontclean --logdir logs_bash --remediate-using bash --name ssg_test_suite --datastream build/ssg-sle15-ds.xml audit_rules_login_events
Setting console output to log level INFO
INFO - The base image option has been specified, choosing Podman-based test environment.
INFO - Logging into logs_bash-4/test_suite.log
WARNING - Nothing has been tested!
Traceback (most recent call last):
  File "/home/jcerny/work/git/scap-security-guide/tests/automatus.py", line 511, in <module>
    main()
  File "/home/jcerny/work/git/scap-security-guide/tests/automatus.py", line 507, in main
    options.func(options)
  File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/rule.py", line 689, in perform_rule_check
    checker.test_target()
  File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/oscap.py", line 683, in test_target
    self._test_target()
  File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/rule.py", line 458, in _test_target
    self._prepare_environment(test_content_by_rule_id)
  File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/rule.py", line 275, in _prepare_environment
    self._ensure_package_present_for_all_scenarios(test_content_by_rule_id)
  File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/rule.py", line 265, in _ensure_package_present_for_all_scenarios
    common.install_packages(self.test_env, packages_to_install)
  File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/common.py", line 592, in install_packages
    platform = cpes_to_platform([platform_cpe])
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/common.py", line 623, in cpes_to_platform
    raise ValueError(msg)
ValueError: Unable to deduce a platform from these CPEs: ['cpe:/o:suse:sles:15:sp5']

This commit tries to fix a traceback that happens when evaluating
a SLE15 data stream on a container back end when the test scenarios
require to install a package into the back end.

Resolves:

```
[jcerny@fedora scap-security-guide{master}]$ tests/test_rule_in_container.sh --no-remove-machine-only --dontclean --logdir logs_bash --remediate-using bash --name ssg_test_suite --datastream build/ssg-sle15-ds.xml audit_rules_login_events
Setting console output to log level INFO
INFO - The base image option has been specified, choosing Podman-based test environment.
INFO - Logging into logs_bash-4/test_suite.log
WARNING - Nothing has been tested!
Traceback (most recent call last):
  File "/home/jcerny/work/git/scap-security-guide/tests/automatus.py", line 511, in <module>
    main()
  File "/home/jcerny/work/git/scap-security-guide/tests/automatus.py", line 507, in main
    options.func(options)
  File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/rule.py", line 689, in perform_rule_check
    checker.test_target()
  File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/oscap.py", line 683, in test_target
    self._test_target()
  File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/rule.py", line 458, in _test_target
    self._prepare_environment(test_content_by_rule_id)
  File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/rule.py", line 275, in _prepare_environment
    self._ensure_package_present_for_all_scenarios(test_content_by_rule_id)
  File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/rule.py", line 265, in _ensure_package_present_for_all_scenarios
    common.install_packages(self.test_env, packages_to_install)
  File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/common.py", line 592, in install_packages
    platform = cpes_to_platform([platform_cpe])
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/common.py", line 623, in cpes_to_platform
    raise ValueError(msg)
ValueError: Unable to deduce a platform from these CPEs: ['cpe:/o:suse:sles:15:sp5']
```
@jan-cerny jan-cerny added Test Suite Update in Test Suite. SLES SUSE Linux Enterprise Server product related. labels Sep 12, 2023
@jan-cerny jan-cerny added this to the 0.1.70 milestone Sep 12, 2023
@github-actions
Copy link

Start a new ephemeral environment with changes proposed in this pull request:

Fedora Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

Refactor the code to have less return statements in a function
and reduce cognitive complexity.
Reduce code complexity
@ggbecker
Copy link
Member

ggbecker commented Sep 12, 2023

I was fixing this as part of an old open pull request: ad31112

But your solution is cleaner and improves the code. I will discard that commit and rebase on top of this when it gets merged.

@codeclimate
Copy link

codeclimate bot commented Sep 12, 2023

Code Climate has analyzed commit 6d0a593 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 53.8% (0.0% change).

View more on Code Climate.

@ggbecker ggbecker merged commit 0cc8001 into ComplianceAsCode:master Sep 13, 2023
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SLES SUSE Linux Enterprise Server product related. Test Suite Update in Test Suite.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants