Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #37695 to v1.4-branch #37713

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ CurrentHue
CurrentLevel
CurrentSaturation
customAcl
customizable
customizations
cvfJ
cxx
Expand Down Expand Up @@ -1039,6 +1040,7 @@ otatesting
otaURL
OTBR
otcli
OU
outform
outgoingCommands
overridable
Expand Down Expand Up @@ -1150,6 +1152,7 @@ PyObject
pypi
PyRun
pytest
PYTHONPATH
QEMU
Qorvo
QPG
Expand Down Expand Up @@ -1326,6 +1329,7 @@ SRP
SRV
SSBL
SSID
SSL
startoffset
StartScan
startsWith
Expand Down Expand Up @@ -1490,6 +1494,7 @@ unfocus
Unicast
UniFlash
UnitLocalization
unittest
unpair
unprovisioned
Unsecure
Expand Down
29 changes: 27 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,37 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Mock Server Tests",
"type": "debugpy",
"request": "launch",
"module": "unittest",
"args": [
"${workspaceFolder}/integrations/mock_server/tests/test_mock_server.py"
],
"env": {
"PYTHONPATH": "${workspaceFolder}/integrations/mock_server/src:${PYTHONPATH}"
},
"console": "integratedTerminal",
"cwd": "${workspaceFolder}"
},
{
"name": "Python Debugger: test_dcl_server",
"type": "debugpy",
"request": "launch",
"program": "/workspace/connectedhomeip/examples/chip-tool/commands/dcl/test_dcl_server.py",
"args": [],
"program": "${workspaceFolder}/integrations/mock_server/src/main.py",
"args": [
"--port",
"8443",
"--config",
"${workspaceFolder}/integrations/mock_server/configurations/server_config.json",
"--routing-config-dir",
"${workspaceFolder}/integrations/mock_server/configurations/fake_distributed_compliance_ledger",
"--cert",
"${workspaceFolder}/server.crt",
"--key",
"${workspaceFolder}/server.key"
],
"console": "integratedTerminal"
},
{
Expand Down
251 changes: 0 additions & 251 deletions examples/chip-tool/commands/dcl/test_dcl_server.py

This file was deleted.

56 changes: 56 additions & 0 deletions integrations/mock_server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Mock HTTP/HTTPS Server

## Overview

This project provides a configurable mock HTTP/HTTPS server designed for API
testing, dynamic response generation, and automated request handling. It
supports static responses, dynamic custom response handlers, query parameter
matching, request body validation (including regex), and both HTTP and HTTPS
protocols.

## Setup

```bash
openssl req -x509 -newkey rsa:2048 -keyout server.key -out server.crt -days 365 -nodes -subj "/C=US/ST= /L= /O= /OU= /CN=localhost"
```

## Features

### Server Functionality

- Secure HTTPS with TLS support
- CLI-driven execution with customizable options (port, configuration files,
SSL options)
- Handles GET, POST, PUT, and DELETE requests
- Concurrent request handling via threading

### Route Matching

- Exact path and wildcard (\*) path matching
- Query parameter validation
- Priority-based route matching

### Configuration

- Main server configuration file
- Separate routing configuration directory
- JSON-based configuration format
- Dynamic route loading

### Security & Logging

- TLS encryption (HTTPS only)
- Structured logging with DEBUG level
- Graceful error handling for invalid routes

## Running Tests

### Test Execution

You can run the tests using one of these methods:

1. Using Python unittest with PYTHONPATH:

```bash
PYTHONPATH=$PYTHONPATH:/workspace/connectedhomeip/integrations/mock_server/src python3 -m unittest integrations/mock_server/tests/test_mock_server.py
```
Loading
Loading