From 323013cb8773118c82061da3cc7b5ec553b77b84 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 5 Apr 2020 15:08:46 -0300 Subject: [PATCH] Add test to ensure a removed state invalidates WS --- tests/test_websocket.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/tests/test_websocket.py b/tests/test_websocket.py index 7ac678f..ed49838 100644 --- a/tests/test_websocket.py +++ b/tests/test_websocket.py @@ -205,9 +205,7 @@ async def test_resume(test_cli_user): # try to resume conn = await gw_start(test_cli_user.cli) - - # get the hello frame but ignore it - await _json(conn) + _ = await _json(conn) await _json_send( conn, @@ -227,3 +225,30 @@ async def test_resume(test_cli_user): assert msg["op"] == OP.DISPATCH assert isinstance(msg["t"], str) assert msg["t"] in ("RESUMED", "PRESENCE_REPLACE") + + # close again, and retry again, but this time by removing the state + # and asserting the session won't be resumed. + await _close(conn) + + conn = await gw_start(test_cli_user.cli) + _ = await _json(conn) + + async with test_cli_user.app.app_context(): + test_cli_user.app.state_manager.remove(sess_id) + + await _json_send( + conn, + { + "op": OP.RESUME, + "d": { + "token": test_cli_user.user["token"], + "session_id": sess_id, + "seq": 0, + }, + }, + ) + + msg = await _json(conn) + assert isinstance(msg, dict) + assert isinstance(msg["op"], int) + assert msg["op"] == OP.INVALID_SESSION