def test_delete_contents(self): folder = self.create_folder('c1')[0] for i in range(11): descendant = '%s_%d' % (strnextling(folder), i) self.upload_object('c1', descendant) self.create_folder('c1', '%s/%s' % (folder, get_random_data(5)))[0] r = self.delete('%s?delimiter=/' % join_urls( self.pithos_path, self.user, 'c1')) self.assertEqual(r.status_code, 204) self.assertEqual([], self.list_objects('c1')) self.assertTrue('c1' in self.list_containers(format=None))
def test_list_shared_public(self): cname = self.cnames[0] container_url = join_urls(self.pithos_path, self.user, cname) onames = self.objects[cname].keys() r = self.get('%s?shared=&public=&format=json' % container_url) self.assertEqual(r.status_code, 200) objects = json.loads(r.content) self.assertEqual(len(objects), 0) # publish an object public1 = onames.pop() url = join_urls(container_url, public1) r = self.post(url, content_type='', HTTP_X_OBJECT_PUBLIC='true') self.assertEqual(r.status_code, 202) r = self.get('%s?shared=&public=&format=json' % container_url) self.assertEqual(r.status_code, 200) objects = json.loads(r.content) self.assertEqual(len(objects), 1) self.assertEqual(objects[0]['name'], public1) self.assertEqual(objects[0]['bytes'], len(self.objects[cname][public1])) self.assertTrue('x_object_public' in objects[0]) # publish another public2 = onames.pop() url = join_urls(container_url, public2) r = self.post(url, content_type='', HTTP_X_OBJECT_PUBLIC='true') self.assertEqual(r.status_code, 202) # share an object shared1 = onames.pop() url = join_urls(container_url, shared1) r = self.post(url, content_type='', HTTP_X_OBJECT_SHARING='read=alice') self.assertEqual(r.status_code, 202) # share another shared2 = onames.pop() url = join_urls(container_url, shared2) r = self.post(url, content_type='', HTTP_X_OBJECT_SHARING='read=alice') self.assertEqual(r.status_code, 202) # list shared and public objects and assert object is listed r = self.get('%s?shared=&public=&format=json' % container_url) self.assertEqual(r.status_code, 200) objects = json.loads(r.content) l = sorted([public1, public2, shared1, shared2]) i = 0 for name in l: self.assertEqual(objects[i]['name'], name) self.assertEqual(objects[i]['bytes'], len(self.objects[cname][name])) self.assertTrue('x_object_sharing' in objects[i] or 'x_object_public' in objects[i]) i += 1 # assert not listing shared and public to a not shared user r = self.get('%s?shared=&public=&format=json' % container_url, user='******') self.assertEqual(r.status_code, 403) # assert not listing public to a shared user r = self.get('%s?shared=&public=&format=json' % container_url, user='******') self.assertEqual(r.status_code, 403) # create child object descendant = strnextling(public1) self.upload_object(cname, descendant) # request public and assert child object is not listed r = self.get('%s?shared=&public=' % container_url) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertEqual(r.status_code, 200) self.assertEqual(objects, l) # test folder inheritance folder, _ = self.create_folder(cname, HTTP_X_OBJECT_PUBLIC='true') # create child object descendant = '%s/%s' % (folder, get_random_name()) self.upload_object(cname, descendant) # request public r = self.get('%s?shared=&public=' % container_url) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertTrue(folder in objects) self.assertTrue(descendant not in objects) # unpublish public1 url = join_urls(container_url, public1) r = self.post(url, content_type='', HTTP_X_OBJECT_PUBLIC='false') self.assertEqual(r.status_code, 202) # unpublish public2 url = join_urls(container_url, public2) r = self.post(url, content_type='', HTTP_X_OBJECT_PUBLIC='false') self.assertEqual(r.status_code, 202) # unpublish folder url = join_urls(container_url, folder) r = self.post(url, content_type='', HTTP_X_OBJECT_PUBLIC='false') self.assertEqual(r.status_code, 202) r = self.get('%s?shared=&public=' % container_url) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') if '' in objects: objects.remove('') l = sorted([shared1, shared2]) self.assertEqual(objects, l)
def test_list_public(self): cname = self.cnames[0] onames = self.objects[cname].keys() # publish an object public1 = onames.pop() url = join_urls(self.pithos_path, self.user, cname, public1) r = self.post(url, content_type='', HTTP_X_OBJECT_PUBLIC='true') self.assertEqual(r.status_code, 202) # publish another public2 = onames.pop() url = join_urls(self.pithos_path, self.user, cname, public2) r = self.post(url, content_type='', HTTP_X_OBJECT_PUBLIC='true') self.assertEqual(r.status_code, 202) # share an object shared1 = onames.pop() url = join_urls(self.pithos_path, self.user, cname, shared1) r = self.post(url, content_type='', HTTP_X_OBJECT_SHARING='read=alice') self.assertEqual(r.status_code, 202) # share another shared2 = onames.pop() url = join_urls(self.pithos_path, self.user, cname, shared2) r = self.post(url, content_type='', HTTP_X_OBJECT_SHARING='read=alice') self.assertEqual(r.status_code, 202) # list public and assert only the public object is returned url = join_urls(self.pithos_path, self.user, cname) r = self.get('%s?public=' % url) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertEqual(sorted([public1, public2]), objects) # list detailed public and assert only the public object is returned url = join_urls(self.pithos_path, self.user, cname) r = self.get('%s?public=&format=json' % url) self.assertEqual(r.status_code, 200) try: objects = json.loads(r.content) except: self.fail('json format expected') l = sorted([public1, public2]) i = 0 for name in l: self.assertEqual(objects[i]['name'], name) self.assertEqual(objects[i]['bytes'], len(self.objects[cname][name])) self.assertTrue('x_object_sharing' not in objects[i]) self.assertTrue('x_object_public' in objects[i]) i += 1 # share the public object and assert it is still listed in the # public objects url = join_urls(self.pithos_path, self.user, cname, public1) r = self.post(url, content_type='', HTTP_X_OBJECT_SHARING='read=alice') self.assertEqual(r.status_code, 202) url = join_urls(self.pithos_path, self.user, cname) r = self.get('%s?public=&format=json' % url) self.assertEqual(r.status_code, 200) try: objects = json.loads(r.content) except: self.fail('json format expected') i = 0 for name in l: self.assertEqual(objects[i]['name'], name) self.assertEqual(objects[i]['bytes'], len(self.objects[cname][name])) if name == public1: self.assertTrue('x_object_sharing' in objects[i]) else: self.assertTrue('x_object_sharing' not in objects[i]) i += 1 url = join_urls(self.pithos_path, self.user, cname) # Assert listing the container public contents is forbidden to not # shared users r = self.get('%s?public=&format=json' % url, user='******') self.assertEqual(r.status_code, 403) # Assert forbidden public object listing to shared users r = self.get('%s?public=&format=json' % url, user='******') self.assertEqual(r.status_code, 403) # create child object descendant = strnextling(public1) self.upload_object(cname, descendant) # request public and assert child obejct is not listed r = self.get('%s?public=' % url) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertEqual(r.status_code, 200) self.assertTrue(public1 in objects) self.assertTrue(descendant not in objects) # test folder inheritance folder, _ = self.create_folder(cname, HTTP_X_OBJECT_PUBLIC='true') # create child object descendant = '%s/%s' % (folder, get_random_name()) self.upload_object(cname, descendant) # request public r = self.get('%s?public=' % url) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') self.assertTrue(folder in objects) self.assertTrue(descendant not in objects)
def test_list_shared(self): # share an object cname = self.cnames[0] onames = self.objects[cname].keys() shared1 = onames.pop() url = join_urls(self.pithos_path, self.user, cname, shared1) r = self.post(url, content_type='', HTTP_X_OBJECT_SHARING='read=*') self.assertEqual(r.status_code, 202) # share another object shared2 = onames.pop() url = join_urls(self.pithos_path, self.user, cname, shared2) r = self.post(url, content_type='', HTTP_X_OBJECT_SHARING='read=*') self.assertEqual(r.status_code, 202) # publish another object public1 = onames.pop() url = join_urls(self.pithos_path, self.user, cname, public1) r = self.post(url, content_type='', HTTP_X_OBJECT_PUBLIC='true') self.assertEqual(r.status_code, 202) # publish another object public2 = onames.pop() url = join_urls(self.pithos_path, self.user, cname, public2) r = self.post(url, content_type='', HTTP_X_OBJECT_PUBLIC='true') self.assertEqual(r.status_code, 202) # list shared and assert only the shared object is returned url = join_urls(self.pithos_path, self.user, cname) r = self.get('%s?shared=' % url) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertEqual(sorted([shared1, shared2]), objects) # list detailed shared and assert only the shared object is returned url = join_urls(self.pithos_path, self.user, cname) r = self.get('%s?shared=&format=json' % url) self.assertEqual(r.status_code, 200) try: objects = json.loads(r.content) except: self.fail('json format expected') l = sorted([shared1, shared2]) i = 0 for name in l: self.assertEqual(objects[i]['name'], name) self.assertEqual(objects[i]['bytes'], len(self.objects[cname][name])) self.assertTrue('x_object_sharing' in objects[i]) self.assertTrue('x_object_public' not in objects[i]) i += 1 # publish the shared object and assert it is still listed in the # shared objects url = join_urls(self.pithos_path, self.user, cname, shared1) r = self.post(url, content_type='', HTTP_X_OBJECT_PUBLIC='true') self.assertEqual(r.status_code, 202) url = join_urls(self.pithos_path, self.user, cname) r = self.get('%s?shared=&format=json' % url) self.assertEqual(r.status_code, 200) try: objects = json.loads(r.content) except: self.fail('json format expected') i = 0 for name in l: self.assertEqual(objects[i]['name'], name) self.assertEqual(objects[i]['bytes'], len(self.objects[cname][name])) self.assertTrue('x_object_sharing' in objects[i]) if name == shared1: self.assertTrue('x_object_public' in objects[i]) else: self.assertTrue('x_object_public' not in objects[i]) i += 1 # create child object descendant = strnextling(shared1) self.upload_object(cname, descendant) # request shared and assert child obejct is not listed url = join_urls(self.pithos_path, self.user, cname) r = self.get('%s?shared=' % url) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertTrue(shared1 in objects) self.assertTrue(descendant not in objects) # check folder inheritance folder, _ = self.create_folder(cname, HTTP_X_OBJECT_SHARING='read=*') # create child object descendant = '%s/%s' % (folder, get_random_name()) self.upload_object(cname, descendant) # request shared url = join_urls(self.pithos_path, self.user, cname) r = self.get('%s?shared=' % url) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertTrue(folder in objects) self.assertTrue(descendant in objects)