Validate UUIDs before the driver sends them
Redis driver does not always validate UUIDs (claim ID, message ID and client_uuid). This commit introduces validation of them before the driver sends them. Closes-Bug: #1367024 Change-Id: I08eaa7df1f6887224edd0a3324ee4e5db3f6c229
This commit is contained in:
parent
0a2d30f770
commit
6c4bb628be
|
@ -50,14 +50,16 @@ class MessageEnvelope(object):
|
|||
]
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.id = kwargs.get('id', str(uuid.uuid4()))
|
||||
self.id = _validate_uuid4(kwargs.get('id', str(uuid.uuid4())))
|
||||
self.ttl = kwargs['ttl']
|
||||
self.created = kwargs['created']
|
||||
self.expires = kwargs.get('expires', self.created + self.ttl)
|
||||
|
||||
self.client_uuid = str(kwargs['client_uuid'])
|
||||
self.client_uuid = _validate_uuid4(str(kwargs['client_uuid']))
|
||||
|
||||
self.claim_id = kwargs.get('claim_id')
|
||||
if self.claim_id:
|
||||
_validate_uuid4(self.claim_id)
|
||||
self.claim_expires = kwargs['claim_expires']
|
||||
|
||||
@staticmethod
|
||||
|
@ -309,3 +311,8 @@ def _subenv_to_hmap(msg):
|
|||
'e': msg.expires,
|
||||
'o': msg.options
|
||||
}
|
||||
|
||||
|
||||
def _validate_uuid4(_uuid):
|
||||
uuid.UUID(str(_uuid), version=4)
|
||||
return _uuid
|
||||
|
|
|
@ -353,6 +353,16 @@ class RedisMessagesTest(base.MessageControllerTest):
|
|||
num_removed = self.controller.gc()
|
||||
self.assertEqual(num_removed, 100)
|
||||
|
||||
def test_invalid_uuid(self):
|
||||
queue_name = 'invalid-uuid-test'
|
||||
msgs = [{
|
||||
'ttl': 300,
|
||||
'body': 'di mo fy'
|
||||
}]
|
||||
client_id = "invalid_uuid"
|
||||
self.controller.post(queue_name, msgs, client_id)
|
||||
self.assertRaises(ValueError, self.controller.first, queue_name)
|
||||
|
||||
|
||||
@testing.requires_redis
|
||||
class RedisClaimsTest(base.ClaimControllerTest):
|
||||
|
|
Loading…
Reference in New Issue