Skip to content

Commit

Permalink
Add a test for bucket_id a UUID + @leplatrem review.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémy HUBSCHER committed Jun 30, 2015
1 parent aaa43cc commit b00df84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions kinto/tests/test_default_bucket.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import uuid
from .support import (BaseWebTest, unittest, get_user_headers,
MINIMALIST_RECORD)

Expand All @@ -9,9 +10,6 @@ class DefaultBucketViewTest(BaseWebTest, unittest.TestCase):
bucket_url = '/buckets/default'
collection_url = '/buckets/default/collections/tasks'

def setUp(self):
super(DefaultBucketViewTest, self).setUp()

def test_default_bucket_exists_and_has_user_id(self):
bucket = self.app.get(self.bucket_url, headers=self.headers)
result = bucket.json
Expand All @@ -37,3 +35,11 @@ def test_unauthenticated_bucket_access_raises_json_401(self):
resp = self.app.get(self.bucket_url, status=401)
self.assertEquals(resp.json['message'],
'Please authenticate yourself to use this endpoint.')

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)
except ValueError:
self.fail('bucket_id: %s is not a valid UUID.' % bucket_id)
4 changes: 2 additions & 2 deletions kinto/views/buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

@view_config(route_name='default_bucket', permission=NO_PERMISSION_REQUIRED)
def default_bucket(request):
if (not hasattr(request, 'prefixed_userid') or
request.prefixed_userid is None):
if getattr(request, 'prefixed_userid', None) is None:
raise HTTPForbidden # Pass through the forbidden_view_config

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]
path = request.path.replace('default', bucket_id)

Expand Down

0 comments on commit b00df84

Please sign in to comment.