Esempio n. 1
0
def test_verify_signature_nested():
    data = {'a': 'A',
            'b': 'B',
            'nested': {'a': 'A',
                       'b': 'B',
                       },
            }
    data['message_signature'] = meter.compute_signature(data, 'not-so-secret')
    assert meter.verify_signature(data, 'not-so-secret')
Esempio n. 2
0
def test_verify_signature_nested():
    data = {
        'a': 'A',
        'b': 'B',
        'nested': {
            'a': 'A',
            'b': 'B',
        },
    }
    data['message_signature'] = meter.compute_signature(data, 'not-so-secret')
    assert meter.verify_signature(data, 'not-so-secret')
Esempio n. 3
0
def test_verify_signature_nested_json():
    data = {'a': 'A',
            'b': 'B',
            'nested': {'a': 'A',
                       'b': 'B',
                       'c': ('c',),
                       'd': ['d']
                       },
            }
    data['message_signature'] = meter.compute_signature(data, 'not-so-secret')
    jsondata = jsonutils.loads(jsonutils.dumps(data))
    assert meter.verify_signature(jsondata, 'not-so-secret')
Esempio n. 4
0
def test_verify_signature_nested_json():
    data = {
        'a': 'A',
        'b': 'B',
        'nested': {
            'a': 'A',
            'b': 'B',
            'c': ('c', ),
            'd': ['d']
        },
    }
    data['message_signature'] = meter.compute_signature(data, 'not-so-secret')
    jsondata = jsonutils.loads(jsonutils.dumps(data))
    assert meter.verify_signature(jsondata, 'not-so-secret')
Esempio n. 5
0
    def test_valid_message(self):
        msg = {'counter_name': 'test',
               'resource_id': self.id(),
               'counter_volume': 1,
               }
        msg['message_signature'] = meter.compute_signature(
            msg,
            cfg.CONF.metering_secret,
        )

        self.srv.storage_conn = self.mox.CreateMock(base.Connection)
        self.srv.storage_conn.record_metering_data(msg)
        self.mox.ReplayAll()

        self.srv.record_metering_data(self.ctx, msg)
        self.mox.VerifyAll()
Esempio n. 6
0
    def test_valid_message(self):
        msg = {
            'counter_name': 'test',
            'resource_id': self.id(),
            'counter_volume': 1,
        }
        msg['message_signature'] = meter.compute_signature(
            msg,
            cfg.CONF.metering_secret,
        )

        self.srv.storage_conn = self.mox.CreateMock(base.Connection)
        self.srv.storage_conn.record_metering_data(msg)
        self.mox.ReplayAll()

        self.srv.record_metering_data(self.ctx, msg)
        self.mox.VerifyAll()
Esempio n. 7
0
    def test_timestamp_conversion(self):
        msg = {'counter_name': 'test',
               'resource_id': self.id(),
               'counter_volume': 1,
               'timestamp': '2012-07-02T13:53:40Z',
               }
        msg['message_signature'] = meter.compute_signature(
            msg,
            cfg.CONF.metering_secret,
        )

        expected = {}
        expected.update(msg)
        expected['timestamp'] = datetime(2012, 7, 2, 13, 53, 40)

        self.srv.storage_conn = self.mox.CreateMock(base.Connection)
        self.srv.storage_conn.record_metering_data(expected)
        self.mox.ReplayAll()

        self.srv.record_metering_data(self.ctx, msg)
        self.mox.VerifyAll()
Esempio n. 8
0
    def test_timestamp_tzinfo_conversion(self):
        msg = {'counter_name': 'test',
               'resource_id': self.id(),
               'counter_volume': 1,
               'timestamp': '2012-09-30T15:31:50.262-08:00',
               }
        msg['message_signature'] = meter.compute_signature(
            msg,
            cfg.CONF.metering_secret,
        )

        expected = {}
        expected.update(msg)
        expected['timestamp'] = datetime(2012, 9, 30, 23, 31, 50, 262000)

        self.srv.storage_conn = self.mox.CreateMock(base.Connection)
        self.srv.storage_conn.record_metering_data(expected)
        self.mox.ReplayAll()

        self.srv.record_metering_data(self.ctx, msg)
        self.mox.VerifyAll()
Esempio n. 9
0
    def test_timestamp_tzinfo_conversion(self):
        msg = {
            'counter_name': 'test',
            'resource_id': self.id(),
            'counter_volume': 1,
            'timestamp': '2012-09-30T15:31:50.262-08:00',
        }
        msg['message_signature'] = meter.compute_signature(
            msg,
            cfg.CONF.metering_secret,
        )

        expected = {}
        expected.update(msg)
        expected['timestamp'] = datetime(2012, 9, 30, 23, 31, 50, 262000)

        self.srv.storage_conn = self.mox.CreateMock(base.Connection)
        self.srv.storage_conn.record_metering_data(expected)
        self.mox.ReplayAll()

        self.srv.record_metering_data(self.ctx, msg)
        self.mox.VerifyAll()
Esempio n. 10
0
    def test_timestamp_conversion(self):
        msg = {
            'counter_name': 'test',
            'resource_id': self.id(),
            'counter_volume': 1,
            'timestamp': '2012-07-02T13:53:40Z',
        }
        msg['message_signature'] = meter.compute_signature(
            msg,
            cfg.CONF.metering_secret,
        )

        expected = {}
        expected.update(msg)
        expected['timestamp'] = datetime(2012, 7, 2, 13, 53, 40)

        self.srv.storage_conn = self.mox.CreateMock(base.Connection)
        self.srv.storage_conn.record_metering_data(expected)
        self.mox.ReplayAll()

        self.srv.record_metering_data(self.ctx, msg)
        self.mox.VerifyAll()
Esempio n. 11
0
def test_compute_signature_change_value():
    sig1 = meter.compute_signature({'a': 'A', 'b': 'B'}, 'not-so-secret')
    sig2 = meter.compute_signature({'a': 'a', 'b': 'B'}, 'not-so-secret')
    assert sig1 != sig2
Esempio n. 12
0
def test_compute_signature_change_value():
    sig1 = meter.compute_signature({'a': 'A', 'b': 'B'}, 'not-so-secret')
    sig2 = meter.compute_signature({'a': 'a', 'b': 'B'}, 'not-so-secret')
    assert sig1 != sig2
Esempio n. 13
0
def test_compute_signature_same():
    sig1 = meter.compute_signature({'a': 'A', 'b': 'B'}, 'not-so-secret')
    sig2 = meter.compute_signature({'a': 'A', 'b': 'B'}, 'not-so-secret')
    assert sig1 == sig2
Esempio n. 14
0
def test_compute_signature_use_configured_secret():
    data = {'a': 'A', 'b': 'B'}
    sig1 = meter.compute_signature(data, 'not-so-secret')
    sig2 = meter.compute_signature(data, 'different-value')
    assert sig1 != sig2
Esempio n. 15
0
def test_verify_signature_signed():
    data = {'a': 'A', 'b': 'B'}
    sig1 = meter.compute_signature(data, 'not-so-secret')
    data['message_signature'] = sig1
    assert meter.verify_signature(data, 'not-so-secret')
Esempio n. 16
0
def test_compute_signature_signed():
    data = {'a': 'A', 'b': 'B'}
    sig1 = meter.compute_signature(data, 'not-so-secret')
    data['message_signature'] = sig1
    sig2 = meter.compute_signature(data, 'not-so-secret')
    assert sig1 == sig2
Esempio n. 17
0
def test_compute_signature_same():
    sig1 = meter.compute_signature({'a': 'A', 'b': 'B'}, 'not-so-secret')
    sig2 = meter.compute_signature({'a': 'A', 'b': 'B'}, 'not-so-secret')
    assert sig1 == sig2
Esempio n. 18
0
def test_compute_signature_signed():
    data = {'a': 'A', 'b': 'B'}
    sig1 = meter.compute_signature(data, 'not-so-secret')
    data['message_signature'] = sig1
    sig2 = meter.compute_signature(data, 'not-so-secret')
    assert sig1 == sig2
Esempio n. 19
0
def test_compute_signature_use_configured_secret():
    data = {'a': 'A', 'b': 'B'}
    sig1 = meter.compute_signature(data, 'not-so-secret')
    sig2 = meter.compute_signature(data, 'different-value')
    assert sig1 != sig2
Esempio n. 20
0
def test_verify_signature_signed():
    data = {'a': 'A', 'b': 'B'}
    sig1 = meter.compute_signature(data, 'not-so-secret')
    data['message_signature'] = sig1
    assert meter.verify_signature(data, 'not-so-secret')