diff options
author | Ilya Tyaptin <ityaptin@mirantis.com> | 2014-11-11 17:17:04 +0400 |
---|---|---|
committer | Eoghan Glynn <eglynn@redhat.com> | 2014-11-27 17:01:12 +0000 |
commit | ca52652e5a14f2332bd91b0c5a57e98af872c8db (patch) | |
tree | a4f8f92fc41282972391661929321dcfbe412baa | |
parent | 0cce6021a1f4b01bf8307bbfef7a9279ce43144b (diff) | |
download | ceilometer-ca52652e5a14f2332bd91b0c5a57e98af872c8db.tar.gz |
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
(cherry picked from commit 05276690525d76e18769712bc66d0cd535b11f18)
-rw-r--r-- | ceilometer/publisher/utils.py | 2 | ||||
-rw-r--r-- | ceilometer/tests/publisher/test_utils.py | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/ceilometer/publisher/utils.py b/ceilometer/publisher/utils.py index 0a8e89cd..2974276b 100644 --- a/ceilometer/publisher/utils.py +++ b/ceilometer/publisher/utils.py @@ -55,7 +55,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 479fc5c9..b4b1b67d 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" |