-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Testing] Refactor mock server to support distributed configuration l…
…oading (#37695) (#37713) * 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 * server: Add validation checks for SSL certificate and key files Add input validation to verify that SSL certificate and key files exist and are regular files before attempting to create the SSL context. This provides clearer error messages to users when certificate files are missing or invalid, following the same validation pattern used for config files.
- Loading branch information
1 parent
f654bba
commit 2b4717e
Showing
22 changed files
with
1,379 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
Oops, something went wrong.