~ubuntu-branches/ubuntu/trusty/ceilometer/trusty-proposed

« back to all changes in this revision

Viewing changes to ceilometer/tests/publisher/test_utils.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, James Page, Chuck Short
  • Date: 2014-01-23 15:08:11 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20140123150811-1zaismsuyh1hcl8y
Tags: 2014.1~b2-0ubuntu1
[ James Page ]
* d/control: Add python-jsonpath-rw to BD's.
* d/p/fix-setup-requirements.patch: Bump WebOb to support < 1.4.
 (LP: #1261101)

[ Chuck Short ]
* New upstream version.
* debian/control, debian/ceilometer-common.install: Split out
  ceilometer-alarm-evaluator and ceilometer-alarm-notifier into their
  own packages. (LP: #1250002)
* debian/ceilometer-agent-central.logrotate,
  debian/ceilometer-agent-compute.logrotate,
  debian/ceilometer-api.logrotate,
  debian/ceilometer-collector.logrotate: Add logrotate files, 
  thanks to Ahmed Rahal. (LP: #1224223)
* Fix typos in upstart files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
#
 
3
# Copyright © 2012 New Dream Network, LLC (DreamHost)
 
4
#
 
5
# Author: Doug Hellmann <doug.hellmann@dreamhost.com>
 
6
#         Julien Danjou <julien@danjou.info>
 
7
#         Tyaptin Ilya <ityaptin@mirantis.com>
 
8
#
 
9
# Licensed under the Apache License, Version 2.0 (the "License"); you may
 
10
# not use this file except in compliance with the License. You may obtain
 
11
# a copy of the License at
 
12
#
 
13
#      http://www.apache.org/licenses/LICENSE-2.0
 
14
#
 
15
# Unless required by applicable law or agreed to in writing, software
 
16
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
17
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
18
# License for the specific language governing permissions and limitations
 
19
# under the License.
 
20
"""Tests for ceilometer/publisher/utils.py
 
21
"""
 
22
 
 
23
from ceilometer.openstack.common import jsonutils
 
24
from ceilometer.openstack.common import test
 
25
from ceilometer.publisher import utils
 
26
 
 
27
 
 
28
class TestSignature(test.BaseTestCase):
 
29
    def test_compute_signature_change_key(self):
 
30
        sig1 = utils.compute_signature({'a': 'A', 'b': 'B'},
 
31
                                       'not-so-secret')
 
32
        sig2 = utils.compute_signature({'A': 'A', 'b': 'B'},
 
33
                                       'not-so-secret')
 
34
        self.assertNotEqual(sig1, sig2)
 
35
 
 
36
    def test_compute_signature_change_value(self):
 
37
        sig1 = utils.compute_signature({'a': 'A', 'b': 'B'},
 
38
                                       'not-so-secret')
 
39
        sig2 = utils.compute_signature({'a': 'a', 'b': 'B'},
 
40
                                       'not-so-secret')
 
41
        self.assertNotEqual(sig1, sig2)
 
42
 
 
43
    def test_compute_signature_same(self):
 
44
        sig1 = utils.compute_signature({'a': 'A', 'b': 'B'},
 
45
                                       'not-so-secret')
 
46
        sig2 = utils.compute_signature({'a': 'A', 'b': 'B'},
 
47
                                       'not-so-secret')
 
48
        self.assertEqual(sig1, sig2)
 
49
 
 
50
    def test_compute_signature_signed(self):
 
51
        data = {'a': 'A', 'b': 'B'}
 
52
        sig1 = utils.compute_signature(data, 'not-so-secret')
 
53
        data['message_signature'] = sig1
 
54
        sig2 = utils.compute_signature(data, 'not-so-secret')
 
55
        self.assertEqual(sig1, sig2)
 
56
 
 
57
    def test_compute_signature_use_configured_secret(self):
 
58
        data = {'a': 'A', 'b': 'B'}
 
59
        sig1 = utils.compute_signature(data, 'not-so-secret')
 
60
        sig2 = utils.compute_signature(data, 'different-value')
 
61
        self.assertNotEqual(sig1, sig2)
 
62
 
 
63
    def test_verify_signature_signed(self):
 
64
        data = {'a': 'A', 'b': 'B'}
 
65
        sig1 = utils.compute_signature(data, 'not-so-secret')
 
66
        data['message_signature'] = sig1
 
67
        self.assertTrue(utils.verify_signature(data, 'not-so-secret'))
 
68
 
 
69
    def test_verify_signature_unsigned(self):
 
70
        data = {'a': 'A', 'b': 'B'}
 
71
        self.assertFalse(utils.verify_signature(data, 'not-so-secret'))
 
72
 
 
73
    def test_verify_signature_incorrect(self):
 
74
        data = {'a': 'A', 'b': 'B',
 
75
                'message_signature': 'Not the same'}
 
76
        self.assertFalse(utils.verify_signature(data, 'not-so-secret'))
 
77
 
 
78
    def test_verify_signature_nested(self):
 
79
        data = {'a': 'A',
 
80
                'b': 'B',
 
81
                'nested': {'a': 'A',
 
82
                           'b': 'B',
 
83
                           },
 
84
                }
 
85
        data['message_signature'] = utils.compute_signature(
 
86
            data,
 
87
            'not-so-secret')
 
88
        self.assertTrue(utils.verify_signature(data, 'not-so-secret'))
 
89
 
 
90
    def test_verify_signature_nested_json(self):
 
91
        data = {'a': 'A',
 
92
                'b': 'B',
 
93
                'nested': {'a': 'A',
 
94
                           'b': 'B',
 
95
                           'c': ('c',),
 
96
                           'd': ['d']
 
97
                           },
 
98
                }
 
99
        data['message_signature'] = utils.compute_signature(
 
100
            data,
 
101
            'not-so-secret')
 
102
        jsondata = jsonutils.loads(jsonutils.dumps(data))
 
103
        self.assertTrue(utils.verify_signature(jsondata, 'not-so-secret'))