Field baseline deviations now show distinct Mark expected, Mark false positive, and Mark confirmed
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -65,6 +66,39 @@ class RecommendationTests(unittest.TestCase):
|
||||
|
||||
self.assertEqual(client._select_provider(), "virustotal")
|
||||
|
||||
def test_successful_lookup_is_reused_from_cache(self):
|
||||
with tempfile.TemporaryDirectory() as directory, patch.dict(
|
||||
os.environ,
|
||||
{"FGAI_THREAT_INTEL": "1", "VIRUSTOTAL_API_KEY": "test", "FGAI_THREAT_INTEL_PROVIDER": "virustotal"},
|
||||
clear=True,
|
||||
):
|
||||
client = ThreatIntelClient(cache_file=f"{directory}/intel.json")
|
||||
with patch.object(client, "_lookup_virustotal_ip", return_value={"ip": "8.8.8.8", "provider": "virustotal", "status": "ok", "score": 0}) as lookup:
|
||||
client.lookup_ip("8.8.8.8")
|
||||
client.lookup_ip("8.8.8.8")
|
||||
|
||||
self.assertEqual(lookup.call_count, 1)
|
||||
self.assertEqual(client.status()["requests_today"], 1)
|
||||
|
||||
def test_daily_limit_prevents_new_external_lookups(self):
|
||||
with tempfile.TemporaryDirectory() as directory, patch.dict(
|
||||
os.environ,
|
||||
{
|
||||
"FGAI_THREAT_INTEL": "1",
|
||||
"VIRUSTOTAL_API_KEY": "test",
|
||||
"FGAI_THREAT_INTEL_PROVIDER": "virustotal",
|
||||
"FGAI_THREAT_INTEL_DAILY_LIMIT": "1",
|
||||
},
|
||||
clear=True,
|
||||
):
|
||||
client = ThreatIntelClient(cache_file=f"{directory}/intel.json")
|
||||
with patch.object(client, "_lookup_virustotal_ip", return_value={"ip": "8.8.8.8", "provider": "virustotal", "status": "ok", "score": 0}) as lookup:
|
||||
client.lookup_ip("8.8.8.8")
|
||||
limited = client.lookup_ip("1.1.1.1")
|
||||
|
||||
self.assertEqual(lookup.call_count, 1)
|
||||
self.assertEqual(limited["status"], "daily_limit_reached")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user