예제 #1
0
def test_compute_signature_use_configured_secret():
    data = {'a': 'A', 'b': 'B'}
    sig1 = meter.compute_signature(data)
    old_secret = cfg.CONF.metering_secret
    try:
        cfg.CONF.metering_secret = 'not the default value'
        sig2 = meter.compute_signature(data)
    finally:
        cfg.CONF.metering_secret = old_secret
    assert sig1 != sig2
예제 #2
0
def test_compute_signature_use_configured_secret():
    data = {"a": "A", "b": "B"}
    sig1 = meter.compute_signature(data)
    old_secret = cfg.CONF.metering_secret
    try:
        cfg.CONF.metering_secret = "not the default value"
        sig2 = meter.compute_signature(data)
    finally:
        cfg.CONF.metering_secret = old_secret
    assert sig1 != sig2
예제 #3
0
def test_verify_signature_nested():
    data = {'a': 'A',
            'b': 'B',
            'nested': {'a': 'A',
                       'b': 'B',
                       },
            }
    data['message_signature'] = meter.compute_signature(data)
    assert meter.verify_signature(data)
예제 #4
0
def test_verify_signature_nested():
    data = {
        'a': 'A',
        'b': 'B',
        'nested': {
            'a': 'A',
            'b': 'B',
        },
    }
    data['message_signature'] = meter.compute_signature(data)
    assert meter.verify_signature(data)
예제 #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)

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

        self.mgr.record_metering_data(self.ctx, msg)
        self.mox.VerifyAll()
예제 #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)

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

        self.mgr.record_metering_data(self.ctx, msg)
        self.mox.VerifyAll()
예제 #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)

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

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

        self.mgr.record_metering_data(self.ctx, msg)
        self.mox.VerifyAll()
예제 #8
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)

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

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

        self.mgr.record_metering_data(self.ctx, msg)
        self.mox.VerifyAll()
예제 #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()
예제 #10
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
예제 #11
0
def test_compute_signature_signed():
    data = {'a': 'A', 'b': 'B'}
    sig1 = meter.compute_signature(data)
    data['message_signature'] = sig1
    sig2 = meter.compute_signature(data)
    assert sig1 == sig2
예제 #12
0
def test_verify_signature_nested():
    data = {"a": "A", "b": "B", "nested": {"a": "A", "b": "B"}}
    data["message_signature"] = meter.compute_signature(data)
    assert meter.verify_signature(data)
예제 #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
예제 #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
예제 #15
0
def test_verify_signature_signed():
    data = {"a": "A", "b": "B"}
    sig1 = meter.compute_signature(data)
    data["message_signature"] = sig1
    assert meter.verify_signature(data)
예제 #16
0
def test_compute_signature_same():
    sig1 = meter.compute_signature({"a": "A", "b": "B"})
    sig2 = meter.compute_signature({"a": "A", "b": "B"})
    assert sig1 == sig2
예제 #17
0
def test_compute_signature_signed():
    data = {"a": "A", "b": "B"}
    sig1 = meter.compute_signature(data)
    data["message_signature"] = sig1
    sig2 = meter.compute_signature(data)
    assert sig1 == sig2
예제 #18
0
def test_compute_signature_change_value():
    sig1 = meter.compute_signature({"a": "A", "b": "B"})
    sig2 = meter.compute_signature({"a": "a", "b": "B"})
    assert sig1 != sig2
예제 #19
0
def test_verify_signature_signed():
    data = {'a': 'A', 'b': 'B'}
    sig1 = meter.compute_signature(data)
    data['message_signature'] = sig1
    assert meter.verify_signature(data)
예제 #20
0
def test_verify_signature_signed():
    data = {'a': 'A', 'b': 'B'}
    sig1 = meter.compute_signature(data)
    data['message_signature'] = sig1
    assert meter.verify_signature(data)
예제 #21
0
def test_compute_signature_same():
    sig1 = meter.compute_signature({'a': 'A', 'b': 'B'})
    sig2 = meter.compute_signature({'a': 'A', 'b': 'B'})
    assert sig1 == sig2
예제 #22
0
def test_compute_signature_change_value():
    sig1 = meter.compute_signature({'a': 'A', 'b': 'B'})
    sig2 = meter.compute_signature({'a': 'a', 'b': 'B'})
    assert sig1 != sig2