@@ -54,6 +54,7 @@ def __init__(
5454 ssl : SSLConfig ,
5555 remotes : list [object ],
5656 private_key : PrivateKey ,
57+ test_mode : bool = False ,
5758 ) -> None :
5859 """Initialize the server.
5960
@@ -66,6 +67,7 @@ def __init__(
6667 self ._app = None
6768 self ._private_key = private_key
6869 self ._remotes = remotes
70+ self ._test_mode = test_mode
6971 if ssl :
7072 cert_path : str = join (CONFIG_DIR , ssl ["cert_path" ])
7173 key_path : str = join (CONFIG_DIR , ssl ["key_path" ])
@@ -146,12 +148,13 @@ async def websocket_handler(self, request: Request) -> StreamResponse:
146148 """
147149 log .info ("WebSocket connection starting" )
148150
149- approved , display_addr , remote_addr = await self ._authorize_request_ok (request )
150- if not approved :
151- log .warning (f"Connection from { display_addr } not approved." )
152- # Return a 403 Forbidden response to properly reject the connection.
153- return Response (status = 403 , text = "Connection not approved" )
154- self ._approved_remotes .add (remote_addr )
151+ if not self ._test_mode :
152+ approved , display_addr , remote_addr = await self ._authorize_request_ok (request )
153+ if not approved :
154+ log .warning (f"Connection from { display_addr } not approved." )
155+ # Return a 403 Forbidden response to properly reject the connection.
156+ return Response (status = 403 , text = "Connection not approved" )
157+ self ._approved_remotes .add (remote_addr )
155158
156159 socket = WebSocketResponse ()
157160 await socket .prepare (request )
0 commit comments