diff --git a/src/mapex/write_parsed_mappings.py b/src/mapex/write_parsed_mappings.py index f759434e..eb495b24 100644 --- a/src/mapex/write_parsed_mappings.py +++ b/src/mapex/write_parsed_mappings.py @@ -361,7 +361,7 @@ def load_attack_json(parsed_mappings): def get_techniques_dict(mapping_objects): techniques_dict = {} for mapping in mapping_objects: - tehchnique_id = mapping["attack_object_id"] + technique_id = mapping["attack_object_id"] capability_id = mapping["capability_id"] # define metadata @@ -380,25 +380,30 @@ def get_techniques_dict(mapping_objects): if mapping.get("comments"): metadata.append({"name": "comment", "value": mapping["comments"]}) - if techniques_dict.get(tehchnique_id): - # add capability information to technique it is mapped to - techniques_dict[tehchnique_id]["capability_ids"].append(capability_id) - metadata_info = [{"name": "control", "value": mapping["capability_id"]}] + if techniques_dict.get(technique_id) is None: + techniques_dict[technique_id] = { + "capability_ids": {capability_id}, + "metadata": [], + } + + technique = techniques_dict[technique_id] + + # Add Capability ID + technique["capability_ids"].add(capability_id) + + # Add Metadata + metadata_info = [] + if len(metadata) > 0: + metadata_info.extend( + [ + {"divider": True}, + {"name": "control", "value": mapping["capability_id"]}, + ] + ) metadata_info.extend(metadata) - metadata_info.append({"divider": True}) - if "metadata" in techniques_dict[tehchnique_id]: - techniques_dict[tehchnique_id]["metadata"].extend(metadata_info) - else: - techniques_dict[tehchnique_id]["metadata"] = metadata_info - else: - # add capability information to technique it is mapped to - techniques_dict[tehchnique_id] = {"capability_ids": [capability_id]} - techniques_dict[tehchnique_id]["metadata"] = [ - {"name": "control", "value": mapping["capability_id"]} - ] - techniques_dict[tehchnique_id]["metadata"].extend(metadata) - techniques_dict[tehchnique_id]["metadata"].append({"divider": True}) + # No need to check if metadata_info is empty + technique["metadata"].extend(metadata_info) return techniques_dict @@ -434,13 +439,14 @@ def create_layer(techniques_dict, layer_title, domain, attack_version): related_controls_string = "" if len(capability_ids): - related_controls_string = ", ".join(capability_ids) + # formats ids in a bulleted list + related_controls_string = "\u2022" + "\n\u2022".join(capability_ids) layer["techniques"].append( { "techniqueID": technique, "score": len(techniques_dict[technique]["capability_ids"]), - "comment": f"Related to {related_controls_string}", + "comment": f" Related to: \n {related_controls_string}", "metadata": techniques_dict[technique].get("metadata", []), } ) diff --git a/tests/expected_results/expected_results_navigator_layer.py b/tests/expected_results/expected_results_navigator_layer.py index 07ec178f..deff3fbe 100644 --- a/tests/expected_results/expected_results_navigator_layer.py +++ b/tests/expected_results/expected_results_navigator_layer.py @@ -8,14 +8,14 @@ { "techniqueID": "T1137", "score": 1, - "comment": "Related to AC-10", - "metadata": [{"name": "control", "value": "AC-10"}, {"divider": True}], + "comment": " Related to: \n •AC-10", + "metadata": [], }, { "techniqueID": "T1137.002", "score": 1, - "comment": "Related to AC-10", - "metadata": [{"name": "control", "value": "AC-10"}, {"divider": True}], + "comment": " Related to: \n •AC-10", + "metadata": [], }, ], "gradient": {"colors": ["#ffe766", "#ffaf66"], "minValue": 1, "maxValue": 1},