22import pytest
33
44from nightfall .api import Nightfall
5- from nightfall .detection_rules import DetectionRule , Detector , LogicalOp , Confidence , ExclusionRule
5+ from nightfall .detection_rules import DetectionRule , Detector , LogicalOp , Confidence , ExclusionRule , ContextRule , \
6+ WordList , MatchType , RedactionConfig , MaskConfig , Regex
67from nightfall .findings import Finding , Range
78
89
@@ -12,22 +13,38 @@ def nightfall():
1213
1314
1415def test_scan_text_detection_rules_v3 (nightfall ):
15- result , _ = nightfall .scan_text (
16+ result , redactions = nightfall .scan_text (
1617 ["4916-6734-7572-5015 is my credit card number" ],
1718 detection_rules = [DetectionRule (logical_op = LogicalOp .ANY , detectors = [
18- Detector (min_confidence = Confidence .LIKELY , min_num_findings = 1 ,
19- display_name = "Credit Card Number" , nightfall_detector = "CREDIT_CARD_NUMBER" )])]
19+ Detector (min_confidence = Confidence .LIKELY ,
20+ min_num_findings = 1 ,
21+ display_name = "Credit Card Number" ,
22+ nightfall_detector = "CREDIT_CARD_NUMBER" ,
23+ context_rules = [ContextRule (regex = Regex ("fake regex" , is_case_sensitive = False ),
24+ window_before = 10 , window_after = 10 ,
25+ fixed_confidence = Confidence .VERY_UNLIKELY )],
26+ exclusion_rules = [ExclusionRule (MatchType .FULL ,
27+ word_list = WordList (["never" , "match" ],
28+ is_case_sensitive = True ))],
29+ redaction_config = RedactionConfig (remove_finding = False ,
30+ mask_config = MaskConfig (masking_char = '👀' ,
31+ num_chars_to_leave_unmasked = 3 ,
32+ chars_to_ignore = ["-" ]))
33+ )])]
2034 )
2135
2236 assert len (result ) == 1
2337 assert result [0 ][0 ] == Finding (
2438 "4916-6734-7572-5015" ,
25- None , None , None ,
39+ '491👀-👀👀👀👀-👀👀👀👀-👀👀👀👀' ,
40+ None , None ,
2641 "Credit Card Number" ,
2742 result [0 ][0 ].detector_uuid ,
2843 Confidence .VERY_LIKELY ,
2944 Range (0 , 19 ), Range (0 , 19 ),
3045 [], ["Inline Detection Rule #1" ])
46+ assert len (redactions ) == 1
47+ assert redactions [0 ] == "491👀-👀👀👀👀-👀👀👀👀-👀👀👀👀 is my credit card number"
3148
3249
3350@pytest .mark .filetest
0 commit comments