Skip to content

Commit 6485b45

Browse files
authored
feat(scan_file): Check file argument is a file object (#70)
1 parent 654a194 commit 6485b45

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

tests/test_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@ def test_scan_file(httpserver):
339339
assert analysis.type == 'analysis'
340340

341341

342+
def test_scan_file_valueerror(httpserver):
343+
"""Tests an exception is raised when calling scan_file using invalid args."""
344+
with new_client(httpserver) as client:
345+
with pytest.raises(TypeError):
346+
client.scan_file('/Users/test/path/to/file.txt')
347+
348+
342349
def test_scan_url(httpserver):
343350

344351
httpserver.expect_request(

vt/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import asyncio
1616
import base64
1717
import json
18+
import io
1819

1920
from .error import APIError
2021
from .feed import Feed
@@ -584,6 +585,9 @@ def scan_file(self, file, wait_for_completion=False):
584585
async def scan_file_async(self, file, wait_for_completion=False):
585586
"""Like :func:`scan_file` but returns a coroutine."""
586587

588+
if not isinstance(file, io.IOBase):
589+
raise TypeError(f'Expected a file to be a file object, got {type(file)}')
590+
587591
# The snippet below could be replaced with this simpler code:
588592
#
589593
# form_data = aiohttp.FormData()

0 commit comments

Comments
 (0)