Commit 46910f2f authored by Sofia Papagiannaki's avatar Sofia Papagiannaki

pithos: Fix TypeError when trying to retrieve invalid object version

parent ab866c5d
......@@ -136,6 +136,46 @@ class ObjectGet(PithosAPITest):
self.assertEqual(len(l3), len(l2) + 1)
self.assertEqual(l3[:-1], l2)
def test_get_version(self):
c = 'c1'
o = self.objects[c][0]
url = join_urls(self.pithos_path, self.user, c, o)
# Update metadata
meta = {'HTTP_X_OBJECT_META_QUALITY': 'AAA'}
r = self.post(url, content_type='', **meta)
self.assertEqual(r.status_code, 202)
url = join_urls(self.pithos_path, self.user, c, o)
r = self.get('%s?version=list&format=json' % url)
self.assertEqual(r.status_code, 200)
l = json.loads(r.content)['versions']
self.assertEqual(len(l), 2)
r = self.head('%s?version=%s' % (url, l[0][0]))
self.assertEqual(r.status_code, 200)
self.assertTrue('X-Object-Meta-Quality' not in r)
r = self.head('%s?version=%s' % (url, l[1][0]))
self.assertEqual(r.status_code, 200)
self.assertTrue('X-Object-Meta-Quality' in r)
# test invalid version
r = self.head('%s?version=-1' % url)
self.assertEqual(r.status_code, 404)
other_name, other_data, r = self.upload_object(c)
self.assertTrue('X-Object-Version' in r)
other_version = r['X-Object-Version']
self.assertTrue(o != other_name)
r = self.get('%s?version=%s' % (url, other_version))
self.assertEqual(r.status_code, 403)
r = self.head('%s?version=%s' % (url, other_version))
self.assertEqual(r.status_code, 403)
def test_objects_with_trailing_spaces(self):
# create object
oname = self.upload_object('c1')[0]
......
......@@ -32,14 +32,14 @@
# or implied, of GRNET S.A.
from dbwrapper import DBWrapper
from node import (Node, ROOTNODE, SERIAL, HASH, SIZE, TYPE, MTIME, MUSER, UUID,
CHECKSUM, CLUSTER, MATCH_PREFIX, MATCH_EXACT)
from node import (Node, ROOTNODE, SERIAL, NODE, HASH, SIZE, TYPE, MTIME, MUSER,
UUID, CHECKSUM, CLUSTER, MATCH_PREFIX, MATCH_EXACT)
from permissions import Permissions, READ, WRITE
from config import Config
from quotaholder_serials import QuotaholderSerial
__all__ = ["DBWrapper",
"Node", "ROOTNODE", "SERIAL", "HASH", "SIZE", "TYPE", "MTIME",
"MUSER", "UUID", "CHECKSUM", "CLUSTER", "MATCH_PREFIX",
"Node", "ROOTNODE", "NODE", "SERIAL", "HASH", "SIZE", "TYPE",
"MTIME", "MUSER", "UUID", "CHECKSUM", "CLUSTER", "MATCH_PREFIX",
"MATCH_EXACT", "Permissions", "READ", "WRITE", "Config",
"QuotaholderSerial"]
......@@ -32,14 +32,14 @@
# or implied, of GRNET S.A.
from dbwrapper import DBWrapper
from node import (Node, ROOTNODE, SERIAL, HASH, SIZE, TYPE, MTIME, MUSER, UUID,
CHECKSUM, CLUSTER, MATCH_PREFIX, MATCH_EXACT)
from node import (Node, ROOTNODE, SERIAL, NODE, HASH, SIZE, TYPE, MTIME, MUSER,
UUID, CHECKSUM, CLUSTER, MATCH_PREFIX, MATCH_EXACT)
from permissions import Permissions, READ, WRITE
from config import Config
from quotaholder_serials import QuotaholderSerial
__all__ = ["DBWrapper",
"Node", "ROOTNODE", "SERIAL", "HASH", "SIZE", "TYPE", "MTIME",
"MUSER", "UUID", "CHECKSUM", "CLUSTER", "MATCH_PREFIX",
"Node", "ROOTNODE", "SERIAL", "NODE", "HASH", "SIZE", "TYPE",
"MTIME", "MUSER", "UUID", "CHECKSUM", "CLUSTER", "MATCH_PREFIX",
"MATCH_EXACT", "Permissions", "READ", "WRITE", "Config",
"QuotaholderSerial"]
......@@ -203,9 +203,9 @@ class ModularBackend(BaseBackend):
for x in ['READ', 'WRITE']:
setattr(self, x, getattr(self.db_module, x))
self.node = self.db_module.Node(**params)
for x in ['ROOTNODE', 'SERIAL', 'HASH', 'SIZE', 'TYPE', 'MTIME',
'MUSER', 'UUID', 'CHECKSUM', 'CLUSTER', 'MATCH_PREFIX',
'MATCH_EXACT']:
for x in ['ROOTNODE', 'SERIAL', 'NODE', 'HASH', 'SIZE', 'TYPE',
'MTIME', 'MUSER', 'UUID', 'CHECKSUM', 'CLUSTER',
'MATCH_PREFIX', 'MATCH_EXACT']:
setattr(self, x, getattr(self.db_module, x))
self.block_module = load_module(block_module)
......@@ -915,8 +915,7 @@ class ModularBackend(BaseBackend):
self.permissions.public_unset(path)
else:
self.permissions.public_set(
path, self.public_url_security, self.public_url_alphabet
)
path, self.public_url_security, self.public_url_alphabet)
@debug_method
def get_object_hashmap(self, user, account, container, name, version=None):
......@@ -925,6 +924,8 @@ class ModularBackend(BaseBackend):
self._can_read(user, account, container, name)
path, node = self._lookup_object(account, container, name)
props = self._get_version(node, version)
if props[self.HASH] is None:
return 0, ()
hashmap = self.store.map_get(binascii.unhexlify(props[self.HASH]))
return props[self.SIZE], [binascii.hexlify(x) for x in hashmap]
......@@ -1368,6 +1369,8 @@ class ModularBackend(BaseBackend):
except ValueError:
raise VersionNotExists('Version does not exist')
props = self.node.version_get_properties(version)
if props is not None and node != props[self.NODE]:
raise NotAllowedError('Version does not belong to this path')
if props is None or props[self.CLUSTER] == CLUSTER_DELETED:
raise VersionNotExists('Version does not exist')
return props
......
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