def test_hmac(self): """ From http://en.wikipedia.org/wiki/Hash-based_message_authentication_code HMAC_SHA1("key", "The quick brown fox jumps over the lazy dog") = 0xde7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9 """ message = "The quick brown fox jumps over the lazy dog" key = "a2V5" # "key" -> base64 signature = "3nybhbi3iqa8ino29wqQcBydtNk=" self.assertEqual(signature, _client.sign_hmac(key, message))
async def test_url_signed(aresponses, enterprise_client, credentials): address = 'Test St.' params = {'address': address, 'client': credentials['client_id']} path = '?'.join( ['/maps/api/geocode/json', urlencode_params(params.items())]) expected_signature = sign_hmac(credentials['client_secret'], path) aresponses.add( 'maps.googleapis.com', path + '&signature={}'.format(expected_signature), 'get', aresponses.Response( body='{"status": "OK", "results": ["foo"]}', status=web.HTTPOk.status_code, content_type='application/json', ), match_querystring=True, ) resp = await enterprise_client.geocode(address) assert resp == ['foo']