Skip to content

Commit

Permalink
Added get_upcoming functions in targets (#13)
Browse files Browse the repository at this point in the history
Added `get_upcoming()` function to targets plugin to get a list of upcoming targets
  • Loading branch information
huseyince authored Nov 12, 2022
1 parent 264f06e commit b8211a4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/src/usage/plugins/targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@
>> [{"slug": "lfjpgmk",...},...]
>> ```
## targets.get_upcoming()
> Gets a list of upcoming Targets from the Synack API.
>
>> Examples
>> ```python3
>> >>> h.targets.get_upcoming()
>> [{'codename': 'SLEEPYSLUG', 'slug': '1o2h8o', 'category_name': 'Web Application', 'organization_name': 'SLEEPY Orgnization', 'upcoming_start_date': 1668430800}, ...]
>> ```
## targets.set_connected(target, **kwargs)
> Connect to a specified target
Expand Down
20 changes: 20 additions & 0 deletions src/synack/plugins/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,26 @@ def get_unregistered(self):
ret.append({'codename': t['codename'], 'slug': t['slug']})
return ret

def get_upcoming(self):
"""Get slugs and upcoming start dates of all upcoming targets"""
query = {
'filter[primary]': 'upcoming',
'filter[secondary]': 'all',
'filter[industry]': 'all',
'sorting[field]': 'upcomingStartDate',
'sorting[direction]': 'asc'
}
res = self.api.request('GET', 'targets', query=query)
ret = []
if res.status_code == 200:
for t in res.json():
ret.append({'codename': t['codename'],
'slug': t['slug'],
'category_name': t['category']['name'],
'organization_name': t['organization']['name'],
'upcoming_start_date': t['upcoming_start_date']})
return ret

def set_connected(self, target=None, **kwargs):
"""Connect to a target"""
slug = None
Expand Down
25 changes: 25 additions & 0 deletions test/test_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,31 @@ def test_get_unregistered(self):
"targets",
query=query)

def test_get_upcoming(self):
"""Should get a list upcoming targets"""
query = {
'filter[primary]': 'upcoming',
'filter[secondary]': 'all',
'filter[industry]': 'all',
'sorting[field]': 'upcomingStartDate',
'sorting[direction]': 'asc'
}
self.targets.api.request.return_value.status_code = 200
upcoming = [
{
"codename": "SLEEPYSLUG",
"slug": "1o2h8o",
'category_name': 'Web Application',
'organization_name': 'SLEEPY Orgnization',
'upcoming_start_date': 1668430800
}
]
self.targets.api.request.return_value.json.return_value = upcoming
self.assertEqual(upcoming, self.targets.get_upcoming())
self.targets.api.request.assert_called_with("GET",
"targets",
query=query)

def test_get_unregistered_assessments_empty(self):
"""Should get a list of unregistered targets"""
self.targets.get_assessments = MagicMock()
Expand Down

0 comments on commit b8211a4

Please sign in to comment.