Skip to content

Commit 99c5a12

Browse files
committed
Update test_dcl_server.py for Python 3.10+ compatibility (#37549)
* fix: Update test_dcl_server.py for Python 3.x compatibility Update the DCL server script to support newer Python versions for TC-CGEN-2.12 manual test case execution. The script provides terms and conditions functionality required for testing the DCL flow. Testing: 1. Start the DCL server in terminal 1: ```bash python3 ./examples/chip-tool/commands/dcl/test_dcl_server.py ``` 2. Launch terms and conditions app in terminal 2: ```bash rm /tmp/chip* ; ./out/linux-x64-terms-and-conditions/chip-terms-and-conditions-app \ --version 0 --custom-flow 2 --capabilities 6 --discriminator 3840 \ --passcode 20202021 --KVS /tmp/chip_kvs.bin --trace_file /tmp/chip_trace.log \ --trace_log 1 --trace_decode 1 ``` 3. Execute pairing command in terminal 3: ```bash yes | ./out/linux-x64-chip-tool/chip-tool pairing code 0x12344321 \ MT:-24J029Q00KA0648G00 --use-dcl true --dcl-hostname localhost --dcl-port 4443 ``` * [DCL] Improve HTTPS server implementation and documentation - Add detailed comments explaining the SSL/TLS setup process - Use context manager for proper socket cleanup
1 parent 54deab6 commit 99c5a12

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

.vscode/launch.json

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"name": "Python Debugger: test_dcl_server",
9+
"type": "debugpy",
10+
"request": "launch",
11+
"program": "/workspace/connectedhomeip/examples/chip-tool/commands/dcl/test_dcl_server.py",
12+
"args": [],
13+
"console": "integratedTerminal"
14+
},
715
{
816
"name": "Attach to running process",
917
"type": "lldb",

examples/chip-tool/commands/dcl/test_dcl_server.py

+19-13
Original file line numberDiff line numberDiff line change
@@ -211,19 +211,25 @@ def handle_tc_request(self, vendor_id, product_id):
211211

212212

213213
def run_https_server(cert_file="cert.pem", key_file="key.pem"):
214-
httpd = http.server.HTTPServer(
215-
(DEFAULT_HOSTNAME, DEFAULT_PORT), RESTRequestHandler)
216-
217-
httpd.socket = ssl.wrap_socket(
218-
httpd.socket,
219-
server_side=True,
220-
certfile=cert_file,
221-
keyfile=key_file,
222-
ssl_version=ssl.PROTOCOL_TLS,
223-
)
224-
225-
print(f"Serving on https://{DEFAULT_HOSTNAME}:{DEFAULT_PORT}")
226-
httpd.serve_forever()
214+
# Creates a basic HTTP server instance that listens on DEFAULT_HOSTNAME and DEFAULT_PORT
215+
# RESTRequestHandler handles incoming HTTP requests
216+
httpd = http.server.HTTPServer((DEFAULT_HOSTNAME, DEFAULT_PORT), RESTRequestHandler)
217+
218+
# Creates an SSL context using TLS protocol for secure communications
219+
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
220+
221+
# Loads the SSL certificate and private key for the server
222+
# cert_file: contains the server's public certificate
223+
# key_file: contains the server's private key
224+
context.load_cert_chain(certfile=cert_file, keyfile=key_file)
225+
226+
# Uses a context manager (with statement) to wrap the HTTP server's socket with SSL
227+
# server_side=True indicates this is a server socket
228+
# The wrapped socket is automatically closed when exiting the with block
229+
with context.wrap_socket(httpd.socket, server_side=True) as httpd.socket:
230+
print(f"Serving on https://{DEFAULT_HOSTNAME}:{DEFAULT_PORT}")
231+
# Starts the server and runs indefinitely, handling incoming HTTPS requests
232+
httpd.serve_forever()
227233

228234

229235
# Generate self-signed certificates if needed

0 commit comments

Comments
 (0)