Commit f480a496 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki

pithos: Fix group issues

* Fix encoding issues
* Provide the appropriate tests
parent 786bb703
......@@ -17,7 +17,6 @@ from django.http import HttpResponse
from django.template.loader import render_to_string
from django.utils import simplejson as json
from django.utils.http import parse_etags
from django.utils.encoding import smart_str
from django.views.decorators.csrf import csrf_exempt
from astakosclient import AstakosClient
......@@ -650,8 +649,7 @@ def object_list(request, v_account, v_container):
keys = request.GET.get('meta')
if keys:
keys = [smart_str(x.strip()) for x in keys.split(',')
if x.strip() != '']
keys = [x.strip() for x in keys.split(',') if x.strip() != '']
included, excluded, opers = parse_filters(keys)
keys = []
keys += [format_header_key('X-Object-Meta-' + x) for x in included]
......
......@@ -345,6 +345,15 @@ class TestUnicode(PithosAPITest):
self.assertTrue('γκρουπ' in groups)
self.assertEqual(groups['γκρουπ'], 'chazapis,διογένης')
headers = {'HTTP_X_ACCOUNT_GROUP_γκρουπ': 'διογένης'}
url = join_urls(self.pithos_path, self.user)
r = self.post('%s?update=' % url, **headers)
self.assertEqual(r.status_code, 202)
groups = self.get_account_groups()
self.assertTrue('γκρουπ' in groups)
self.assertEqual(groups['γκρουπ'], 'διογένης')
# check read access
self.create_container('φάκελος')
odata = self.upload_object('φάκελος', 'ο1')[1]
......@@ -389,6 +398,40 @@ class TestUnicode(PithosAPITest):
self.assertEqual(r.status_code, 200)
self.assertEqual(r.content, odata + appended_data)
gname = ('a' * 256).capitalize()
headers = {'HTTP_X_ACCOUNT_GROUP_%s' % gname: 'β'}
url = join_urls(self.pithos_path, self.user)
r = self.post(url, **headers)
self.assertEqual(r.status_code, 202)
groups = self.get_account_groups()
self.assertTrue(gname in groups)
self.assertEqual(groups[gname], 'β')
gname = ('a' * 257).capitalize()
headers = {'HTTP_X_ACCOUNT_GROUP_%s' % gname: 'β'}
url = join_urls(self.pithos_path, self.user)
r = self.post(url, **headers)
self.assertEqual(r.status_code, 400)
def test_group_delete(self):
# create a group
headers = {'HTTP_X_ACCOUNT_GROUP_γκρουπ': 'chazapis,διογένης'}
url = join_urls(self.pithos_path, self.user)
r = self.post(url, **headers)
self.assertEqual(r.status_code, 202)
groups = self.get_account_groups()
self.assertTrue('γκρουπ' in groups)
self.assertEqual(groups['γκρουπ'], 'chazapis,διογένης')
headers = {'HTTP_X_ACCOUNT_GROUP_γκρουπ': ''}
r = self.post('%s?update=' % url, **headers)
self.assertEqual(r.status_code, 202)
groups = self.get_account_groups()
self.assertTrue('γκρουπ' not in groups)
def test_manifestation(self):
self.create_container('κουβάς')
prefix = 'μέρη/'
......
......@@ -328,7 +328,8 @@ def retrieve_displaynames(token, uuids, return_dict=False, fail_silently=True):
catalog = astakos.get_usernames(uuids) or {}
missing = list(set(uuids) - set(catalog))
if missing and not fail_silently:
raise ItemNotExists('Unknown displaynames: %s' % ', '.join(missing))
raise ItemNotExists('Unknown displaynames: %s' %
', '.join(map(smart_str, missing)))
return catalog if return_dict else [catalog.get(i) for i in uuids]
......@@ -353,7 +354,8 @@ def retrieve_uuids(token, displaynames, return_dict=False, fail_silently=True):
catalog = astakos.get_uuids(displaynames) or {}
missing = list(set(displaynames) - set(catalog))
if missing and not fail_silently:
raise ItemNotExists('Unknown uuids: %s' % ', '.join(missing))
raise ItemNotExists('Unknown uuids: %s' %
', '.join(map(smart_str, missing)))
return catalog if return_dict else [catalog.get(i) for i in displaynames]
......@@ -1073,8 +1075,8 @@ def update_request_headers(request):
v.decode('ascii')
if '%' in k or '%' in v:
del(request.META[k])
request.META[unquote(k)] = smart_unicode(unquote(
v), strings_only=True)
request.META[smart_unicode(unquote(k), strings_only=True)] = \
smart_unicode(unquote(v), strings_only=True)
except UnicodeDecodeError:
raise faults.BadRequest('Bad character in headers.')
......
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