Merge "Fix the wrong check of X-PROJECT-ID"

This commit is contained in:
Jenkins 2016-07-04 08:19:05 +00:00 committed by Gerrit Code Review
commit 7f55ed7d3f
3 changed files with 22 additions and 6 deletions

View File

@ -15,6 +15,7 @@
"""wsgi transport helpers."""
from distutils.version import LooseVersion
import uuid
import falcon
@ -93,12 +94,12 @@ def extract_project_id(req, resp, params):
params['project_id'] = req.get_header('X-PROJECT-ID')
if params['project_id'] == "":
raise falcon.HTTPBadRequest('Empty project header not allowed',
_(u'''
X-PROJECT-ID cannot be an empty string. Specify the right header X-PROJECT-ID
and retry.'''))
_(u'X-PROJECT-ID cannot be an empty '
u'string. Specify the right header '
u'X-PROJECT-ID and retry.'))
# TODO(flaper87): Make version comparison smarter to support v2_0.
if not params['project_id'] and 'v1.1' in req.path:
api_version = LooseVersion(req.path.split('/')[1])
if not params['project_id'] and api_version >= LooseVersion('v1.1'):
raise falcon.HTTPBadRequest('Project-Id Missing',
_(u'The header X-PROJECT-ID was missing'))

View File

@ -88,7 +88,9 @@ class TestBase(testing.TestBase):
headers = kwargs.get('headers', self.headers).copy()
project_id = ('518b51ea133c4facadae42c328d6b77b' if project_id
is None else project_id)
headers['X-Project-ID'] = headers.get('X-Project-ID', project_id)
if kwargs.get('need_project_id', True):
headers['X-Project-ID'] = headers.get('X-Project-ID', project_id)
kwargs.pop('need_project_id', None)
kwargs['headers'] = headers
try:
if six.PY3:

View File

@ -55,6 +55,19 @@ class TestQueueLifecycleMongoDB(base.V2Base):
super(TestQueueLifecycleMongoDB, self).tearDown()
def test_without_project_id(self):
headers = {
'Client-ID': str(uuid.uuid4()),
}
self.simulate_put(self.gumshoe_queue_path, headers=headers,
need_project_id=False)
self.assertEqual(falcon.HTTP_400, self.srmock.status)
self.simulate_delete(self.gumshoe_queue_path, headers=headers,
need_project_id=False)
self.assertEqual(falcon.HTTP_400, self.srmock.status)
def test_empty_project_id(self):
headers = {
'Client-ID': str(uuid.uuid4()),