Commit 848d552e authored by Łukasz Nowak's avatar Łukasz Nowak

Cover cases of bad response from shadir.

parent ec8f2d45
......@@ -581,10 +581,62 @@ class OnlineTest(OnlineMixin, unittest.TestCase):
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_json_no_in_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(json.dumps([['This is not a json.', 'signature']]))
try:
nc.select(key)
except slapos.libnetworkcache.DirectoryNotFound, msg:
self.assertTrue(str(msg).startswith('It was impossible to parse '
'json-in-json response'))
def test_select_json_in_json_no_dict(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(json.dumps([[json.dumps('This is a string'),
'signature']]))
try:
nc.select(key)
except slapos.libnetworkcache.DirectoryNotFound, msg:
self.assertTrue(str(msg).startswith('It was impossible to fetch sha512 '
'from directory response'))
def test_select_signed_content_server_hacked(self):
key = 'somekey' + 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