Use NULL as creator in ResourceUUID conversion

In older versions of Gnocchi, the creator could be null. It's unlikely now as
all auth helper returns a string as creator, but it's still possible in theory.
This patch uses the NULL string as the creator is it's None (so NULL in SQL).

Change-Id: Id1faa16512b995fa2cd24ca4bed7912934cb5aad
Closes-Bug: #1684246
(cherry picked from commit 75e4206731)
This commit is contained in:
Julien Danjou 2017-04-20 08:45:14 +02:00
parent e786537802
commit 89c9170731
2 changed files with 21 additions and 0 deletions

View File

@ -13,6 +13,7 @@
# under the License.
import datetime
import os
import uuid
import iso8601
import mock
@ -57,3 +58,21 @@ class TestUtils(tests_base.TestCase):
utils.to_datetime(utils.to_timestamp(1425652440.4)),
datetime.datetime(2015, 3, 6, 14, 34, 0, 400000,
tzinfo=iso8601.iso8601.UTC))
class TestResourceUUID(tests_base.TestCase):
def test_conversion(self):
self.assertEqual(
uuid.UUID('ba571521-1de6-5aff-b183-1535fd6eb5d0'),
utils.ResourceUUID(
uuid.UUID('ba571521-1de6-5aff-b183-1535fd6eb5d0'),
"bar"))
self.assertEqual(
uuid.UUID('ba571521-1de6-5aff-b183-1535fd6eb5d0'),
utils.ResourceUUID("foo", "bar"))
self.assertEqual(
uuid.UUID('4efb21f6-3d19-5fe3-910b-be8f0f727846'),
utils.ResourceUUID("foo", None))
self.assertEqual(
uuid.UUID('853e5c64-f45e-58b2-999c-96df856fbe3d'),
utils.ResourceUUID("foo", ""))

View File

@ -48,6 +48,8 @@ def ResourceUUID(value, creator):
return uuid.UUID(value)
except ValueError:
if len(value) <= 255:
if creator is None:
creator = "\x00"
# value/creator must be str (unicode) in Python 3 and str (bytes)
# in Python 2. It's not logical, I know.
if six.PY2: