def test_valid(self): with mock.patch('sentry.coreapi.get_signature') as get_signature: get_signature.return_value = 'signature' validate_hmac('foo', 'signature', time.time(), 'foo')
def test_invalid_validate_hmac_expired(self): with mock.patch('sentry.coreapi.get_signature') as get_signature: get_signature.return_value = 'signature' with self.assertRaises(APITimestampExpired): validate_hmac('foo', 'signature', time.time() - 3601, 'foo')
def test_invalid_validate_hmac_bad_timestamp(self): with mock.patch('sentry.coreapi.get_signature') as get_signature: get_signature.return_value = 'signature' with self.assertRaises(APIError): validate_hmac('foo', 'signature', 'foo', 'foo')
def test_invalid_validate_hmac_signature(self): with mock.patch('sentry.coreapi.get_signature') as get_signature: get_signature.return_value = 'notsignature' with self.assertRaises(APIForbidden): validate_hmac('foo', 'signature', time.time(), 'foo')
def test_valid_validate_hmac(self): with mock.patch('sentry.coreapi.get_signature') as get_signature: get_signature.return_value = 'signature' validate_hmac('foo', 'signature', time.time(), 'foo')