diff --git a/CHANGES b/CHANGES index c25c76c..1e41212 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +1.18.6 +______ +- Raise `FileTooLargeError` on analyzing file that is too large. + 1.18.5 ______ - Fix URL analysis report bug. diff --git a/intezer_sdk/__init__.py b/intezer_sdk/__init__.py index dfcd902..7002b98 100644 --- a/intezer_sdk/__init__.py +++ b/intezer_sdk/__init__.py @@ -1 +1 @@ -__version__ = '1.18.5' +__version__ = '1.18.6' diff --git a/intezer_sdk/_api.py b/intezer_sdk/_api.py index 1740ce2..2f0fcba 100644 --- a/intezer_sdk/_api.py +++ b/intezer_sdk/_api.py @@ -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) diff --git a/intezer_sdk/errors.py b/intezer_sdk/errors.py index dd75042..2d5d612 100644 --- a/intezer_sdk/errors.py +++ b/intezer_sdk/errors.py @@ -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): diff --git a/tests/unit/test_file_analysis.py b/tests/unit/test_file_analysis.py index 36239df..b51f36e 100644 --- a/tests/unit/test_file_analysis.py +++ b/tests/unit/test_file_analysis.py @@ -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) @@ -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)