From 13d96c506d38a57f4835f53a3c43e00906fbdd74 Mon Sep 17 00:00:00 2001 From: Caroline Russell Date: Sun, 4 Aug 2024 21:26:01 -0400 Subject: [PATCH 1/3] Fix html report bug. Signed-off-by: Caroline Russell --- custom_json_diff/bom_diff_template.j2 | 4 ++-- custom_json_diff/custom_diff.py | 5 +++-- custom_json_diff/custom_diff_classes.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/custom_json_diff/bom_diff_template.j2 b/custom_json_diff/bom_diff_template.j2 index 3314d0a..415a92b 100644 --- a/custom_json_diff/bom_diff_template.j2 +++ b/custom_json_diff/bom_diff_template.j2 @@ -96,7 +96,7 @@ {{ bom_1 }} {{ bom_2 }} - {% if not (diff_apps_1 or diff_apps_2 or diff_frameworks_1 or diff_frameworks_2 or diff_lib_1 or diff_lib_2 or diff_other_1 or diff_other_2 or diff_vdrs_1 or diff_vdrs_2) %} + {% if diff_status == 0 %} No differences found. @@ -432,7 +432,7 @@ Components - {% if not (common_apps or common_frameworks or common_lib or common_other) %} + {% if not (common_apps or common_frameworks or common_lib or common_other or common_services or common_deps or common_vdrs) %} No commonalities. diff --git a/custom_json_diff/custom_diff.py b/custom_json_diff/custom_diff.py index 6d83f34..35527b8 100644 --- a/custom_json_diff/custom_diff.py +++ b/custom_json_diff/custom_diff.py @@ -43,7 +43,7 @@ def compare_dicts(options: Options) -> Tuple[int, FlatDicts | BomDicts, FlatDict return 1, json_1_data, json_2_data -def export_html_report(outfile: str, diffs: Dict, j1: BomDicts, j2: BomDicts, options: Options) -> None: +def export_html_report(outfile: str, diffs: Dict, j1: BomDicts, j2: BomDicts, options: Options, status: int) -> None: if options.report_template: template_file = options.report_template else: @@ -92,6 +92,7 @@ def export_html_report(outfile: str, diffs: Dict, j1: BomDicts, j2: BomDicts, op stats=stats_summary, comp_only=options.comp_only, metadata=metadata_results, + diff_status=status, ) with open(outfile, "w", encoding="utf-8") as f: f.write(report_result) @@ -178,7 +179,7 @@ def report_results(status: int, diffs: Dict, options: Options, j1: BomDicts | No return if options.bom_diff: report_file = options.output.replace(".json", "") + ".html" - export_html_report(report_file, diffs, j1, j2, options) # type: ignore + export_html_report(report_file, diffs, j1, j2, options, status) # type: ignore def sort_dict_lists(result: Dict, sort_keys: List[str]) -> Dict: diff --git a/custom_json_diff/custom_diff_classes.py b/custom_json_diff/custom_diff_classes.py index 8dff555..d68ffed 100644 --- a/custom_json_diff/custom_diff_classes.py +++ b/custom_json_diff/custom_diff_classes.py @@ -454,7 +454,7 @@ def compare_date(dt1: str, dt2: str, comparator: str): def compare_vdr_new_versions(vdr_1: BomVdr, vdr_2: BomVdr) -> bool: return all((vdr_1.affects == vdr_2.affects, - compare_date(vdr_1.updated, vdr_2.updated, "<"), + (not vdr_1.updated or compare_date(vdr_1.updated, vdr_2.updated, "<=")), compare_bom_refs(vdr_1.bom_ref, vdr_2.bom_ref))) From 0517dc852968063e530d7458faca70fe59bb4469 Mon Sep 17 00:00:00 2001 From: Caroline Russell Date: Sun, 4 Aug 2024 22:20:45 -0400 Subject: [PATCH 2/3] Add VDR sort fields. Signed-off-by: Caroline Russell --- custom_json_diff/custom_diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_json_diff/custom_diff.py b/custom_json_diff/custom_diff.py index 35527b8..07f3518 100644 --- a/custom_json_diff/custom_diff.py +++ b/custom_json_diff/custom_diff.py @@ -147,7 +147,7 @@ def load_json(json_file: str, options: Options) -> FlatDicts | BomDicts: logger.error("Invalid JSON: %s", json_file) sys.exit(1) if options.bom_diff: - data = sort_dict_lists(data, ["url", "content", "ref", "name", "value"]) + data = sort_dict_lists(data, ["bom-ref", "id", "url", "content", "ref", "name", "value"]) data = filter_dict(data, options).to_dict(unflat=True) return BomDicts(options, json_file, data, {}) return filter_dict(data, options) From a1593d007c8a619844cbae29fe42adbe95579e86 Mon Sep 17 00:00:00 2001 From: Caroline Russell Date: Sun, 4 Aug 2024 22:20:59 -0400 Subject: [PATCH 3/3] Use only date in datetime comparison Signed-off-by: Caroline Russell --- custom_json_diff/custom_diff_classes.py | 6 +++--- pyproject.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_json_diff/custom_diff_classes.py b/custom_json_diff/custom_diff_classes.py index d68ffed..94ef5e8 100644 --- a/custom_json_diff/custom_diff_classes.py +++ b/custom_json_diff/custom_diff_classes.py @@ -432,11 +432,11 @@ def compare_bom_refs(v1: str, v2: str) -> bool: def compare_date(dt1: str, dt2: str, comparator: str): """Compares two dates""" - if dt1 == dt2 or (not dt1 and not dt2): + if not dt1 and not dt2: return True try: - date_1 = datetime.fromisoformat(dt1) - date_2 = datetime.fromisoformat(dt2) + date_1 = datetime.fromisoformat(dt1).date() + date_2 = datetime.fromisoformat(dt2).date() match comparator: case "<": return date_1 < date_2 diff --git a/pyproject.toml b/pyproject.toml index 25c37d3..bcc91fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "custom-json-diff" -version = "1.5.5" +version = "1.5.6" description = "Custom JSON and CycloneDx BOM diffing and comparison tool." authors = [ { name = "Caroline Russell", email = "caroline@appthreat.dev" },