Skip to content

Commit 3fbcc02

Browse files
committed
Refactor mock server to support distributed configuration loading
Refactors the mock server implementation to support loading configuration from multiple JSON files, enabling flexible mocking of different services during Matter device commissioning validation. Key Changes: - Restructured configuration loading to support directory-based routing configs - Added dataclass-based type safety for configuration and route definitions - Updated path handling to use pathlib.Path for better cross-platform support - Modified server launch configuration to support routing config directory - Added configurations for mocking multiple services: * Distributed Compliance Ledger (DCL) * Product Terms & Conditions server Technical Improvements: - Introduced strongly typed Route and Configuration classes - Simplified route matching logic with dedicated matcher - Improved error handling for configuration loading - Updated unit tests to support new configuration structure The changes enable quick iteration of mock service responses during preproduction testing and PlugFest validation, particularly for testing new commissioning flows that rely on DCL-based configuration with indirect product server references. Test Configuration: - Added example configurations for VID:65521/65522, PID:32769 - Updated TC URL endpoints to use port 44538 - Included sample Terms & Conditions responses
1 parent 5398152 commit 3fbcc02

22 files changed

+1219
-253
lines changed

.github/.wordlist.txt

+5
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ CurrentHue
333333
CurrentLevel
334334
CurrentSaturation
335335
customAcl
336+
customizable
336337
customizations
337338
cvfJ
338339
cxx
@@ -1060,6 +1061,7 @@ otatesting
10601061
otaURL
10611062
OTBR
10621063
otcli
1064+
OU
10631065
outform
10641066
outgoingCommands
10651067
overridable
@@ -1171,6 +1173,7 @@ PyObject
11711173
pypi
11721174
PyRun
11731175
pytest
1176+
PYTHONPATH
11741177
QEMU
11751178
Qorvo
11761179
QPG
@@ -1349,6 +1352,7 @@ SRP
13491352
SRV
13501353
SSBL
13511354
SSID
1355+
SSL
13521356
startoffset
13531357
StartScan
13541358
startsWith
@@ -1516,6 +1520,7 @@ unfocus
15161520
Unicast
15171521
UniFlash
15181522
UnitLocalization
1523+
unittest
15191524
unpair
15201525
unprovisioned
15211526
Unsecure

.vscode/launch.json

+27-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,37 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"name": "Python: Mock Server Tests",
9+
"type": "debugpy",
10+
"request": "launch",
11+
"module": "unittest",
12+
"args": [
13+
"${workspaceFolder}/integrations/mock_server/tests/test_mock_server.py"
14+
],
15+
"env": {
16+
"PYTHONPATH": "${workspaceFolder}/integrations/mock_server/src:${PYTHONPATH}"
17+
},
18+
"console": "integratedTerminal",
19+
"cwd": "${workspaceFolder}"
20+
},
721
{
822
"name": "Python Debugger: test_dcl_server",
923
"type": "debugpy",
1024
"request": "launch",
11-
"program": "/workspace/connectedhomeip/examples/chip-tool/commands/dcl/test_dcl_server.py",
12-
"args": [],
25+
"program": "${workspaceFolder}/integrations/mock_server/src/main.py",
26+
"args": [
27+
"--port",
28+
"8443",
29+
"--config",
30+
"${workspaceFolder}/integrations/mock_server/configurations/server_config.json",
31+
"--routing-config-dir",
32+
"${workspaceFolder}/integrations/mock_server/configurations/fake_distributed_compliance_ledger",
33+
"--cert",
34+
"${workspaceFolder}/server.crt",
35+
"--key",
36+
"${workspaceFolder}/server.key"
37+
],
1338
"console": "integratedTerminal"
1439
},
1540
{

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

-251
This file was deleted.

integrations/mock_server/README.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Mock HTTP/HTTPS Server
2+
3+
## Overview
4+
5+
This project provides a configurable mock HTTP/HTTPS server designed for API
6+
testing, dynamic response generation, and automated request handling. It
7+
supports static responses, dynamic custom response handlers, query parameter
8+
matching, request body validation (including regex), and both HTTP and HTTPS
9+
protocols.
10+
11+
## Setup
12+
13+
```bash
14+
openssl req -x509 -newkey rsa:2048 -keyout server.key -out server.crt -days 365 -nodes -subj "/C=US/ST= /L= /O= /OU= /CN=localhost"
15+
```
16+
17+
## Features
18+
19+
- **Server Functionality**
20+
21+
- Supports HTTP & HTTPS (with self-signed certificates)
22+
- CLI-driven execution with customizable options (port, configuration
23+
file, SSL options, etc.)
24+
- Handles GET, POST, PUT, and DELETE requests
25+
26+
- **Route Matching**
27+
28+
- Exact path and wildcard (\*) path matching
29+
- Query parameter validation
30+
- Request body matching with exact or regex-based rules
31+
32+
- **Static Response Handling**
33+
34+
- Static responses defined in `config.json`
35+
36+
- **Error Handling & Logging**
37+
- Graceful error responses for missing or invalid routes
38+
- Structured logging with configurable verbosity
39+
40+
## Running Tests
41+
42+
### Prerequisites
43+
44+
- Python virtual environment (located in `out/venv`)
45+
- Python unittest framework
46+
47+
### Test Execution
48+
49+
You can run the tests using one of these methods:
50+
51+
1. Using Python unittest with PYTHONPATH:
52+
53+
```bash
54+
PYTHONPATH=$PYTHONPATH:/workspace/connectedhomeip/integrations/mock_server/src python3 -m unittest integrations/mock_server/tests/test_mock_server.py
55+
```

0 commit comments

Comments
 (0)