commit e161c24fcb80bc8b10284205e3aaea717d8b5217
Author: Sofia Papagiannaki <spapagian@grnet.gr>
Date:   Fri Oct 25 18:34:37 2013 +0300

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

diff --git a/snf-pithos-app/pithos/api/test/listing.py b/snf-pithos-app/pithos/api/test/listing.py
index 5d8adcf..6c4ff2e 100644
--- a/snf-pithos-app/pithos/api/test/listing.py
+++ b/snf-pithos-app/pithos/api/test/listing.py
@@ -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'])
diff --git a/snf-pithos-backend/pithos/backends/modular.py b/snf-pithos-backend/pithos/backends/modular.py
index cbffac0..e9c711f 100644
--- a/snf-pithos-backend/pithos/backends/modular.py
+++ b/snf-pithos-backend/pithos/backends/modular.py
@@ -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
