Skip to content

Commit 62333c0

Browse files
authored
Add commit hash to finding. (#31)
Part of PLAT-1576
1 parent dee576a commit 62333c0

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

nightfall/findings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Finding:
3131
byte_range (Range): The byte range in which a finding was detected within the item.
3232
codepoint_range (Range): The codepoint range in which a finding was detected within the item. This differs
3333
from byte range since a codepoint may contain multiple bytes.
34+
commit_hash (str): The hash of the commit in which the finding was detected, if known.
3435
matched_detection_rule_uuids (List[str]): The list of detection rule UUIDs that contained a detector that
3536
triggered a match.
3637
matched_detection_rules (List[str]): The list of inline detection rules that contained a detector that triggered
@@ -45,6 +46,7 @@ class Finding:
4546
confidence: Confidence
4647
byte_range: Range
4748
codepoint_range: Range
49+
commit_hash: str
4850
matched_detection_rule_uuids: List[str]
4951
matched_detection_rules: List[str]
5052

@@ -60,6 +62,7 @@ def from_dict(cls, resp: dict) -> "Finding":
6062
Confidence[resp["confidence"]],
6163
Range(resp["location"]["byteRange"]["start"], resp["location"]["byteRange"]["end"]),
6264
Range(resp["location"]["codepointRange"]["start"], resp["location"]["codepointRange"]["end"]),
65+
resp["location"].get("commitHash", ""),
6366
resp["matchedDetectionRuleUUIDs"],
6467
resp["matchedDetectionRules"]
6568
)

tests/test_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def finding_orderer(f):
5757
"Credit Card Number",
5858
result[0][0].detector_uuid,
5959
Confidence.VERY_LIKELY,
60-
Range(0, 19), Range(0, 19),
60+
Range(0, 19), Range(0, 19), "",
6161
[], ["Inline Detection Rule #1"])
6262
assert result[0][1] == Finding(
6363
"489-36-8350",
@@ -66,7 +66,7 @@ def finding_orderer(f):
6666
"",
6767
result[0][1].detector_uuid,
6868
Confidence.VERY_LIKELY,
69-
Range(46, 57), Range(46, 57),
69+
Range(46, 57), Range(46, 57), "",
7070
[], ["Inline Detection Rule #1"])
7171
assert len(redactions) == 1
7272
assert redactions[0] == "491👀-👀👀👀👀-👀👀👀👀-👀👀👀👀 is my credit card number, [REDACTED] ssn"
@@ -318,7 +318,7 @@ def test_scan_text():
318318
"Credit Card Number",
319319
result[0][0].detector_uuid,
320320
Confidence.VERY_LIKELY,
321-
Range(0, 19), Range(0, 19),
321+
Range(0, 19), Range(0, 19), "",
322322
[], ["Inline Detection Rule #1"])
323323
assert result[0][1] == Finding(
324324
"489-36-8350",
@@ -327,7 +327,7 @@ def test_scan_text():
327327
"",
328328
result[0][1].detector_uuid,
329329
Confidence.VERY_LIKELY,
330-
Range(46, 57), Range(46, 57),
330+
Range(46, 57), Range(46, 57), "",
331331
[], ["Inline Detection Rule #1"])
332332
assert len(redactions) == 1
333333
assert redactions[0] == "491👀-👀👀👀👀-👀👀👀👀-👀👀👀👀 is my credit card number, [REDACTED] ssn"

0 commit comments

Comments
 (0)