Make Client-ID a required header
It was decided to make Client-ID a required header. This patch adds a new `before hook` that enforces this new rule. Partially-Implements blueprint: api-v1.1-header-changes Change-Id: I7b20d56812a0dff4f8ed3e6da75b62ef7c0f307e
This commit is contained in:
parent
668ce67dfc
commit
5bf16193e7
@ -150,7 +150,8 @@ class TestInsertQueue(base.V1_1FunctionalTestBase):
|
||||
def test_insert_queue_header_asterisk(self):
|
||||
"""Insert Queue with 'Accept': '*/*'."""
|
||||
path = '/queues/asteriskinheader'
|
||||
headers = {"Accept": '*/*',
|
||||
headers = {'Accept': '*/*',
|
||||
'Client-ID': str(uuid.uuid4()),
|
||||
'X-Project-ID': '518b51ea133c4facadae42c328d6b77b'}
|
||||
self.addCleanup(self.client.delete, url=path, headers=headers)
|
||||
|
||||
|
@ -21,6 +21,7 @@ import six
|
||||
from zaqar.i18n import _
|
||||
import zaqar.openstack.common.log as logging
|
||||
from zaqar.queues.transport import validation
|
||||
from zaqar.queues.transport.wsgi import utils
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -52,6 +53,25 @@ and retry.'''))
|
||||
_(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):
|
||||
"""Hook for validating the queue name and project id in requests.
|
||||
|
||||
|
@ -64,6 +64,7 @@ class Driver(transport.DriverBase):
|
||||
"""Exposed to facilitate unit testing."""
|
||||
return [
|
||||
helpers.require_accepts_json,
|
||||
helpers.require_client_id,
|
||||
helpers.extract_project_id,
|
||||
|
||||
# NOTE(kgriffs): Depends on project_id being extracted, above
|
||||
|
@ -233,8 +233,10 @@ class QueueLifecycleBaseTest(base.V1_1Base):
|
||||
def test_list(self):
|
||||
arbitrary_number = 644079696574693
|
||||
project_id = str(arbitrary_number)
|
||||
client_id = str(uuid.uuid4())
|
||||
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
|
||||
@ -253,7 +255,7 @@ class QueueLifecycleBaseTest(base.V1_1Base):
|
||||
|
||||
# Create some
|
||||
def create_queue(name, project_id, body):
|
||||
altheader = {}
|
||||
altheader = {'Client-ID': client_id}
|
||||
if project_id is not None:
|
||||
altheader['X-Project-ID'] = project_id
|
||||
uri = self.queue_path + '/' + name
|
||||
|
Loading…
Reference in New Issue
Block a user