Remove Python app example and replace with header-echo server for testing
- Deleted the `/examples/docker/python-app` directory and associated files. - Integrated a custom `header-echo` server for Kubernetes and Docker Compose tests. - Updated Kubernetes and Docker Compose configurations to use the new `header-echo-server:test` image. - Enhanced Kubernetes integration tests to validate JSON responses and Cloudflare IP translation behavior.
This commit is contained in:
parent
1fd5873dc9
commit
b34d7822e4
6 changed files with 139 additions and 14 deletions
11
examples/fixtures/header-echo/Dockerfile
Normal file
11
examples/fixtures/header-echo/Dockerfile
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
FROM python:3.12-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY server.py .
|
||||
|
||||
RUN chmod +x server.py
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
CMD ["python3", "server.py"]
|
||||
66
examples/fixtures/header-echo/README.md
Normal file
66
examples/fixtures/header-echo/README.md
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
# Header Echo Server - Test Fixture
|
||||
|
||||
A lightweight Python HTTP server that echoes all request headers as JSON. Used for testing HAProxy plugins that manipulate headers and client IPs.
|
||||
|
||||
## Purpose
|
||||
|
||||
This test fixture is used by both Docker Compose and Kubernetes test suites to verify:
|
||||
- Header manipulation (e.g., X-Forwarded-For, CF-Connecting-IP)
|
||||
- IP restoration plugins (Cloudflare, custom CDN integrations)
|
||||
- Request routing and backend visibility
|
||||
|
||||
## Usage
|
||||
|
||||
### Docker Compose
|
||||
```yaml
|
||||
services:
|
||||
webapp:
|
||||
build: ../fixtures/header-echo
|
||||
ports:
|
||||
- "8080:8080"
|
||||
```
|
||||
|
||||
### Kubernetes
|
||||
```bash
|
||||
# Build and load into kind cluster
|
||||
docker build -t header-echo-server:test .
|
||||
kind load docker-image header-echo-server:test --name your-cluster
|
||||
|
||||
# Use in deployment
|
||||
spec:
|
||||
containers:
|
||||
- name: webapp
|
||||
image: header-echo-server:test
|
||||
imagePullPolicy: Never
|
||||
```
|
||||
|
||||
### Manual Testing
|
||||
```bash
|
||||
# Start the server
|
||||
python3 server.py
|
||||
|
||||
# Test it
|
||||
curl http://localhost:8080
|
||||
# Returns JSON with all headers, client IP, and X-Forwarded-For value
|
||||
```
|
||||
|
||||
## Response Format
|
||||
|
||||
```json
|
||||
{
|
||||
"headers": {
|
||||
"Host": "localhost:8080",
|
||||
"User-Agent": "curl/7.81.0",
|
||||
"Accept": "*/*"
|
||||
},
|
||||
"client_ip": "127.0.0.1",
|
||||
"x_forwarded_for": "NOT SET"
|
||||
}
|
||||
```
|
||||
|
||||
## Used By
|
||||
|
||||
- `examples/docker/docker-compose-cloudflare.yml`
|
||||
- `examples/docker/test_docker_compose.py::TestCloudflare`
|
||||
- `examples/kubernetes/cloudflare.yml`
|
||||
- `examples/kubernetes/test_kubernetes.py::TestCloudflare`
|
||||
33
examples/fixtures/header-echo/server.py
Normal file
33
examples/fixtures/header-echo/server.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Simple HTTP server that echoes all request headers"""
|
||||
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
import json
|
||||
|
||||
class HeaderEchoHandler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
|
||||
# Collect all headers
|
||||
headers = dict(self.headers)
|
||||
|
||||
# Add the client IP as seen by this server
|
||||
response = {
|
||||
'headers': headers,
|
||||
'client_ip': self.client_address[0],
|
||||
'x_forwarded_for': self.headers.get('X-Forwarded-For', 'NOT SET')
|
||||
}
|
||||
|
||||
self.wfile.write(json.dumps(response, indent=2).encode())
|
||||
|
||||
def log_message(self, format, *args):
|
||||
# Log to stdout
|
||||
print(f"{self.address_string()} - {format % args}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
port = 8080
|
||||
server = HTTPServer(('0.0.0.0', port), HeaderEchoHandler)
|
||||
print(f'Header echo server running on port {port}...')
|
||||
server.serve_forever()
|
||||
Loading…
Add table
Add a link
Reference in a new issue