Merge "Make Client-ID a required header"
This commit is contained in:
@@ -150,7 +150,8 @@ class TestInsertQueue(base.V1_1FunctionalTestBase):
|
|||||||
def test_insert_queue_header_asterisk(self):
|
def test_insert_queue_header_asterisk(self):
|
||||||
"""Insert Queue with 'Accept': '*/*'."""
|
"""Insert Queue with 'Accept': '*/*'."""
|
||||||
path = '/queues/asteriskinheader'
|
path = '/queues/asteriskinheader'
|
||||||
headers = {"Accept": '*/*',
|
headers = {'Accept': '*/*',
|
||||||
|
'Client-ID': str(uuid.uuid4()),
|
||||||
'X-Project-ID': '518b51ea133c4facadae42c328d6b77b'}
|
'X-Project-ID': '518b51ea133c4facadae42c328d6b77b'}
|
||||||
self.addCleanup(self.client.delete, url=path, headers=headers)
|
self.addCleanup(self.client.delete, url=path, headers=headers)
|
||||||
|
|
||||||
|
@@ -21,6 +21,7 @@ import six
|
|||||||
from zaqar.i18n import _
|
from zaqar.i18n import _
|
||||||
import zaqar.openstack.common.log as logging
|
import zaqar.openstack.common.log as logging
|
||||||
from zaqar.queues.transport import validation
|
from zaqar.queues.transport import validation
|
||||||
|
from zaqar.queues.transport.wsgi import utils
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@@ -52,6 +53,25 @@ and retry.'''))
|
|||||||
_(u'The header X-PROJECT-ID was missing'))
|
_(u'The header X-PROJECT-ID was missing'))
|
||||||
|
|
||||||
|
|
||||||
|
def require_client_id(req, resp, params):
|
||||||
|
"""Makes sure the header `Client-ID` is present in the request
|
||||||
|
|
||||||
|
Use as a before hook.
|
||||||
|
:param req: request sent
|
||||||
|
:type req: falcon.request.Request
|
||||||
|
:param resp: response object to return
|
||||||
|
:type resp: falcon.response.Response
|
||||||
|
:param params: additional parameters passed to responders
|
||||||
|
:type params: dict
|
||||||
|
:rtype: None
|
||||||
|
"""
|
||||||
|
|
||||||
|
if 'v1.1' in req.path:
|
||||||
|
# NOTE(flaper87): `get_client_uuid` already raises 400
|
||||||
|
# it the header is missing.
|
||||||
|
utils.get_client_uuid(req)
|
||||||
|
|
||||||
|
|
||||||
def validate_queue_identification(validate, req, resp, params):
|
def validate_queue_identification(validate, req, resp, params):
|
||||||
"""Hook for validating the queue name and project id in requests.
|
"""Hook for validating the queue name and project id in requests.
|
||||||
|
|
||||||
|
@@ -64,6 +64,7 @@ class Driver(transport.DriverBase):
|
|||||||
"""Exposed to facilitate unit testing."""
|
"""Exposed to facilitate unit testing."""
|
||||||
return [
|
return [
|
||||||
helpers.require_accepts_json,
|
helpers.require_accepts_json,
|
||||||
|
helpers.require_client_id,
|
||||||
helpers.extract_project_id,
|
helpers.extract_project_id,
|
||||||
|
|
||||||
# NOTE(kgriffs): Depends on project_id being extracted, above
|
# NOTE(kgriffs): Depends on project_id being extracted, above
|
||||||
|
@@ -233,8 +233,10 @@ class QueueLifecycleBaseTest(base.V1_1Base):
|
|||||||
def test_list(self):
|
def test_list(self):
|
||||||
arbitrary_number = 644079696574693
|
arbitrary_number = 644079696574693
|
||||||
project_id = str(arbitrary_number)
|
project_id = str(arbitrary_number)
|
||||||
|
client_id = str(uuid.uuid4())
|
||||||
header = {
|
header = {
|
||||||
'X-Project-ID': project_id
|
'X-Project-ID': project_id,
|
||||||
|
'Client-ID': client_id
|
||||||
}
|
}
|
||||||
|
|
||||||
# NOTE(kgriffs): It's important that this one sort after the one
|
# NOTE(kgriffs): It's important that this one sort after the one
|
||||||
@@ -253,7 +255,7 @@ class QueueLifecycleBaseTest(base.V1_1Base):
|
|||||||
|
|
||||||
# Create some
|
# Create some
|
||||||
def create_queue(name, project_id, body):
|
def create_queue(name, project_id, body):
|
||||||
altheader = {}
|
altheader = {'Client-ID': client_id}
|
||||||
if project_id is not None:
|
if project_id is not None:
|
||||||
altheader['X-Project-ID'] = project_id
|
altheader['X-Project-ID'] = project_id
|
||||||
uri = self.queue_path + '/' + name
|
uri = self.queue_path + '/' + name
|
||||||
|
Reference in New Issue
Block a user