From 05276690525d76e18769712bc66d0cd535b11f18 Mon Sep 17 00:00:00 2001 From: Ilya Tyaptin Date: Tue, 11 Nov 2014 17:17:04 +0400 Subject: [PATCH] Add encoding to keys in compute_signature Unlike fixed sample keys as counter_name and counter_volume, metadata keys may contain unicode characters. ceilometer.publisher.utils.compute_signature can't calculate signature of unicode symbols and crashes. In this patch encoding keys is added. Change-Id: I94d02ce20999510e9c6aaf33f7ee503bbb350e87 Closes-bug: #1391517 --- ceilometer/publisher/utils.py | 2 +- ceilometer/tests/publisher/test_utils.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ceilometer/publisher/utils.py b/ceilometer/publisher/utils.py index 72204a5e2..5c16636e1 100644 --- a/ceilometer/publisher/utils.py +++ b/ceilometer/publisher/utils.py @@ -48,7 +48,7 @@ def compute_signature(message, secret): # Skip any existing signature value, which would not have # been part of the original message. continue - digest_maker.update(name) + digest_maker.update(six.text_type(name).encode('utf-8')) digest_maker.update(six.text_type(value).encode('utf-8')) return digest_maker.hexdigest() diff --git a/ceilometer/tests/publisher/test_utils.py b/ceilometer/tests/publisher/test_utils.py index 479fc5c9d..b4b1b67dd 100644 --- a/ceilometer/tests/publisher/test_utils.py +++ b/ceilometer/tests/publisher/test_utils.py @@ -111,6 +111,16 @@ class TestSignature(base.BaseTestCase): jsondata = jsonutils.loads(jsonutils.dumps(data)) self.assertTrue(utils.verify_signature(jsondata, 'not-so-secret')) + def test_verify_unicode_symbols(self): + data = {u'a\xe9\u0437': 'A', + 'b': u'B\xe9\u0437' + } + data['message_signature'] = utils.compute_signature( + data, + 'not-so-secret') + jsondata = jsonutils.loads(jsonutils.dumps(data)) + self.assertTrue(utils.verify_signature(jsondata, 'not-so-secret')) + def test_besteffort_compare_digest(self): hash1 = "f5ac3fe42b80b80f979825d177191bc5" hash2 = "f5ac3fe42b80b80f979825d177191bc5"