Skip to content

Commit 2e52aae

Browse files
authored
Merge pull request #109 from intezer/fix/raise-file-too-large
fix(analysis): Raise `FileTooLargeError` on analyzing file that is to…
2 parents d02c955 + 575d402 commit 2e52aae

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

CHANGES

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
1.18.6
2+
______
3+
- Raise `FileTooLargeError` on analyzing file that is too large.
4+
15
1.18.5
26
______
37
- Fix URL analysis report bug.

intezer_sdk/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.18.5'
1+
__version__ = '1.18.6'

intezer_sdk/_api.py

+2
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,8 @@ def _param_initialize(disable_dynamic_unpacking: bool,
727727
def _assert_analysis_response_status_code(response: Response):
728728
if response.status_code == HTTPStatus.NOT_FOUND:
729729
raise errors.HashDoesNotExistError(response)
730+
elif response.status_code == HTTPStatus.REQUEST_ENTITY_TOO_LARGE:
731+
raise errors.FileTooLargeError(response)
730732
elif response.status_code == HTTPStatus.CONFLICT:
731733
running_analysis_id = response.json().get('result', {}).get('analysis_id')
732734
raise errors.AnalysisIsAlreadyRunningError(response, running_analysis_id)

intezer_sdk/errors.py

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class HashDoesNotExistError(ServerError):
5656
def __init__(self, response: requests.Response):
5757
super().__init__('Hash was not found', response)
5858

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

6063
class ReportDoesNotExistError(IntezerError):
6164
def __init__(self):

tests/unit/test_file_analysis.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,17 @@ def test_send_analysis_by_sha256_that_dont_exist_raise_error(self):
541541
with self.assertRaises(errors.HashDoesNotExistError):
542542
analysis.send()
543543

544+
def test_send_analysis_by_sha256_that_is_too_large_raise_error(self):
545+
# Arrange
546+
with responses.RequestsMock() as mock:
547+
mock.add('POST',
548+
url=f'{self.full_url}/analyze-by-hash',
549+
status=HTTPStatus.REQUEST_ENTITY_TOO_LARGE)
550+
analysis = FileAnalysis(file_hash='a' * 64)
551+
# Act + Assert
552+
with self.assertRaises(errors.FileTooLargeError):
553+
analysis.send()
554+
544555
def test_send_analysis_by_sha256_with_expired_jwt_token_gets_new_token(self):
545556
# Arrange
546557
analysis = FileAnalysis(file_hash='a' * 64)
@@ -565,7 +576,7 @@ def request_callback(request):
565576
analysis.send()
566577
self.assertEqual(3, len(mock.calls)) # analyze -> refresh access_token -> analyze retry
567578

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

0 commit comments

Comments
 (0)