diff --git a/lanscatter/masternode.py b/lanscatter/masternode.py index ad0e87d..5e289c6 100644 --- a/lanscatter/masternode.py +++ b/lanscatter/masternode.py @@ -97,11 +97,15 @@ async def ok(txt): here = packaging.version.parse(Defaults.PROTOCOL_VERSION) try: there = packaging.version.parse(msg.get('protocol') or 'MISSING') + if not there.release: + raise packaging.version.InvalidVersion if there.release[0] != here.release[0]: await send_queue.put({'action': 'fatal', 'message': f'Incompatible protocol. Server has {Defaults.PROTOCOL_VERSION}, ' f'yours is {msg.get("protocol")}'}) - except InvalidVersion: + else: + await ok({'message': 'Version accepted.'}) + except packaging.version.InvalidVersion: return await error(f'Invalid protocol version {str(msg.get("protocol"))}.', fatal=True) self.status_func(log_info=f'Client "{client_name}" uses protocol version {msg.get("protocol")}, '+ f'app version {msg.get("app") or "MISSING"}') @@ -247,7 +251,6 @@ async def send_loop(): if msg and msg.get('action') == 'fatal': self.status_func(log_info=f'Sent fatal error to client. Kicking them out: {str(msg)}"') await ws.close() - break send_task = asyncio.create_task(send_loop()) @@ -405,8 +408,6 @@ def scandir_blocking(): server.planner_loop(), ], return_when=asyncio.FIRST_COMPLETED) - status_func(log_info='Server finished.') - except (KeyboardInterrupt, concurrent.futures.CancelledError): status_func(log_info='User exit.') kb_exit = True diff --git a/tests/test_integration.py b/tests/test_integration.py index 1c45d2c..9186327 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -236,6 +236,102 @@ def test_bad_dir(is_master): _assert_node_basics(p, check_sync_results=False) +async def _bad_request_tests(master_port): + + async with aiohttp.ClientSession() as session: + + print("Request: test HTTP requests") + if True: + print(" - HTTP on websocet endpoint") + async with session.get(f'http://localhost:{master_port}/join') as resp: + assert resp.status != 200, "Websocket endpoint answered plain HTML request with 200." + + print(" - request HTML status page") + async with session.get(f'http://localhost:{master_port}/') as resp: + assert resp.status == 200, "Server status page returned HTTP error: " + str(resp.status) + assert '