Skip to content

Commit

Permalink
Create default bucket uuid with dashes - Fixes #120
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémy HUBSCHER committed Jul 6, 2015
1 parent eade34e commit ba9a02a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions kinto/tests/test_default_bucket.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import uuid
from uuid import UUID
from .support import (BaseWebTest, unittest, get_user_headers,
MINIMALIST_RECORD)

Expand All @@ -15,7 +15,7 @@ def test_default_bucket_exists_and_has_user_id(self):
result = bucket.json
settings = self.app.app.registry.settings
hmac_secret = settings['cliquet.userid_hmac_secret']
bucket_id = hmac_digest(hmac_secret, self.principal)[:32]
bucket_id = '%s' % UUID(hmac_digest(hmac_secret, self.principal)[:32])

self.assertEqual(result['data']['id'], bucket_id)
self.assertEqual(result['permissions']['write'], [self.principal])
Expand All @@ -40,7 +40,7 @@ def test_bucket_id_is_an_uuid(self):
bucket = self.app.get(self.bucket_url, headers=self.headers)
bucket_id = bucket.json['data']['id']
try:
uuid.UUID(bucket_id)
UUID(bucket_id)
except ValueError:
self.fail('bucket_id: %s is not a valid UUID.' % bucket_id)

Expand Down
5 changes: 4 additions & 1 deletion kinto/views/buckets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from uuid import UUID

from pyramid.httpexceptions import HTTPForbidden, HTTPPreconditionFailed
from pyramid.security import NO_PERMISSION_REQUIRED
from pyramid.view import view_config
Expand Down Expand Up @@ -57,7 +59,8 @@ def default_bucket(request):
settings = request.registry.settings
hmac_secret = settings['cliquet.userid_hmac_secret']
# Build the user unguessable bucket_id UUID from its user_id
bucket_id = hmac_digest(hmac_secret, request.prefixed_userid)[:32]
bucket_id = '%s' % UUID(hmac_digest(hmac_secret,
request.prefixed_userid)[:32])
path = request.path.replace('default', bucket_id)
querystring = request.url[(request.url.index(request.path) +
len(request.path)):]
Expand Down

0 comments on commit ba9a02a

Please sign in to comment.