Skip to content

Commit 41d9ee5

Browse files
[client] Add enpoint to fetch targets for nuclei and nmap injectors
Co-authored-by: MarineLM <[email protected]>
1 parent a80e93f commit 41d9ee5

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

pyoaev/apis/endpoint.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any, Dict
22

33
from pyoaev import exceptions as exc
4+
from pyoaev.apis.inputs.search import SearchPaginationInput
45
from pyoaev.base import RESTManager, RESTObject
56
from pyoaev.utils import RequiredOptional
67

@@ -36,3 +37,11 @@ def upsert(self, endpoint: Dict[str, Any], **kwargs: Any) -> Dict[str, Any]:
3637
path = f"{self.path}/agentless/upsert"
3738
result = self.openaev.http_post(path, post_data=endpoint, **kwargs)
3839
return result
40+
41+
@exc.on_http_error(exc.OpenAEVUpdateError)
42+
def searchTargets(
43+
self, input: SearchPaginationInput, **kwargs: Any
44+
) -> Dict[str, Any]:
45+
path = f"{self.path}/targets"
46+
result = self.openaev.http_post(path, post_data=input.to_dict(), **kwargs)
47+
return result

pyoaev/contracts/contract_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class ContractFieldType(str, Enum):
3232
Payload: str = "payload"
3333

3434

35+
class ContractFieldKey(str, Enum):
36+
Asset: str = "assets"
37+
AssetGroup: str = "asset_groups"
38+
39+
3540
class ContractOutputType(str, Enum):
3641
Text: str = "text"
3742
Number: str = "number"
@@ -270,6 +275,7 @@ def get_type(self) -> str:
270275

271276
@dataclass
272277
class ContractAsset(ContractCardinalityElement):
278+
key: str = field(default=ContractFieldKey.Asset.value, init=False)
273279

274280
@property
275281
def get_type(self) -> str:
@@ -278,6 +284,7 @@ def get_type(self) -> str:
278284

279285
@dataclass
280286
class ContractAssetGroup(ContractCardinalityElement):
287+
key: str = field(default=ContractFieldKey.AssetGroup.value, init=False)
281288

282289
@property
283290
def get_type(self) -> str:

test/apis/endpoint/__init__.py

Whitespace-only changes.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from unittest import TestCase, main, mock
2+
from unittest.mock import ANY
3+
4+
from pyoaev import OpenAEV
5+
from pyoaev.apis.inputs.search import Filter, FilterGroup, SearchPaginationInput
6+
7+
8+
def mock_response(**kwargs):
9+
class MockResponse:
10+
def __init__(self, json_data, status_code):
11+
self.json_data = json_data
12+
self.status_code = status_code
13+
self.history = None
14+
self.content = None
15+
self.headers = {"Content-Type": "application/json"}
16+
17+
def json(self):
18+
return self.json_data
19+
20+
return MockResponse(None, 200)
21+
22+
23+
class TestInjectorContract(TestCase):
24+
@mock.patch("requests.Session.request", side_effect=mock_response)
25+
def test_search_input_correctly_serialised(self, mock_request):
26+
api_client = OpenAEV("url", "token")
27+
28+
search_input = SearchPaginationInput(
29+
0,
30+
20,
31+
FilterGroup(
32+
"or",
33+
[Filter("targets", "and", "eq", ["target_1", "target_2", "target_3"])],
34+
),
35+
None,
36+
None,
37+
)
38+
39+
expected_json = search_input.to_dict()
40+
api_client.endpoint.searchTargets(search_input)
41+
42+
mock_request.assert_called_once_with(
43+
method="post",
44+
url="url/api/endpoints/targets",
45+
params={},
46+
data=None,
47+
timeout=None,
48+
stream=False,
49+
verify=True,
50+
json=expected_json,
51+
headers=ANY,
52+
auth=ANY,
53+
)
54+
55+
56+
if __name__ == "__main__":
57+
main()

0 commit comments

Comments
 (0)