Commit f1dab536 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki

pithos: Fix permission listing for objects containing / in their name

Add tests
parent 1dfba7ed
......@@ -47,7 +47,8 @@ class ListSharing(PithosAPITest):
self.upload_object(cname, 'obj', user=user)
self.create_folder(cname, 'f1', user=user)
self.create_folder(cname, 'f1/f2', user=user)
self.upload_object(cname, 'f1/f2/obj', user=user)
self.create_folder(cname, 'f1/f2/f3', user=user)
self.upload_object(cname, 'f1/f2/f3/obj', user=user)
# share /c0/f1 path for read
url = join_urls(self.pithos_path, user, 'c0', 'f1')
......@@ -92,23 +93,66 @@ class ListSharing(PithosAPITest):
self.assertEqual([i['name'] for i in allowed_containers], ['c0'])
url = join_urls(url, 'c0')
r = self.get('%s?delimiter=/&shared=&format=json' % url)
r = self.get('%s?delimiter=/&shared=&' % url)
self.assertEqual(r.status_code, 200)
shared_objects = [i.get('name', i.get('subdir')) for i in
json.loads(r.content)]
shared_objects = r.content.split('\n')
if '' in shared_objects:
shared_objects.remove('')
self.assertEqual(shared_objects, ['f1', 'f1/'])
r = self.get('%s?delimiter=/&shared=&format=json' % url)
self.assertEqual(r.status_code, 200)
shared_objects = json.loads(r.content)
self.assertEqual([o.get('name', o.get('subdir')) for
o in shared_objects],
['f1', 'f1/'])
folder = (o for o in shared_objects if o['name'] == 'f1').next()
self.assertTrue('x_object_sharing' in folder)
self.assertTrue(folder['x_object_sharing'] == 'read=*')
r = self.get('%s?delimiter=/&prefix=f1&shared=&' % url)
self.assertEqual(r.status_code, 200)
shared_objects = r.content.split('\n')
if '' in shared_objects:
shared_objects.remove('')
self.assertEqual(shared_objects, ['f1/f2', 'f1/f2/'])
r = self.get('%s?delimiter=/&prefix=f1&shared=&format=json' % url)
self.assertEqual(r.status_code, 200)
shared_objects = json.loads(r.content)
self.assertEqual([o.get('name', o.get('subdir')) for
o in shared_objects],
['f1/f2', 'f1/f2/'])
folder = (o for o in shared_objects if o['name'] == 'f1/f2').next()
self.assertTrue('x_object_sharing' in folder)
self.assertTrue(folder['x_object_sharing'] == 'write=*')
r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&' % url)
self.assertEqual(r.status_code, 200)
shared_objects = r.content.split('\n')
if '' in shared_objects:
shared_objects.remove('')
self.assertEqual(shared_objects, ['f1/f2/f3', 'f1/f2/f3/'])
r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&format=json' % url)
self.assertEqual(r.status_code, 200)
shared_objects = [i.get('name', i.get('subdir')) for i in
json.loads(r.content)]
self.assertEqual(shared_objects, ['f1/f2', 'f1/f2/'])
self.assertEqual(shared_objects, ['f1/f2/f3', 'f1/f2/f3/'])
r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&format=json' % url)
r = self.get('%s?delimiter=/&prefix=f1/f2/f3&shared=&' % url)
self.assertEqual(r.status_code, 200)
shared_objects = r.content.split('\n')
if '' in shared_objects:
shared_objects.remove('')
self.assertEqual(shared_objects, ['f1/f2/f3/obj'])
r = self.get('%s?delimiter=/&prefix=f1/f2/f3&shared=&format=json' %
url)
self.assertEqual(r.status_code, 200)
shared_objects = [i.get('name', i.get('subdir')) for i in
json.loads(r.content)]
self.assertEqual(shared_objects, ['f1/f2/obj'])
self.assertEqual(shared_objects, ['f1/f2/f3/obj'])
def test_list_shared_by_me(self):
self._build_structure()
......@@ -126,20 +170,63 @@ class ListSharing(PithosAPITest):
self.assertEqual([i['name'] for i in shared_containers], ['c0'])
url = join_urls(url, 'c0')
r = self.get('%s?delimiter=/&shared=&format=json' % url)
r = self.get('%s?delimiter=/&shared=&' % url)
self.assertEqual(r.status_code, 200)
shared_objects = [i.get('name', i.get('subdir')) for i in
json.loads(r.content)]
shared_objects = r.content.split('\n')
if '' in shared_objects:
shared_objects.remove('')
self.assertEqual(shared_objects, ['f1', 'f1/'])
r = self.get('%s?delimiter=/&shared=&format=json' % url)
self.assertEqual(r.status_code, 200)
shared_objects = json.loads(r.content)
self.assertEqual([o.get('name', o.get('subdir')) for
o in shared_objects],
['f1', 'f1/'])
folder = (o for o in shared_objects if o['name'] == 'f1').next()
self.assertTrue('x_object_sharing' in folder)
self.assertTrue(folder['x_object_sharing'] == 'read=*')
r = self.get('%s?delimiter=/&prefix=f1&shared=&' % url)
self.assertEqual(r.status_code, 200)
shared_objects = r.content.split('\n')
if '' in shared_objects:
shared_objects.remove('')
self.assertEqual(shared_objects, ['f1/f2', 'f1/f2/'])
r = self.get('%s?delimiter=/&prefix=f1&shared=&format=json' % url)
self.assertEqual(r.status_code, 200)
shared_objects = json.loads(r.content)
self.assertEqual([o.get('name', o.get('subdir')) for
o in shared_objects],
['f1/f2', 'f1/f2/'])
folder = (o for o in shared_objects if o['name'] == 'f1/f2').next()
self.assertTrue('x_object_sharing' in folder)
self.assertTrue(folder['x_object_sharing'] == 'write=*')
r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&' % url)
self.assertEqual(r.status_code, 200)
shared_objects = r.content.split('\n')
if '' in shared_objects:
shared_objects.remove('')
self.assertEqual(shared_objects, ['f1/f2/f3', 'f1/f2/f3/'])
r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&format=json' % url)
self.assertEqual(r.status_code, 200)
shared_objects = [i.get('name', i.get('subdir')) for i in
json.loads(r.content)]
self.assertEqual(shared_objects, ['f1/f2', 'f1/f2/'])
self.assertEqual(shared_objects, ['f1/f2/f3', 'f1/f2/f3/'])
r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&format=json' % url)
r = self.get('%s?delimiter=/&prefix=f1/f2/f3&shared=&' % url)
self.assertEqual(r.status_code, 200)
shared_objects = r.content.split('\n')
if '' in shared_objects:
shared_objects.remove('')
self.assertEqual(shared_objects, ['f1/f2/f3/obj'])
r = self.get('%s?delimiter=/&prefix=f1/f2/f3&shared=&format=json' %
url)
self.assertEqual(r.status_code, 200)
shared_objects = [i.get('name', i.get('subdir')) for i in
json.loads(r.content)]
self.assertEqual(shared_objects, ['f1/f2/obj'])
self.assertEqual(shared_objects, ['f1/f2/f3/obj'])
......@@ -884,9 +884,11 @@ class ModularBackend(BaseBackend):
user)
#group_parents = access_objects['group_parents']
nobject_permissions = {}
cpath = '/'.join((account, container, ''))
cpath_idx = len(cpath)
for path in permissions_path:
allowed = 1
name = path.split('/')[-1]
name = path[cpath_idx:]
if user != account:
try:
allowed = access_objects[path]
......@@ -1723,8 +1725,7 @@ class ModularBackend(BaseBackend):
for prop in props:
if prop[1].split(';', 1)[0].strip() in (
'application/directory', 'application/folder'):
permission_paths_list.append((
prop[0].rstrip('/') + '/', self.MATCH_PREFIX))
permission_paths_list.append(prop[0])
if len(permission_paths_list) > 0:
return permission_paths_list
......
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