Skip to content

Commit

Permalink
feat(scan_file): Check file argument is a file object (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmacias95 authored Aug 13, 2021
1 parent 654a194 commit 6485b45
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ def test_scan_file(httpserver):
assert analysis.type == 'analysis'


def test_scan_file_valueerror(httpserver):
"""Tests an exception is raised when calling scan_file using invalid args."""
with new_client(httpserver) as client:
with pytest.raises(TypeError):
client.scan_file('/Users/test/path/to/file.txt')


def test_scan_url(httpserver):

httpserver.expect_request(
Expand Down
4 changes: 4 additions & 0 deletions vt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import asyncio
import base64
import json
import io

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

if not isinstance(file, io.IOBase):
raise TypeError(f'Expected a file to be a file object, got {type(file)}')

# The snippet below could be replaced with this simpler code:
#
# form_data = aiohttp.FormData()
Expand Down

0 comments on commit 6485b45

Please sign in to comment.