-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Limit the length of game names to 256 characters
This limits the maximum length of game names to 256 characters. Longer game names will be simply cut to the first 256 characters. While Pyrogenesis already contains a check to limit the game name to 256 characters, this is to counter modified clients trying to circumvent this limitation. Fixes https://gitea.wildfiregames.com/0ad/0ad/issues/3651
- Loading branch information
Showing
2 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
from unittest.mock import Mock, call, patch | ||
|
||
from cachetools import FIFOCache | ||
from hypothesis import example, given | ||
from hypothesis import strategies as st | ||
from parameterized import parameterized | ||
from slixmpp.jid import JID | ||
|
||
|
@@ -35,7 +37,12 @@ def test_add(self): | |
"""Test successfully adding a game.""" | ||
games = Games() | ||
jid = JID(jid="[email protected]") | ||
game_data = {"players": ["player1", "player2"], "nbp": "foo", "state": "init"} | ||
game_data = { | ||
"players": ["player1", "player2"], | ||
"name": "game", | ||
"nbp": "foo", | ||
"state": "init", | ||
} | ||
self.assertTrue(games.add_game(jid, game_data)) | ||
all_games = games.get_all_games() | ||
game_data.update( | ||
|
@@ -61,14 +68,41 @@ def test_add_invalid(self, jid, game_data): | |
games = Games() | ||
self.assertFalse(games.add_game(jid, game_data)) | ||
|
||
@given(game_name=st.text()) | ||
@example(game_name="a" * 300) | ||
def test_add_long_game_name(self, game_name): | ||
"""Test adding a game with a long name cuts the name.""" | ||
games = Games() | ||
jid = JID(jid="[email protected]") | ||
game_data = { | ||
"players": ["player1", "player2"], | ||
"name": game_name, | ||
"nbp": "foo", | ||
"state": "init", | ||
} | ||
self.assertTrue(games.add_game(jid, game_data)) | ||
all_games = games.get_all_games() | ||
self.assertEqual(len(all_games), 1) | ||
self.assertEqual(all_games["[email protected]"]["name"], game_name[:256]) | ||
|
||
def test_remove(self): | ||
"""Test removal of games.""" | ||
games = Games() | ||
jid1 = JID(jid="[email protected]") | ||
jid2 = JID(jid="[email protected]") | ||
game_data1 = {"players": ["player1", "player2"], "nbp": "foo", "state": "init"} | ||
game_data1 = { | ||
"players": ["player1", "player2"], | ||
"name": "game1", | ||
"nbp": "foo", | ||
"state": "init", | ||
} | ||
games.add_game(jid1, game_data1) | ||
game_data2 = {"players": ["player3", "player4"], "nbp": "bar", "state": "init"} | ||
game_data2 = { | ||
"players": ["player3", "player4"], | ||
"name": "game2", | ||
"nbp": "bar", | ||
"state": "init", | ||
} | ||
games.add_game(jid2, game_data2) | ||
game_data1.update( | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters