Exemplo n.º 1
0
def test_basic_signup(temp_db_session):
    with auth_api_session(temp_db_session) as auth_api:
        reply = auth_api.Signup(auth_pb2.SignupReq(email="*****@*****.**"))
    assert reply.next_step == 0  # SENT_SIGNUP_EMAIL

    # read out the signup token directly from the database for now
    entry = temp_db_session().query(SignupToken).filter(
        SignupToken.email == "*****@*****.**").one_or_none()
    signup_token = entry.token

    with auth_api_session(temp_db_session) as auth_api:
        reply = auth_api.SignupTokenInfo(
            auth_pb2.SignupTokenInfoReq(signup_token=signup_token))

    assert reply.email == "*****@*****.**"

    with auth_api_session(temp_db_session) as auth_api:
        reply = auth_api.CompleteSignup(
            auth_pb2.CompleteSignupReq(signup_token=signup_token,
                                       username="******",
                                       name="Räksmörgås",
                                       city="Minas Tirith",
                                       birthdate="1980-12-31",
                                       gender="Robot"))
    assert isinstance(reply.token, str)
Exemplo n.º 2
0
def test_purge_signup_tokens(db):
    with auth_api_session() as (auth_api, metadata_interceptor):
        reply = auth_api.Signup(auth_pb2.SignupReq(email="*****@*****.**"))

    # send email
    process_job()

    with session_scope() as session:
        signup_token = session.query(SignupToken).one()
        signup_token.expiry = func.now()
        assert session.query(SignupToken).count() == 1

    queue_job(BackgroundJobType.purge_signup_tokens, empty_pb2.Empty())

    # purge tokens
    process_job()

    with session_scope() as session:
        assert session.query(SignupToken).count() == 0

    with session_scope() as session:
        assert session.query(BackgroundJob).filter(
            BackgroundJob.state == BackgroundJobState.completed).count() == 2
        assert session.query(BackgroundJob).filter(
            BackgroundJob.state != BackgroundJobState.completed).count() == 0
Exemplo n.º 3
0
def test_signup_invalid_birthdate(db):
    with auth_api_session() as (auth_api, metadata_interceptor):
        reply = auth_api.Signup(auth_pb2.SignupReq(email="*****@*****.**"))
    assert reply.next_step == auth_pb2.SignupRes.SignupStep.SENT_SIGNUP_EMAIL

    # read out the signup token directly from the database for now
    with session_scope() as session:
        entry = session.query(SignupToken).filter(
            SignupToken.email == "*****@*****.**").one()
        signup_token = entry.token

    with auth_api_session() as (auth_api, metadata_interceptor):
        reply = auth_api.SignupTokenInfo(
            auth_pb2.SignupTokenInfoReq(signup_token=signup_token))

    assert reply.email == "*****@*****.**"

    with auth_api_session() as (auth_api, metadata_interceptor), pytest.raises(
            grpc.RpcError) as e:
        reply = auth_api.CompleteSignup(
            auth_pb2.CompleteSignupReq(
                signup_token=signup_token,
                username="******",
                name="Räksmörgås",
                city="Minas Tirith",
                birthdate="9999-12-31",  # arbitrary future birthdate
                gender="Robot",
                hosting_status=api_pb2.HOSTING_STATUS_CAN_HOST,
                lat=1,
                lng=1,
                radius=100,
                accept_tos=True,
            ))
    assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT
    assert e.value.details() == errors.INVALID_BIRTHDATE
Exemplo n.º 4
0
def test_basic_signup(db):
    with auth_api_session(db) as auth_api:
        reply = auth_api.Signup(auth_pb2.SignupReq(email="*****@*****.**"))
    assert reply.next_step == auth_pb2.SignupRes.SignupStep.SENT_SIGNUP_EMAIL

    # read out the signup token directly from the database for now
    with session_scope(db) as session:
        entry = session.query(SignupToken).filter(
            SignupToken.email == "*****@*****.**").one_or_none()
        signup_token = entry.token

    with auth_api_session(db) as auth_api:
        reply = auth_api.SignupTokenInfo(
            auth_pb2.SignupTokenInfoReq(signup_token=signup_token))

    assert reply.email == "*****@*****.**"

    with auth_api_session(db) as auth_api:
        reply = auth_api.CompleteSignup(
            auth_pb2.CompleteSignupReq(
                signup_token=signup_token,
                username="******",
                name="Räksmörgås",
                city="Minas Tirith",
                birthdate="1980-12-31",
                gender="Robot",
                hosting_status=api_pb2.HOSTING_STATUS_CAN_HOST,
            ))
    assert isinstance(reply.token, str)
Exemplo n.º 5
0
def test_basic_signup(db):
    with auth_api_session() as (auth_api, metadata_interceptor):
        reply = auth_api.Signup(auth_pb2.SignupReq(email="*****@*****.**"))
    assert reply.next_step == auth_pb2.SignupRes.SignupStep.SENT_SIGNUP_EMAIL

    # read out the signup token directly from the database for now
    with session_scope() as session:
        entry = session.query(SignupToken).filter(
            SignupToken.email == "*****@*****.**").one()
        signup_token = entry.token

    with auth_api_session() as (auth_api, metadata_interceptor):
        reply = auth_api.SignupTokenInfo(
            auth_pb2.SignupTokenInfoReq(signup_token=signup_token))

    assert reply.email == "*****@*****.**"

    with auth_api_session() as (auth_api, metadata_interceptor):
        reply = auth_api.CompleteSignup(
            auth_pb2.CompleteSignupReq(
                signup_token=signup_token,
                username="******",
                name="Räksmörgås",
                city="Minas Tirith",
                birthdate="1980-12-31",
                gender="Robot",
                hosting_status=api_pb2.HOSTING_STATUS_CAN_HOST,
                lat=1,
                lng=1,
                radius=100,
                accept_tos=True,
            ))

    # make sure we got the right token in a cookie
    with session_scope() as session:
        token = session.query(User, UserSession).filter(
            User.username == "frodo").one().UserSession.token
    assert get_session_cookie_token(metadata_interceptor) == token