fix: Encode string in _encode_file_to_upload

pull/186/head
Raphaël Vinot 2018-01-29 10:30:37 +01:00
parent f9063ad588
commit 05bbfac658
2 changed files with 20 additions and 5 deletions

View File

@ -815,9 +815,12 @@ class PyMISP(object):
def _encode_file_to_upload(self, filepath_or_bytes):
"""Helper to encode a file to upload"""
if isinstance(filepath_or_bytes, basestring) and os.path.isfile(filepath_or_bytes):
with open(filepath_or_bytes, 'rb') as f:
binblob = f.read()
if isinstance(filepath_or_bytes, basestring):
if os.path.isfile(filepath_or_bytes):
with open(filepath_or_bytes, 'rb') as f:
binblob = f.read()
else:
binblob = filepath_or_bytes.encode()
else:
binblob = filepath_or_bytes
return base64.b64encode(binblob).decode()
@ -1583,6 +1586,18 @@ class PyMISP(object):
response = self.__prepare_request('GET', url)
return self._check_response(response)
# ############## Galaxies/Clusters ##################
def get_galaxies(self):
url = urljoin(self.root_url, '/galaxies')
response = self.__prepare_request('GET', url)
return self._check_response(response)
def get_galaxy(self, galaxy_id):
url = urljoin(self.root_url, '/galaxies/view/{}'.format(galaxy_id))
response = self.__prepare_request('GET', url)
return self._check_response(response)
# ##############################################
# ############### Non-JSON output ##############
# ##############################################

View File

@ -444,11 +444,11 @@ class TestOffline(unittest.TestCase):
self.assertEqual((False, None), pymisp.download_samples())
def test_sample_upload(self, m):
if (3, 0) < sys.version_info < (3, 5):
return unittest.SkipTest()
self.initURI(m)
pymisp = PyMISP(self.domain, self.key)
upload = pymisp.upload_sample("tmux", "tests/viper-test-files/test_files/tmux", 1)
upload = pymisp.upload_sample("tmux", "non_existing_file", 1)
upload = pymisp.upload_sample("tmux", b"binblob", 1)
def test_get_all_tags(self, m):
self.initURI(m)