Skip to content

Commit

Permalink
Merge pull request #151 from intezer/fix/alert-wait
Browse files Browse the repository at this point in the history
fix(alert): wait works for Alert.from_id properly
  • Loading branch information
davidt99 authored Jan 22, 2025
2 parents c9dab7e + e5ba7e9 commit 5c501ab
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
1.21.10
------
- Fix `Alert.from_id` wait flag

1.21.9
------
- Send autoruns info from offline scan

1.21.8
_______
- Raise AnalysisRateLimitError for all endpoints when rate limit exceeded error returning from server
Expand Down
2 changes: 1 addition & 1 deletion intezer_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.21.9'
__version__ = '1.21.10'
6 changes: 3 additions & 3 deletions intezer_sdk/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@ def from_id(cls,
"""
new_alert = cls(alert_id=alert_id, api=api)
status = new_alert.check_status()
if status == AlertStatusCode.IN_PROGRESS:
if status == AlertStatusCode.IN_PROGRESS and not wait:
raise errors.AlertInProgressError(alert_id)
if fetch_scans:
new_alert.fetch_scans()
if wait:
new_alert.wait_for_completion(timeout=timeout)
if fetch_scans:
new_alert.fetch_scans()
return new_alert

@classmethod
Expand Down
18 changes: 17 additions & 1 deletion tests/unit/test_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_ingest_alert_success(self):
# Assert
self.assertEqual(alert.alert_id, alert_id)

def test_get_alert_with_alert_object(self):
def test_alert_from_id(self):
# Arrange
with responses.RequestsMock() as mock:
mock.add('GET',
Expand All @@ -100,6 +100,22 @@ def test_get_alert_with_alert_object(self):
# Assert
self.assertEqual(alert.alert_id, 'alert_id')


def test_alert_from_id_waits_from_completion(self):
# Arrange
with responses.RequestsMock() as mock:
mock.get(url=f'{self.full_url}/alerts/get-by-id',
status=HTTPStatus.OK,
json={'result': {}, 'status': 'in_progress'})
mock.get(url=f'{self.full_url}/alerts/get-by-id',
status=HTTPStatus.OK,
json={'result': {}, 'status': 'success'})
# Act
alert = Alert.from_id('alert_id', wait=True)

# Assert
self.assertEqual(alert.alert_id, 'alert_id')

def test_ingest_binary_alert_success(self):
# Arrange
raw_alert = load_binary_file_from_resources('binary_alerts/test.eml')
Expand Down

0 comments on commit 5c501ab

Please sign in to comment.