Merge "Fix the wrong check of X-PROJECT-ID"
This commit is contained in:
commit
7f55ed7d3f
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
"""wsgi transport helpers."""
|
"""wsgi transport helpers."""
|
||||||
|
|
||||||
|
from distutils.version import LooseVersion
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
@ -93,12 +94,12 @@ def extract_project_id(req, resp, params):
|
|||||||
params['project_id'] = req.get_header('X-PROJECT-ID')
|
params['project_id'] = req.get_header('X-PROJECT-ID')
|
||||||
if params['project_id'] == "":
|
if params['project_id'] == "":
|
||||||
raise falcon.HTTPBadRequest('Empty project header not allowed',
|
raise falcon.HTTPBadRequest('Empty project header not allowed',
|
||||||
_(u'''
|
_(u'X-PROJECT-ID cannot be an empty '
|
||||||
X-PROJECT-ID cannot be an empty string. Specify the right header X-PROJECT-ID
|
u'string. Specify the right header '
|
||||||
and retry.'''))
|
u'X-PROJECT-ID and retry.'))
|
||||||
|
|
||||||
# TODO(flaper87): Make version comparison smarter to support v2_0.
|
api_version = LooseVersion(req.path.split('/')[1])
|
||||||
if not params['project_id'] and 'v1.1' in req.path:
|
if not params['project_id'] and api_version >= LooseVersion('v1.1'):
|
||||||
raise falcon.HTTPBadRequest('Project-Id Missing',
|
raise falcon.HTTPBadRequest('Project-Id Missing',
|
||||||
_(u'The header X-PROJECT-ID was missing'))
|
_(u'The header X-PROJECT-ID was missing'))
|
||||||
|
|
||||||
|
@ -88,7 +88,9 @@ class TestBase(testing.TestBase):
|
|||||||
headers = kwargs.get('headers', self.headers).copy()
|
headers = kwargs.get('headers', self.headers).copy()
|
||||||
project_id = ('518b51ea133c4facadae42c328d6b77b' if project_id
|
project_id = ('518b51ea133c4facadae42c328d6b77b' if project_id
|
||||||
is None else 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
|
kwargs['headers'] = headers
|
||||||
try:
|
try:
|
||||||
if six.PY3:
|
if six.PY3:
|
||||||
|
@ -55,6 +55,19 @@ class TestQueueLifecycleMongoDB(base.V2Base):
|
|||||||
|
|
||||||
super(TestQueueLifecycleMongoDB, self).tearDown()
|
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):
|
def test_empty_project_id(self):
|
||||||
headers = {
|
headers = {
|
||||||
'Client-ID': str(uuid.uuid4()),
|
'Client-ID': str(uuid.uuid4()),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user