@@ -224,7 +224,7 @@ def test_scan_text():
224224 [
225225 "4916-6734-7572-5015 is my credit card number, 489-36-8350 ssn"
226226 ],
227- "config " :
227+ "policy " :
228228 {
229229 "detectionRules" :
230230 [
@@ -332,6 +332,90 @@ def test_scan_text():
332332 assert len (redactions ) == 1
333333 assert redactions [0 ] == "491👀-👀👀👀👀-👀👀👀👀-👀👀👀👀 is my credit card number, [REDACTED] ssn"
334334
335+ @responses .activate
336+ def test_scan_text_with_policies ():
337+ nightfall = Nightfall ("NF-NOT_REAL" )
338+ responses .add (responses .POST , 'https://api.nightfall.ai/v3/scan' ,
339+ json = {
340+ "findings" :
341+ [
342+ [
343+ {
344+ "finding" : "4916-6734-7572-5015" ,
345+ "redactedFinding" : "491👀-👀👀👀👀-👀👀👀👀-👀👀👀👀" ,
346+ "afterContext" : " is my cre" ,
347+ "detector" :
348+ {
349+ "name" : "Credit Card Number" ,
350+ "uuid" : "74c1815e-c0c3-4df5-8b1e-6cf98864a454"
351+ },
352+ "confidence" : "VERY_LIKELY" ,
353+ "location" :
354+ {
355+ "byteRange" :
356+ {
357+ "start" : 0 ,
358+ "end" : 19
359+ },
360+ "codepointRange" :
361+ {
362+ "start" : 0 ,
363+ "end" : 19
364+ }
365+ },
366+ "redactedLocation" :
367+ {
368+ "byteRange" :
369+ {
370+ "start" : 0 ,
371+ "end" : 19
372+ },
373+ "codepointRange" :
374+ {
375+ "start" : 0 ,
376+ "end" : 19
377+ }
378+ },
379+ "matchedDetectionRuleUUIDs" :
380+ ["0d8efd7b-b87a-478b-984e-9cf5534a46bc" ],
381+ "matchedDetectionRules" :
382+ []
383+ },
384+ ]
385+ ],
386+ "redactedPayload" :
387+ [
388+ "491👀-👀👀👀👀-👀👀👀👀-👀👀👀👀 is my credit card number, [REDACTED] ssn"
389+ ]
390+ })
391+ result , redactions = nightfall .scan_text_with_policies (
392+ ["4916-6734-7572-5015 is my credit card number, 489-36-8350 ssn" ],
393+ ["2388f83f-cd31-4689-971b-4ee94f798281" ]
394+ )
395+
396+ assert len (responses .calls ) == 1
397+ assert responses .calls [0 ].request .headers .get ("Authorization" ) == "Bearer NF-NOT_REAL"
398+ assert json .loads (responses .calls [0 ].request .body ) == {
399+ "payload" :
400+ [
401+ "4916-6734-7572-5015 is my credit card number, 489-36-8350 ssn"
402+ ],
403+ "policyUUIDs" : ["2388f83f-cd31-4689-971b-4ee94f798281" ]
404+ }
405+
406+ assert len (result ) == 1
407+ assert len (result [0 ]) == 1
408+ assert result [0 ][0 ] == Finding (
409+ "4916-6734-7572-5015" ,
410+ '491👀-👀👀👀👀-👀👀👀👀-👀👀👀👀' ,
411+ None , " is my cre" ,
412+ "Credit Card Number" ,
413+ result [0 ][0 ].detector_uuid ,
414+ Confidence .VERY_LIKELY ,
415+ Range (0 , 19 ), Range (0 , 19 ), "" ,
416+ ["0d8efd7b-b87a-478b-984e-9cf5534a46bc" ], [])
417+ assert len (redactions ) == 1
418+ assert redactions [0 ] == "491👀-👀👀👀👀-👀👀👀👀-👀👀👀👀 is my credit card number, [REDACTED] ssn"
335419
336420def test_scan_text_no_detection_rules ():
337421 nightfall = Nightfall ("NF-NOT_REAL" )
0 commit comments