Пример #1
0
def test_jail_basic(db):
    user1, token1 = generate_user(db)

    with real_api_session(db, token1) as api:
        res = api.Ping(api_pb2.PingReq())

    with real_jail_session(db, token1) as jail:
        res = jail.JailInfo(empty_pb2.Empty())
        # check every field is false
        for field in res.DESCRIPTOR.fields:
            assert getattr(res, field.name) == False

        assert not res.jailed

    # make the user jailed
    user2, token2 = generate_user(db, accepted_tos=0)

    with real_api_session(db,
                          token2) as api, pytest.raises(grpc.RpcError) as e:
        res = api.Ping(api_pb2.PingReq())
    assert e.value.code() == grpc.StatusCode.UNAUTHENTICATED

    with real_jail_session(db, token2) as jail:
        res = jail.JailInfo(empty_pb2.Empty())

        assert res.jailed

        reason_count = 0

        # check at least one field is true
        for field in res.DESCRIPTOR.fields:
            reason_count += getattr(res, field.name) == True

        assert reason_count > 0
Пример #2
0
def test_invalid_token(db):
    user1, token1 = generate_user()
    user2, token2 = generate_user()

    wrong_token = random_hex(32)

    with real_api_session(wrong_token) as api, pytest.raises(
            grpc.RpcError) as e:
        res = api.GetUser(api_pb2.GetUserReq(user=user2.username))

    assert e.value.code() == grpc.StatusCode.UNAUTHENTICATED
    assert e.value.details() == "Unauthorized"
Пример #3
0
def test_JailInfo(db):
    user1, token1 = generate_user(accepted_tos=0)

    with real_jail_session(token1) as jail:
        res = jail.JailInfo(empty_pb2.Empty())
        assert res.jailed
        assert res.has_not_accepted_tos

    with real_api_session(token1) as api, pytest.raises(grpc.RpcError) as e:
        res = api.Ping(api_pb2.PingReq())
    assert e.value.code() == grpc.StatusCode.UNAUTHENTICATED

    # make the user not jailed
    user2, token2 = generate_user(accepted_tos=1)

    with real_jail_session(token2) as jail:
        res = jail.JailInfo(empty_pb2.Empty())
        assert not res.jailed
        assert not res.has_not_accepted_tos

    with real_api_session(token2) as api:
        res = api.Ping(api_pb2.PingReq())
Пример #4
0
def test_TOS_increase(db, monkeypatch):
    # test if the TOS version is updated

    # not jailed yet
    user, token = generate_user()

    with real_jail_session(token) as jail:
        res = jail.JailInfo(empty_pb2.Empty())
        assert not res.jailed
        assert not res.has_not_accepted_tos

    with real_api_session(token) as api:
        res = api.Ping(api_pb2.PingReq())

    # now we pretend to update the TOS version
    new_TOS_VERSION = TOS_VERSION + 1

    monkeypatch.setattr(models, "TOS_VERSION", new_TOS_VERSION)
    monkeypatch.setattr(servicers_jail, "TOS_VERSION", new_TOS_VERSION)

    # make sure we're jailed
    with real_api_session(token) as api, pytest.raises(grpc.RpcError) as e:
        res = api.Ping(api_pb2.PingReq())
    assert e.value.code() == grpc.StatusCode.UNAUTHENTICATED

    with real_jail_session(token) as jail:
        res = jail.JailInfo(empty_pb2.Empty())
        assert res.jailed
        assert res.has_not_accepted_tos

        # now accept
        res = jail.AcceptTOS(jail_pb2.AcceptTOSReq(accept=True))

        res = jail.JailInfo(empty_pb2.Empty())
        assert not res.jailed
        assert not res.has_not_accepted_tos
Пример #5
0
def test_ping(db):
    user, token = generate_user()

    with real_api_session(token) as api:
        res = api.Ping(api_pb2.PingReq())

    assert res.user.user_id == user.id
    assert res.user.username == user.username
    assert res.user.name == user.name
    assert res.user.city == user.city
    assert res.user.hometown == user.hometown
    assert res.user.verification == 0.0
    assert res.user.community_standing == user.community_standing
    assert res.user.num_references == 0
    assert res.user.gender == user.gender
    assert res.user.pronouns == user.pronouns
    assert res.user.age == user.age

    assert (res.user.lat, res.user.lng) == (user.coordinates or (0, 0))

    # the joined time is fuzzed
    # but shouldn't be before actual joined time, or more than one hour behind
    assert user.joined - timedelta(hours=1) <= to_aware_datetime(
        res.user.joined) <= user.joined
    # same for last_active
    assert user.last_active - timedelta(hours=1) <= to_aware_datetime(
        res.user.last_active) <= user.last_active

    assert res.user.hosting_status == api_pb2.HOSTING_STATUS_CANT_HOST
    assert res.user.meetup_status == api_pb2.MEETUP_STATUS_OPEN_TO_MEETUP

    assert res.user.occupation == user.occupation
    assert res.user.education == user.education
    assert res.user.about_me == user.about_me
    assert res.user.my_travels == user.my_travels
    assert res.user.things_i_like == user.things_i_like
    assert set(language_ability.code
               for language_ability in res.user.language_abilities) == set(
                   ["fin", "fra"])
    assert res.user.about_place == user.about_place
    assert res.user.regions_visited == [
        "FIN", "REU", "CHE"
    ]  # Tests alphabetization by region name
    assert res.user.regions_lived == ["EST", "FRA", "ESP"]  # Ditto
    assert res.user.additional_information == user.additional_information

    assert res.user.friends == api_pb2.User.FriendshipStatus.NA
    assert not res.user.HasField("pending_friend_request")
Пример #6
0
def test_ping(db):
    user, token = generate_user("tester")

    with real_api_session(token) as api:
        res = api.Ping(api_pb2.PingReq())

    assert res.user.user_id == user.id
    assert res.user.username == user.username
    assert res.user.name == user.name
    assert res.user.city == user.city
    assert res.user.hometown == user.hometown
    assert res.user.verification == user.verification
    assert res.user.community_standing == user.community_standing
    assert res.user.num_references == 0
    assert res.user.gender == user.gender
    assert res.user.pronouns == user.pronouns
    assert res.user.age == user.age

    assert (res.user.lat, res.user.lng) == (user.coordinates or (0, 0))

    # the joined time is fuzzed
    # but shouldn't be before actual joined time, or more than one hour behind
    assert user.joined - timedelta(hours=1) <= to_aware_datetime(
        res.user.joined) <= user.joined
    # same for last_active
    assert user.last_active - timedelta(hours=1) <= to_aware_datetime(
        res.user.last_active) <= user.last_active

    assert res.user.hosting_status == api_pb2.HOSTING_STATUS_UNKNOWN
    assert res.user.meetup_status == api_pb2.MEETUP_STATUS_UNKNOWN

    assert res.user.occupation == user.occupation
    assert res.user.education == user.education
    assert res.user.about_me == user.about_me
    assert res.user.my_travels == user.my_travels
    assert res.user.things_i_like == user.things_i_like
    assert res.user.about_place == user.about_place
    # TODO: this list serialisation will be fixed hopefully soon
    assert res.user.languages == user.languages.split("|")
    assert res.user.countries_visited == user.countries_visited.split("|")
    assert res.user.countries_lived == user.countries_lived.split("|")
    assert res.user.additional_information == user.additional_information

    assert res.user.friends == api_pb2.User.FriendshipStatus.NA
    assert not res.user.HasField("pending_friend_request")
    assert len(res.user.mutual_friends) == 0
Пример #7
0
def test_ping(db):
    user, token = generate_user(db, "tester")

    with real_api_session(db, token) as api:
        res = api.Ping(api_pb2.PingReq())

    assert res.user.user_id == user.id
    assert res.user.username == user.username
    assert res.user.name == user.name
    assert res.user.city == user.city
    assert res.user.verification == user.verification
    assert res.user.community_standing == user.community_standing
    assert res.user.num_references == 0
    assert res.user.gender == user.gender
    assert res.user.age == user.age
    assert res.user.color == user.color

    # the joined time is fuzzed
    # but shouldn't be before actual joined time, or more than one hour behind
    assert user.joined - timedelta(hours=1) <= to_aware_datetime(
        res.user.joined) <= user.joined
    # same for last_active
    assert user.last_active - timedelta(hours=1) <= to_aware_datetime(
        res.user.last_active) <= user.last_active

    assert res.user.hosting_status == api_pb2.HOSTING_STATUS_UNKNOWN

    assert res.user.occupation == user.occupation
    assert res.user.about_me == user.about_me
    assert res.user.about_place == user.about_place
    # TODO: this list serialisation will be fixed hopefully soon
    assert res.user.languages == user.languages.split("|")
    assert res.user.countries_visited == user.countries_visited.split("|")
    assert res.user.countries_lived == user.countries_lived.split("|")

    assert res.user.friends == api_pb2.User.FriendshipStatus.NA
    assert len(res.user.mutual_friends) == 0