File tree Expand file tree Collapse file tree 5 files changed +49
-5
lines changed
Expand file tree Collapse file tree 5 files changed +49
-5
lines changed Original file line number Diff line number Diff line change @@ -136,4 +136,4 @@ assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www
136136# use JSON tailoring (P11) with a new profile from the command line
137137python3 $autotailor --id-namespace " com.example.www" --json-tailoring $json_tailoring --tailored-profile-id=CMDL_P --select R3 $ds $original_profile > $tailoring
138138$OSCAP xccdf eval --profile CMDL_P --progress --tailoring-file $tailoring --results $result $ds
139- assert_exists 1 ' /Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="pass"]'
139+ assert_exists 1 ' /Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="pass"]'
Original file line number Diff line number Diff line change 4040 "evaluate" : true
4141 }
4242 }
43+ },
44+ {
45+ "id" : " JSON_P12" ,
46+ "title" : " JSON Custom profile" ,
47+ "rules" : {
48+ "R3" : {
49+ "evaluate" : true
50+ }
51+ }
52+ },
53+ {
54+ "title" : " JSON Custom profile with no given id" ,
55+ "base_profile_id" : " P1" ,
56+ "rules" : {
57+ "R3" : {
58+ "evaluate" : true
59+ }
60+ }
4361 }
4462 ]
4563}
Original file line number Diff line number Diff line change 1+ {
2+ "profiles" : [
3+ {
4+ "title" : " JSON Tailored Profile P11" ,
5+ "rules" : {
6+ "R3" : {
7+ "evaluate" : true
8+ }
9+ }
10+ }
11+ ]
12+ }
Original file line number Diff line number Diff line change 11import importlib
2+ import pathlib
3+ import json
4+
25import pytest
36
47NS = "http://checklists.nist.gov/xccdf/1.2"
@@ -94,3 +97,12 @@ def test_refine_rule():
9497 "'high'." )
9598 assert p .rule_refinements (fav , "severity" ) == "high"
9699 assert p .rule_refinements (fav , "role" ) == "full"
100+
101+ def test_no_id ():
102+ p = autotailor .Profile ()
103+ profile_dict = None
104+ file_path = pathlib .Path (__file__ ).parent .joinpath ("custom_no_ids.json" )
105+ with open (file_path ) as fp :
106+ profile_dict = json .load (fp )
107+ with pytest .raises (ValueError ):
108+ p .import_json_tailoring_profile (profile_dict )
Original file line number Diff line number Diff line change @@ -268,7 +268,8 @@ class Profile:
268268 def to_xml (self , root ):
269269 profile = ET .SubElement (root , "{%s}Profile" % NS )
270270 profile .set ("id" , self ._full_profile_id (self .profile_id ))
271- profile .set ("extends" , self ._full_profile_id (self .extends ))
271+ if self .extends :
272+ profile .set ("extends" , self ._full_profile_id (self .extends ))
272273
273274 # Title has to be there due to the schema definition.
274275 title = ET .SubElement (profile , "{%s}title" % NS )
@@ -285,9 +286,10 @@ class Profile:
285286 self .value_refinements_to_xml (profile )
286287
287288 def import_json_tailoring_profile (self , profile_dict ):
288- self .extends = profile_dict ["base_profile_id" ]
289-
290- self .profile_id = profile_dict .get ("id" , self .profile_id )
289+ if not profile_dict .get ("base_profile_id" ) and not profile_dict .get ("id" ):
290+ raise ValueError ("You must define a base_profile_id or an id" )
291+ self .extends = profile_dict .get ("base_profile_id" )
292+ self .profile_id = profile_dict .get ("id" )
291293 self .profile_title = profile_dict .get ("title" , self .profile_title )
292294
293295 self ._import_groups_from_tailoring (profile_dict )
You can’t perform that action at this time.
0 commit comments