Ejemplo n.º 1
0
def modify_url(url, user_auth_key, company):
    args = dict(company=company, expires=to_unix_ms(datetime(2032, 1, 1)))
    body = '{company}:{expires}'.format(**args).encode()
    args['signature'] = hmac.new(user_auth_key.encode(), body,
                                 hashlib.sha256).hexdigest()
    url = str(url)
    return url + ('&' if '?' in url else '?') + urlencode(args)
Ejemplo n.º 2
0
def modify_url(url, settings, company='foobar'):
    args = dict(
        company=company,
        expires=to_unix_ms(datetime(2032, 1, 1))
    )
    body = '{company}:{expires}'.format(**args).encode()
    args['signature'] = hmac.new(settings.user_auth_key, body, hashlib.sha256).hexdigest()
    return str(url) + ('&' if '?' in str(url) else '?') + urlencode(args)
Ejemplo n.º 3
0
async def test_sig_expired(cli, settings):
    args = dict(company='whatever', expires=to_unix_ms(datetime(2000, 1, 1)))
    body = '{company}:{expires}'.format(**args).encode()
    args['signature'] = hmac.new(settings.user_auth_key, body, hashlib.sha256).hexdigest()
    r = await cli.get('/user/email-test/messages.json?' + urlencode(args))
    assert r.status == 403, await r.text()
    assert r.headers['Access-Control-Allow-Origin'] == '*'
    assert {'message': 'token expired'} == await r.json()
Ejemplo n.º 4
0
async def test_valid_signature(cli, settings, db_conn):
    await db_conn.execute('insert into companies (code) values ($1)', 'whatever')
    args = dict(company='whatever', expires=to_unix_ms(datetime(2032, 1, 1)))
    body = '{company}:{expires}'.format(**args).encode()
    args['signature'] = hmac.new(settings.user_auth_key, body, hashlib.sha256).hexdigest()
    r = await cli.get('/user/email-test/messages.json?' + urlencode(args))
    assert r.status == 200, await r.text()
    assert r.headers['Access-Control-Allow-Origin'] == '*'
Ejemplo n.º 5
0
async def test_cron_time_match_not_unique(tmpworkdir, redis_conn, actor):
    with open('datatime.pkl', 'wb') as f:
        pickle.dump(datetimes, f)

    v = str(to_unix_ms(datetime(2032, 1, 1, 3, 0, 0, 123456))).encode()
    await redis_conn.set(b'arq:cron:CronActor.save_not_unique', v)

    worker = CronWorker(burst=True, loop=actor.loop)

    assert not tmpworkdir.join('not_unique').exists()
    await worker.run()
    assert tmpworkdir.join('not_unique').exists()
Ejemplo n.º 6
0
 def default(self, obj):
     if isinstance(obj, datetime):
         return to_unix_ms(obj)
     elif isinstance(obj, set):
         return sorted(obj)
     return super().default(obj)