mirror of https://github.com/MISP/PyMISP
fix: Encode string in _encode_file_to_upload
parent
f9063ad588
commit
05bbfac658
|
@ -815,9 +815,12 @@ class PyMISP(object):
|
||||||
|
|
||||||
def _encode_file_to_upload(self, filepath_or_bytes):
|
def _encode_file_to_upload(self, filepath_or_bytes):
|
||||||
"""Helper to encode a file to upload"""
|
"""Helper to encode a file to upload"""
|
||||||
if isinstance(filepath_or_bytes, basestring) and os.path.isfile(filepath_or_bytes):
|
if isinstance(filepath_or_bytes, basestring):
|
||||||
with open(filepath_or_bytes, 'rb') as f:
|
if os.path.isfile(filepath_or_bytes):
|
||||||
binblob = f.read()
|
with open(filepath_or_bytes, 'rb') as f:
|
||||||
|
binblob = f.read()
|
||||||
|
else:
|
||||||
|
binblob = filepath_or_bytes.encode()
|
||||||
else:
|
else:
|
||||||
binblob = filepath_or_bytes
|
binblob = filepath_or_bytes
|
||||||
return base64.b64encode(binblob).decode()
|
return base64.b64encode(binblob).decode()
|
||||||
|
@ -1583,6 +1586,18 @@ class PyMISP(object):
|
||||||
response = self.__prepare_request('GET', url)
|
response = self.__prepare_request('GET', url)
|
||||||
return self._check_response(response)
|
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 ##############
|
# ############### Non-JSON output ##############
|
||||||
# ##############################################
|
# ##############################################
|
||||||
|
|
|
@ -444,11 +444,11 @@ class TestOffline(unittest.TestCase):
|
||||||
self.assertEqual((False, None), pymisp.download_samples())
|
self.assertEqual((False, None), pymisp.download_samples())
|
||||||
|
|
||||||
def test_sample_upload(self, m):
|
def test_sample_upload(self, m):
|
||||||
if (3, 0) < sys.version_info < (3, 5):
|
|
||||||
return unittest.SkipTest()
|
|
||||||
self.initURI(m)
|
self.initURI(m)
|
||||||
pymisp = PyMISP(self.domain, self.key)
|
pymisp = PyMISP(self.domain, self.key)
|
||||||
upload = pymisp.upload_sample("tmux", "tests/viper-test-files/test_files/tmux", 1)
|
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):
|
def test_get_all_tags(self, m):
|
||||||
self.initURI(m)
|
self.initURI(m)
|
||||||
|
|
Loading…
Reference in New Issue