From 69aa0a6d4cab6abc91c1b1ea14dd1771ed4e3419 Mon Sep 17 00:00:00 2001 From: Dakes Date: Tue, 18 Jun 2024 15:23:13 +0200 Subject: [PATCH 1/3] Fix cvss and response overwrite --- pytm/pytm.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pytm/pytm.py b/pytm/pytm.py index 3bd7333..f9b7bc3 100644 --- a/pytm/pytm.py +++ b/pytm/pytm.py @@ -2024,6 +2024,8 @@ def encode_threat_data(obj): "threat_id", "references", "condition", + "cvss", + "response", ] if type(obj) is Finding or (len(obj) != 0 and type(obj[0]) is Finding): @@ -2039,7 +2041,8 @@ def encode_threat_data(obj): # ignore missing attributes, since this can be called # on both a Finding and a Threat continue - setattr(t, a, html.escape(v)) + if v is not None: + setattr(t, a, html.escape(v)) encoded_threat_data.append(t) From 4feea397c20bb6efb2b267a6ad5d7835487213d7 Mon Sep 17 00:00:00 2001 From: Dakes Date: Fri, 21 Jun 2024 12:18:46 +0200 Subject: [PATCH 2/3] Add test for encode_threat_data and cvss override --- tests/test_private_func.py | 40 ++++++++++++++++++++++++++++++++++++++ tests/test_pytmfunc.py | 18 +++++++++++++---- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/tests/test_private_func.py b/tests/test_private_func.py index 3e9aea2..4ce0816 100644 --- a/tests/test_private_func.py +++ b/tests/test_private_func.py @@ -10,10 +10,12 @@ Dataflow, Datastore, DatastoreType, + Finding, Process, Server, Threat, UIError, + encode_threat_data, ) @@ -245,3 +247,41 @@ def test_defaults(self): case["condition"], ), ) + + +class TestFunction(unittest.TestCase): + def test_encode_threat_data(self): + findings = [ + Finding( + description="A test description", + severity="High", + id="1", + threat_id="INP01", + cvss="9.876", + response="A test response", + ), + Finding( + description="An escape test