Skip to content

Commit fd5688a

Browse files
committed
ja4db
Signed-off-by: pranjalg1331 <[email protected]>
1 parent ac7d775 commit fd5688a

File tree

15 files changed

+488
-2
lines changed

15 files changed

+488
-2
lines changed

tests/api_app/analyzers_manager/unit_tests/observable_analyzers/base_test_class.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,17 @@ def test_analyzer_on_supported_observables(self):
139139
if self.analyzer_class is None:
140140
self.skipTest("analyzer_class is not set")
141141

142-
config = AnalyzerConfig.objects.get(
142+
configs = AnalyzerConfig.objects.filter(
143143
python_module=self.analyzer_class.python_module
144144
)
145145

146+
if not configs.exists():
147+
self.skipTest(
148+
f"No AnalyzerConfig found for {self.analyzer_class.python_module}"
149+
)
150+
151+
config = configs.first()
152+
146153
for observable_type in config.observable_supported:
147154
if observable_type == "generic":
148155
continue
@@ -179,10 +186,17 @@ def test_analyzer_error_handling(self):
179186
if self.analyzer_class is None:
180187
self.skipTest("analyzer_class is not set")
181188

182-
config = AnalyzerConfig.objects.get(
189+
configs = AnalyzerConfig.objects.filter(
183190
python_module=self.analyzer_class.python_module
184191
)
185192

193+
if not configs.exists():
194+
self.skipTest(
195+
f"No AnalyzerConfig found for {self.analyzer_class.python_module}"
196+
)
197+
198+
config = configs.first()
199+
186200
# Test with invalid observable types if applicable
187201
invalid_observables = {
188202
"domain": "invalid..domain",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from api_app.analyzers_manager.observable_analyzers.haveibeenpwned import HaveIBeenPwned
2+
from tests.api_app.analyzers_manager.unit_tests.observable_analyzers.base_test_class import (
3+
BaseAnalyzerTest,
4+
)
5+
from tests.mock_utils import MockUpResponse, patch
6+
7+
8+
class HaveIBeenPwnedTestCase(BaseAnalyzerTest):
9+
analyzer_class = HaveIBeenPwned
10+
11+
@classmethod
12+
def get_extra_config(cls):
13+
return {
14+
"truncate_response": True,
15+
"include_unverified": False,
16+
"domain": "",
17+
"_api_key_name": "dummy-key",
18+
}
19+
20+
@staticmethod
21+
def get_mocked_response():
22+
return patch(
23+
"requests.get",
24+
return_value=MockUpResponse({}, 200),
25+
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from api_app.analyzers_manager.observable_analyzers.honeydb import HoneyDB
2+
from tests.api_app.analyzers_manager.unit_tests.observable_analyzers.base_test_class import (
3+
BaseAnalyzerTest,
4+
)
5+
from tests.mock_utils import MockUpResponse, patch
6+
7+
8+
class HoneyDBTestCase(BaseAnalyzerTest):
9+
analyzer_class = HoneyDB
10+
11+
@classmethod
12+
def get_extra_config(cls):
13+
return {
14+
"_api_key_name": "dummy-key",
15+
"_api_id_name": "dummy-id",
16+
"honeydb_analysis": "ip_query",
17+
"headers": {
18+
"X-HoneyDb-ApiKey": "dummy-key",
19+
"X-HoneyDb-ApiId": "dummy-id",
20+
},
21+
"result": {},
22+
"endpoints": [
23+
"scan_twitter",
24+
"ip_query",
25+
"ip_history",
26+
"internet_scanner",
27+
"ip_info",
28+
],
29+
}
30+
31+
@staticmethod
32+
def get_mocked_response():
33+
return patch("requests.get", return_value=MockUpResponse({}, 200))
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from api_app.analyzers_manager.observable_analyzers.hudsonrock import HudsonRock
2+
from tests.api_app.analyzers_manager.unit_tests.observable_analyzers.base_test_class import (
3+
BaseAnalyzerTest,
4+
)
5+
from tests.mock_utils import MockUpResponse, patch
6+
7+
8+
class HudsonRockTestCase(BaseAnalyzerTest):
9+
analyzer_class = HudsonRock
10+
11+
@classmethod
12+
def get_extra_config(cls):
13+
return {
14+
"_api_key_name": "dummy-api-key",
15+
"observable_classification": "generic", # to test login path
16+
"observable_name": "[email protected]",
17+
"page": 1,
18+
"sort_by": "asc",
19+
"installed_software": False,
20+
}
21+
22+
@staticmethod
23+
def get_mocked_response():
24+
return patch(
25+
"requests.post",
26+
return_value=MockUpResponse(
27+
{
28+
"credentials": [
29+
{
30+
"type": "client",
31+
"domain": "disney.com",
32+
"username": "••••",
33+
"password": "••••",
34+
}
35+
]
36+
},
37+
200,
38+
),
39+
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from unittest.mock import patch
2+
3+
from api_app.analyzers_manager.observable_analyzers.hunter_io import Hunter_Io
4+
from tests.api_app.analyzers_manager.unit_tests.observable_analyzers.base_test_class import (
5+
BaseAnalyzerTest,
6+
)
7+
from tests.mock_utils import MockUpResponse
8+
9+
10+
class HunterIoTestCase(BaseAnalyzerTest):
11+
analyzer_class = Hunter_Io
12+
13+
@staticmethod
14+
def get_mocked_response():
15+
mock_response = {
16+
"data": {
17+
"domain": "example.com",
18+
"emails": [{"value": "[email protected]", "type": "generic"}],
19+
}
20+
}
21+
return patch("requests.get", return_value=MockUpResponse(mock_response, 200))
22+
23+
@classmethod
24+
def get_extra_config(cls) -> dict:
25+
return {"_api_key_name": "dummy_api_key"}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from unittest.mock import patch
2+
3+
from api_app.analyzers_manager.observable_analyzers.hunter_how import Hunter_How
4+
from tests.api_app.analyzers_manager.unit_tests.observable_analyzers.base_test_class import (
5+
BaseAnalyzerTest,
6+
)
7+
from tests.mock_utils import MockUpResponse
8+
9+
10+
class HunterHowTestCase(BaseAnalyzerTest):
11+
analyzer_class = Hunter_How
12+
13+
@staticmethod
14+
def get_mocked_response():
15+
mock_response = {
16+
"list": [
17+
{
18+
"ip": "8.8.8.8",
19+
"domain": "example.com",
20+
"timestamp": "2024-01-01T00:00:00Z",
21+
}
22+
]
23+
}
24+
return patch("requests.get", return_value=MockUpResponse(mock_response, 200))
25+
26+
@classmethod
27+
def get_extra_config(cls) -> dict:
28+
return {
29+
"_api_key_name": "dummy_api_key",
30+
"page": 1,
31+
"page_size": 20,
32+
"start_time": "2024-01-01T00:00:00Z",
33+
"end_time": "2024-12-31T23:59:59Z",
34+
"parameters": {},
35+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from unittest.mock import patch
2+
3+
from api_app.analyzers_manager.observable_analyzers.inquest import InQuest
4+
from tests.api_app.analyzers_manager.unit_tests.observable_analyzers.base_test_class import (
5+
BaseAnalyzerTest,
6+
)
7+
from tests.mock_utils import MockUpResponse
8+
9+
10+
class InQuestTestCase(BaseAnalyzerTest):
11+
analyzer_class = InQuest
12+
13+
@staticmethod
14+
def get_mocked_response():
15+
mock_response = {"result": "ok", "data": ["some IOC result"]}
16+
return patch("requests.get", return_value=MockUpResponse(mock_response, 200))
17+
18+
@classmethod
19+
def get_extra_config(cls) -> dict:
20+
return {
21+
"inquest_analysis": "dfi_search",
22+
"_api_key_name": "Bearer dummy_api_key",
23+
"generic_identifier_mode": "user-defined",
24+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from unittest.mock import patch
2+
3+
from api_app.analyzers_manager.observable_analyzers.intelx import IntelX
4+
from tests.api_app.analyzers_manager.unit_tests.observable_analyzers.base_test_class import (
5+
BaseAnalyzerTest,
6+
)
7+
from tests.mock_utils import MockUpResponse
8+
9+
10+
class IntelXTestCase(BaseAnalyzerTest):
11+
analyzer_class = IntelX
12+
13+
@staticmethod
14+
def get_mocked_response():
15+
return [
16+
patch("requests.Session.post", return_value=MockUpResponse({"id": 1}, 200)),
17+
patch(
18+
"requests.Session.get",
19+
return_value=MockUpResponse({"selectors": []}, 200),
20+
),
21+
]
22+
23+
@classmethod
24+
def get_extra_config(cls) -> dict:
25+
return {
26+
"_api_key_name": "dummy_api_key",
27+
"query_type": "phonebook", # or "intelligent"
28+
"rows_limit": 10,
29+
"max_tries": 3,
30+
"poll_distance": 1,
31+
"timeout": 5,
32+
"datefrom": "2024-01-01",
33+
"dateto": "2024-12-31",
34+
"search_url": "",
35+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from unittest.mock import patch
2+
3+
from api_app.analyzers_manager.observable_analyzers.ip2location import Ip2location
4+
from tests.api_app.analyzers_manager.unit_tests.observable_analyzers.base_test_class import (
5+
BaseAnalyzerTest,
6+
)
7+
from tests.mock_utils import MockUpResponse
8+
9+
10+
class Ip2locationTestCase(BaseAnalyzerTest):
11+
analyzer_class = Ip2location
12+
13+
@staticmethod
14+
def get_mocked_response():
15+
mock_response = {
16+
"ip": "8.8.8.8",
17+
"country_code": "US",
18+
"country_name": "United States of America",
19+
"region_name": "California",
20+
"city_name": "Mountain View",
21+
"latitude": 37.405992,
22+
"longitude": -122.078515,
23+
"zip_code": "94043",
24+
"time_zone": "-07:00",
25+
"asn": "15169",
26+
"as": "Google LLC",
27+
"is_proxy": False,
28+
}
29+
30+
return patch("requests.get", return_value=MockUpResponse(mock_response, 200))
31+
32+
@classmethod
33+
def get_extra_config(cls) -> dict:
34+
return {"_api_key_name": "dummy_key", "api_version": "keyed"}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from unittest.mock import patch
2+
3+
from api_app.analyzers_manager.observable_analyzers.ip2whois import Ip2whois
4+
from tests.api_app.analyzers_manager.unit_tests.observable_analyzers.base_test_class import (
5+
BaseAnalyzerTest,
6+
)
7+
from tests.mock_utils import MockUpResponse
8+
9+
10+
class Ip2whoisTestCase(BaseAnalyzerTest):
11+
analyzer_class = Ip2whois
12+
13+
@staticmethod
14+
def get_mocked_response():
15+
mock_response = {
16+
"domain": "msn.com",
17+
"domain_id": "4569290_DOMAIN_COM-VRSN",
18+
"status": "client delete prohibited",
19+
"create_date": "1994-11-10T05:00:00Z",
20+
"update_date": "2023-05-03T11:39:17Z",
21+
"expire_date": "2024-06-04T16:44:29Z",
22+
"domain_age": 10766,
23+
"whois_server": "",
24+
"registrar": {"iana_id": "292", "name": "MarkMonitor Inc.", "url": ""},
25+
"nameservers": [
26+
"dns1.p09.nsone.net",
27+
"ns1-204.azure-dns.com",
28+
"ns2-204.azure-dns.net",
29+
"ns3-204.azure-dns.org",
30+
"ns4-204.azure-dns.info",
31+
],
32+
}
33+
return patch("requests.get", return_value=MockUpResponse(mock_response, 200))
34+
35+
@classmethod
36+
def get_extra_config(cls) -> dict:
37+
return {"_api_key_name": "dummy_api_key"}

0 commit comments

Comments
 (0)