Commit ec8f2d45 authored by Łukasz Nowak's avatar Łukasz Nowak

Cover a case when server replied no json.

parent 755401fd
...@@ -558,6 +558,33 @@ class OnlineTest(OnlineMixin, unittest.TestCase): ...@@ -558,6 +558,33 @@ class OnlineTest(OnlineMixin, unittest.TestCase):
# empty content in shadir so usual exception is raised # empty content in shadir so usual exception is raised
self.assertEqual(str(msg), 'Could not find a trustable entry.') self.assertEqual(str(msg), 'Could not find a trustable entry.')
def test_select_no_json_response(self):
key = 'somekey' + str(random.random())
urlmd5 = str(random.random())
file_name = 'my file'
test_data = tempfile.TemporaryFile()
test_string = str(random.random())
test_data.write(test_string)
test_data.seek(0)
key_file = tempfile.NamedTemporaryFile()
key_file.write(self.key)
key_file.flush()
key_file.seek(0)
nc = slapos.libnetworkcache.NetworkcacheClient(
self.shacache, self.shadir)
self.assertEqual(True, nc.upload(self.test_data, key, urlmd5=urlmd5,
file_name=file_name))
f = os.path.join(self.tree, 'shadir', key)
# now remove the entry from shacache
open(f, 'w').write('This is not a json.')
try:
nc.select(key)
except slapos.libnetworkcache.DirectoryNotFound, msg:
# empty content in shadir so usual exception is raised
self.assertTrue(str(msg).startswith('It was impossible to parse json '
'response'))
def test_select_signed_content_server_hacked(self): def test_select_signed_content_server_hacked(self):
key = 'somekey' + str(random.random()) key = 'somekey' + str(random.random())
urlmd5 = str(random.random()) urlmd5 = str(random.random())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment