Skip to content

Commit

Permalink
Merge pull request #109 from intezer/fix/raise-file-too-large
Browse files Browse the repository at this point in the history
fix(analysis): Raise `FileTooLargeError` on analyzing file that is to…
  • Loading branch information
davidt99 authored Aug 3, 2023
2 parents d02c955 + 575d402 commit 2e52aae
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.18.6
______
- Raise `FileTooLargeError` on analyzing file that is too large.

1.18.5
______
- Fix URL analysis report bug.
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.18.5'
__version__ = '1.18.6'
2 changes: 2 additions & 0 deletions intezer_sdk/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,8 @@ def _param_initialize(disable_dynamic_unpacking: bool,
def _assert_analysis_response_status_code(response: Response):
if response.status_code == HTTPStatus.NOT_FOUND:
raise errors.HashDoesNotExistError(response)
elif response.status_code == HTTPStatus.REQUEST_ENTITY_TOO_LARGE:
raise errors.FileTooLargeError(response)
elif response.status_code == HTTPStatus.CONFLICT:
running_analysis_id = response.json().get('result', {}).get('analysis_id')
raise errors.AnalysisIsAlreadyRunningError(response, running_analysis_id)
Expand Down
3 changes: 3 additions & 0 deletions intezer_sdk/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class HashDoesNotExistError(ServerError):
def __init__(self, response: requests.Response):
super().__init__('Hash was not found', response)

class FileTooLargeError(ServerError):
def __init__(self, response: requests.Response):
super().__init__('File is too large', response)

class ReportDoesNotExistError(IntezerError):
def __init__(self):
Expand Down
13 changes: 12 additions & 1 deletion tests/unit/test_file_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,17 @@ def test_send_analysis_by_sha256_that_dont_exist_raise_error(self):
with self.assertRaises(errors.HashDoesNotExistError):
analysis.send()

def test_send_analysis_by_sha256_that_is_too_large_raise_error(self):
# Arrange
with responses.RequestsMock() as mock:
mock.add('POST',
url=f'{self.full_url}/analyze-by-hash',
status=HTTPStatus.REQUEST_ENTITY_TOO_LARGE)
analysis = FileAnalysis(file_hash='a' * 64)
# Act + Assert
with self.assertRaises(errors.FileTooLargeError):
analysis.send()

def test_send_analysis_by_sha256_with_expired_jwt_token_gets_new_token(self):
# Arrange
analysis = FileAnalysis(file_hash='a' * 64)
Expand All @@ -565,7 +576,7 @@ def request_callback(request):
analysis.send()
self.assertEqual(3, len(mock.calls)) # analyze -> refresh access_token -> analyze retry

def test_send_analysis_by_sha256_with_expired_jwt_token_doesnt_loop_indefinitley(self):
def test_send_analysis_by_sha256_with_expired_jwt_token_doesnt_loop_indefinitely(self):
# Arrange
with responses.RequestsMock() as mock:
mock.add('POST', url=f'{self.full_url}/analyze-by-hash', status=HTTPStatus.UNAUTHORIZED)
Expand Down

0 comments on commit 2e52aae

Please sign in to comment.