Skip to content

Commit 152b29f

Browse files
committed
Add test to verify vncserver TCP port isn't open
1 parent 5a46ef7 commit 152b29f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/test_browser.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import socket
12
from os import getenv
23
from pathlib import Path
34
from 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
4259
def 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)

0 commit comments

Comments
 (0)