async def test_authenticate(pusher): token = await pusher.authenticate('em2.platform.remote.com') assert token.startswith('em2.local.com:2461536000:') async with pusher._redis_pool.get() as redis: v = await redis.get(b'ak:em2.platform.remote.com') assert token == v.decode() ttl = await redis.ttl(b'ak:em2.platform.remote.com') expiry = ttl + now_unix_secs() expected_expiry = 2461536000 - Settings().COMMS_PUSH_TOKEN_EARLY_EXPIRY assert abs(expiry - expected_expiry) < 10
async def auth(s): timestamp = now_unix_secs() msg = '{}:{}'.format(LOCAL_DOMAIN, timestamp) h = SHA256.new(msg.encode()) private_domain_key = Path('private8000.pem').read_text() key = RSA.importKey(private_domain_key) signer = PKCS1_v1_5.new(key) signature = base64.urlsafe_b64encode(signer.sign(h)).decode() auth_data = { 'platform': LOCAL_DOMAIN, 'timestamp': timestamp, 'signature': signature, } return await s.post('authenticate', data=encoding.encode(auth_data), headers=CT_HEADER)
def _now_unix(self): return now_unix_secs()