File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 1+ import socket
12from os import getenv
23from pathlib import Path
34from shutil import which
@@ -38,6 +39,22 @@ def compare_screenshot(test_image):
3839 assert m < threshold
3940
4041
42+ def assert_no_vncserver_tcp_port_open (host = "localhost" , port = 5901 , timeout = 1 ):
43+ """
44+ Test that a specific port is not open, which would be a security issue.
45+ Returns:
46+ True if the port is closed (secure), False if open (security issue)
47+ """
48+ sock = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
49+ sock .settimeout (timeout )
50+ result = sock .connect_ex ((host , port ))
51+ sock .close ()
52+
53+ # If result is 0, connection was successful (port is open - security issue)
54+ # Otherwise, connection failed (port is closed - secure)
55+ assert result != 0
56+
57+
4158# To debug this set environment variable HEADLESS=0
4259def test_desktop (browser ):
4360 page = browser
@@ -54,6 +71,8 @@ def test_desktop(browser):
5471 expect (page1 .get_by_text ("Status: Connected" )).to_be_visible ()
5572 expect (page1 .locator ("canvas" )).to_be_visible ()
5673
74+ assert_no_vncserver_tcp_port_open ()
75+
5776 # Screenshot the desktop element only
5877 # May take a few seconds to load
5978 page1 .wait_for_timeout (5000 )
You can’t perform that action at this time.
0 commit comments