def test_authchallengeresp_happy():
    db_conn = get_db()
    u = db.user_with_pk(db_conn, U1.pk)
    echal = get_chal(u)
    sacr = SignedMessage.sign(account.AuthChallengeResp(echal), SK1)
    resp = server.handle_authchallengeresp(db_conn, sacr)
    assert resp.err is None
    assert isinstance(resp.cred, EncryptedMessage)
    scred = EncryptedMessage.dec(resp.cred, server.ENCKEY)
    cred, pk_used = SignedMessage.unwrap(scred)
    assert pk_used == server.IDKEY.pubkey
    assert cred.expire > time.time()
def test_location_update_happy():
    db_conn = get_db()
    u = db.user_with_pk(db_conn, U1.pk)
    ecred = get_cred(u)
    original_expire = expire_from_ecred(ecred, server.ENCKEY,
                                        server.IDKEY.pubkey)
    loc = location.Location(u, loca.Coords(42, 69), time.time())
    lu = location.LocationUpdate(loc, ecred)
    slu = SignedMessage.sign(lu, SK1)
    resp = server.handle_location_update(db_conn, slu)
    assert resp.ok
    assert isinstance(resp.cred, EncryptedMessage)
    scred = EncryptedMessage.dec(resp.cred, server.ENCKEY)
    cred, pk_used = SignedMessage.unwrap(scred)
    assert pk_used == server.IDKEY.pubkey
    assert cred.expire > original_expire
    assert resp.err is None