Skip to content

Commit

Permalink
Add test for verifying that only your friends can see games with 'fri…
Browse files Browse the repository at this point in the history
…ends' visibility state
  • Loading branch information
Askaholic committed Dec 20, 2019
1 parent 678b9b7 commit 66db33e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tests/data/test-data.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
insert into login (id, login, email, password, steamid, create_time) values
(10, 'friends', 'friends@example.com', SHA2('friends', 256), null, '2000-01-01 00:00:00'),
(50, 'player_service1', 'ps1@example.com', SHA2('player_service1', 256), null, '2000-01-01 00:00:00'),
(51, 'player_service2', 'ps2@example.com', SHA2('player_service2', 256), null, '2000-01-01 00:00:00'),
(52, 'player_service3', 'ps3@example.com', SHA2('player_service3', 256), null, '2000-01-01 00:00:00'),
Expand Down Expand Up @@ -69,7 +70,8 @@ insert into game_player_stats (gameId, playerId, AI, faction, color, team, place

delete from friends_and_foes where user_id = 1 and subject_id = 2;
insert into friends_and_foes (user_id, subject_id, status) values
(2, 1, 'FRIEND');
(2, 1, 'FRIEND'),
(10, 1, 'FRIEND');


insert into `mod` (id, display_name, author) values
Expand Down
36 changes: 36 additions & 0 deletions tests/integration_tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,42 @@ async def test_game_info_not_broadcast_to_foes(lobby_server):
await asyncio.wait_for(read_until_command(proto2, "game_info"), 0.2)


async def test_game_info_broadcast_to_friends(lobby_server):
# test is the friend of friends
_, _, proto1 = await connect_and_sign_in(
("friends", "friends"), lobby_server
)
_, _, proto2 = await connect_and_sign_in(
("test", "test_password"), lobby_server
)
_, _, proto3 = await connect_and_sign_in(
("Rhiza", "puff_the_magic_dragon"), lobby_server
)
await read_until_command(proto1, "game_info")
await read_until_command(proto2, "game_info")
await read_until_command(proto3, "game_info")

await proto1.send_message({
"command": "game_host",
"title": "Friends Only",
"mod": "faf",
"visibility": "friends"
})

# The host and his friend should see the game
msg = await read_until_command(proto1, "game_info")
msg2 = await read_until_command(proto2, "game_info")

assert msg == msg2
assert msg["featured_mod"] == "faf"
assert msg["title"] == "Friends Only"
assert msg["visibility"] == "friends"

# However, the other person should not see the game
with pytest.raises(asyncio.TimeoutError):
await asyncio.wait_for(read_until_command(proto3, "game_info"), 0.2)


@pytest.mark.parametrize("user", [
("test", "test_password"),
("ban_revoked", "ban_revoked"),
Expand Down

0 comments on commit 66db33e

Please sign in to comment.