Skip to content
Open
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
1 change: 0 additions & 1 deletion tests/utils/autotailor_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notchecked"]'
assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4" and @role="unchecked"]'


# select additional rule R3; the customized profile will have a special profile ID
customized_profile="xccdf_com.pink.elephant_profile_pineapple"
python3 $autotailor --new-profile-id $customized_profile --id-namespace "com.example.www" --select R3 $ds $original_profile > $tailoring
Expand Down Expand Up @@ -114,7 +113,7 @@
assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notselected"]'

# use JSON tailoring
python3 $autotailor $ds --id-namespace "com.example.www" --json-tailoring $json_tailoring > $tailoring

Check warning on line 116 in tests/utils/autotailor_integration_test.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of using the literal 'com.example.www' 11 times.

See more on https://sonarcloud.io/project/issues?id=OpenSCAP_openscap&issues=AZ1OMvWzpxBzxuHIhcFB&open=AZ1OMvWzpxBzxuHIhcFB&pullRequest=2330
$OSCAP xccdf eval --profile JSON_P1 --progress --tailoring-file $tailoring --results $result $ds
assert_exists 1 '/Benchmark/TestResult/set-value[@idref="xccdf_com.example.www_value_V1" and text()="New Value"]'
assert_exists 1 '/Benchmark/TestResult/set-value[@idref="xccdf_com.example.www_value_V2" and text()="Some Value"]'
Expand Down
12 changes: 12 additions & 0 deletions tests/utils/custom_no_ids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": [
{
"title": "JSON Tailored Profile P11",
"rules": {
"R3": {
"evaluate": true
}
}
}
]
}
14 changes: 14 additions & 0 deletions tests/utils/test_autotailor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import importlib
import pathlib
import json

import pytest

NS = "http://checklists.nist.gov/xccdf/1.2"
Expand Down Expand Up @@ -94,3 +97,14 @@ def test_refine_rule():
"'high'.")
assert t.rule_refinements(fav, "severity") == "high"
assert t.rule_refinements(fav, "role") == "full"

def test_no_id():
p = autotailor.Profile()
profile_dict = None
file_path = pathlib.Path(__file__).parent.joinpath("custom_no_ids.json")
with open(file_path) as fp:
json_data = json.load(fp)
profile_dict = json_data["profiles"][0]
with pytest.raises(ValueError) as e:
p.import_json_tailoring_profile(profile_dict)
assert str(e.value) == "You must define a base_profile_id or an id"
5 changes: 4 additions & 1 deletion utils/autotailor
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ class Tailoring:
profile = ET.SubElement(root, "{%s}Profile" % NS)
profile.set("id", self._full_profile_id(self.profile_id))
profile.set("extends", self._full_profile_id(self.extends))
if self.extends:
profile.set("extends", self._full_profile_id(self.extends))

# Title has to be there due to the schema definition.
title = ET.SubElement(profile, "{%s}title" % NS)
Expand Down Expand Up @@ -315,7 +317,8 @@ class Tailoring:
raise ValueError("JSON Tailoring does not define any profiles.")

self.extends = tailoring["base_profile_id"]

if not tailoring.get("base_profile_id") and not tailoring.get("id"):
raise ValueError("You must define a base_profile_id or an id")
self.profile_id = tailoring.get("id", self.profile_id)
self.profile_title = tailoring.get("title", self.profile_title)

Expand Down
Loading