File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -83,7 +83,6 @@ assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www
8383assert_exists 1 ' /Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notchecked"]'
8484assert_exists 1 ' /Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4" and @role="unchecked"]'
8585
86-
8786# select additional rule R3; the customized profile will have a special profile ID
8887customized_profile=" xccdf_com.pink.elephant_profile_pineapple"
8988python3 $autotailor --new-profile-id $customized_profile --id-namespace " com.example.www" --select R3 $ds $original_profile > $tailoring
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,14 @@ def test_refine_rule():
9497 "'high'." )
9598 assert t .rule_refinements (fav , "severity" ) == "high"
9699 assert t .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+ json_data = json .load (fp )
107+ profile_dict = json_data ["profiles" ][0 ]
108+ with pytest .raises (ValueError ) as e :
109+ p .import_json_tailoring_profile (profile_dict )
110+ assert str (e .value ) == "You must define a base_profile_id or an id"
Original file line number Diff line number Diff line change @@ -254,6 +254,8 @@ class Tailoring:
254254 profile = ET .SubElement (root , "{%s}Profile" % NS )
255255 profile .set ("id" , self ._full_profile_id (self .profile_id ))
256256 profile .set ("extends" , self ._full_profile_id (self .extends ))
257+ if self .extends :
258+ profile .set ("extends" , self ._full_profile_id (self .extends ))
257259
258260 # Title has to be there due to the schema definition.
259261 title = ET .SubElement (profile , "{%s}title" % NS )
@@ -315,7 +317,8 @@ class Tailoring:
315317 raise ValueError ("JSON Tailoring does not define any profiles." )
316318
317319 self .extends = tailoring ["base_profile_id" ]
318-
320+ if not tailoring .get ("base_profile_id" ) and not tailoring .get ("id" ):
321+ raise ValueError ("You must define a base_profile_id or an id" )
319322 self .profile_id = tailoring .get ("id" , self .profile_id )
320323 self .profile_title = tailoring .get ("title" , self .profile_title )
321324
You can’t perform that action at this time.
0 commit comments