Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(alert): wait works for Alert.from_id properly #151

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading