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

Raise exception when parametrized platform receives invalid argument #9996

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
8 changes: 7 additions & 1 deletion ssg/build_cpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@ def create_resolved_cpe_item_for_fact_ref(self, fact_ref):
if not self.versioned:
raise ValueError("CPE entity '{0}' does not support version specifiers: "
"{1}".format(self.id_, fact_ref.cpe_name))
resolved_parameters = self.args[fact_ref.arg]
try:
resolved_parameters = self.args[fact_ref.arg]
except KeyError:
raise KeyError(
"The {0} CPE item does not support the argument {1}. "
"Following arguments are supported: {2}".format(
self.id_, fact_ref.arg, [a for a in self.args.keys()]))
resolved_parameters.update(fact_ref.as_dict())
cpe_item_as_dict = self.represent_as_dict()
cpe_item_as_dict["args"] = None
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/ssg-module/test_build_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ def test_parametrized_platform(product_cpes):
assert cpe_item.title == "Package ntp is installed"
assert cpe_item.check_id == "installed_env_has_ntp_package"

def test_parametrized_platform_with_invalid_argument(product_cpes):
with pytest.raises(KeyError):
platform = ssg.build_yaml.Platform.from_text("package[nonexisting_argument]", product_cpes)


def test_derive_id_from_file_name():
assert ssg.entities.common.derive_id_from_file_name("rule.yml") == "rule"
Expand Down