Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

test: capture nginx rendering contract before extraction

Juan Denis2a030b31effe
diff --git a/backend/tests/fixtures/nginx-render-contract.json b/backend/tests/fixtures/nginx-render-contract.json
new file mode 100644
index 00000000..4d1497e6
--- /dev/null
+++ b/backend/tests/fixtures/nginx-render-contract.json
@@ -0,0 +1,10 @@
+{
+ "php": "e6d77fd5ac90d438b9f694b3dcf50d63746bd87f3e20030e0c4bd6e94c6f372a",
+ "wordpress": "e6d77fd5ac90d438b9f694b3dcf50d63746bd87f3e20030e0c4bd6e94c6f372a",
+ "flask": "dba3ba47c2d2407bcbcf3b8014bc6f5dc105db8a7e5837f849b871fd5960329b",
+ "django": "dba3ba47c2d2407bcbcf3b8014bc6f5dc105db8a7e5837f849b871fd5960329b",
+ "python": "dba3ba47c2d2407bcbcf3b8014bc6f5dc105db8a7e5837f849b871fd5960329b",
+ "docker": "a18576b49626ed0f88126de8946163720d715016ee24119de22afdb38fda4400",
+ "remote": "7bc871f2c95a333cfe14129ae40df409a3a2165e79fb7c9205510957c95af99f",
+ "static": "91d63c4279f9fa1fa1ecc1cfd0e3f8c5b63e134613d319ae189a4560d3738e28"
+}
diff --git a/backend/tests/test_nginx_render_contract.py b/backend/tests/test_nginx_render_contract.py
new file mode 100644
index 00000000..1368f345
--- /dev/null
+++ b/backend/tests/test_nginx_render_contract.py
@@ -0,0 +1,40 @@
+"""Byte-for-byte characterization of the pre-extraction vhost pipeline.
+
+The digest for each app type covers SSL, cache, immutable assets and WordPress
+protection together (including rejected combinations), plus TTL boundaries.
+Semantic assertions live in the existing nginx/cache/HTTPS suites. These hashes
+specifically detect accidental template whitespace or pipeline-order changes.
+"""
+import hashlib
+import itertools
+import json
+from pathlib import Path
+
+import pytest
+
+from app.services.nginx_service import NginxService
+
+
+APP_TYPES = ('php', 'wordpress', 'flask', 'django', 'python', 'docker', 'remote', 'static')
+SNAPSHOT = Path(__file__).with_name('fixtures') / 'nginx-render-contract.json'
+
+
+def render_contract(app_type):
+ results = []
+ for ssl, cache, immutable, wordpress in itertools.product((False, True), repeat=4):
+ for ttl in (None, 0, 10, 999):
+ results.append(NginxService.render_site_config(
+ 'shop', app_type, ['shop.example.com', 'www.shop.example.com'],
+ root_path='/srv/shop/public', port=8123, upstream='10.0.0.5:8123',
+ ssl_cert='/certs/shop.pem' if ssl else None,
+ ssl_key='/certs/shop.key' if ssl else None,
+ micro_cache=cache, micro_cache_ttl=ttl,
+ immutable_assets=immutable, wordpress_protection=wordpress,
+ ))
+ return hashlib.sha256(json.dumps(results, sort_keys=True).encode()).hexdigest()
+
+
[email protected]('app_type', APP_TYPES)
+def test_generated_vhosts_preserve_existing_output(app_type):
+ expected = json.loads(SNAPSHOT.read_text())
+ assert render_contract(app_type) == expected[app_type]