fix: harden UCE runtime and starter
This commit is contained in:
@@ -9,6 +9,14 @@ def register(registry):
|
||||
("doc relative time page", "/doc/index.uce?p=time_format_relative", "time_format_relative"),
|
||||
]
|
||||
|
||||
starter_pages = [
|
||||
("starter home", "/examples/uce-starter/", 200, "Stunning Apps"),
|
||||
("starter dashboard", "/examples/uce-starter/?dashboard", 200, "Dashboard"),
|
||||
("starter workspace nested route", "/examples/uce-starter/?workspace/projects", 200, "Workspace"),
|
||||
("starter ajax section", "/examples/uce-starter/?page2-section1", 200, "UCE starter AJAX fragment response"),
|
||||
("starter route traversal blocked", "/examples/uce-starter/?../../../demo/index", 404, "The requested page does not exist."),
|
||||
]
|
||||
|
||||
for name, path, needle in pages:
|
||||
def make_case(page_path=path, expected_text=needle):
|
||||
def run(context):
|
||||
@@ -19,3 +27,14 @@ def register(registry):
|
||||
return run
|
||||
|
||||
registry.case(name, make_case(), tags=["http", "smoke", "uce", "public"])
|
||||
|
||||
for name, path, status, needle in starter_pages:
|
||||
def make_starter_case(page_path=path, expected_status=status, expected_text=needle):
|
||||
def run(context):
|
||||
response = context.expect_status(page_path, expected_status)
|
||||
context.expect_body_contains(response, expected_text)
|
||||
return "starter route %s returned HTTP %s with expected marker" % (page_path, expected_status)
|
||||
|
||||
return run
|
||||
|
||||
registry.case(name, make_starter_case(), tags=["http", "smoke", "uce", "public", "starter"])
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
from pathlib import Path
|
||||
|
||||
from run_network_tests import TestFailure
|
||||
|
||||
ERROR_MARKERS = [
|
||||
"compile error",
|
||||
"runtime error",
|
||||
@@ -6,37 +10,95 @@ ERROR_MARKERS = [
|
||||
]
|
||||
|
||||
|
||||
def _repo_root():
|
||||
return Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
def _parse_manifest(manifest_path):
|
||||
manifest = {}
|
||||
if not manifest_path.exists():
|
||||
return manifest
|
||||
for raw_line in manifest_path.read_text(encoding="utf-8").splitlines():
|
||||
line = raw_line.strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
parts = [part.strip() for part in line.split("|")]
|
||||
if len(parts) < 7:
|
||||
continue
|
||||
file_name, title, description, tags, expected, suite, index = parts[:7]
|
||||
manifest[file_name] = {
|
||||
"file": file_name,
|
||||
"title": title,
|
||||
"description": description,
|
||||
"tags": tags.split(),
|
||||
"expected": expected,
|
||||
"suite": suite == "1",
|
||||
"index": index == "1",
|
||||
}
|
||||
return manifest
|
||||
|
||||
|
||||
def _case_name(file_name):
|
||||
if file_name == "index.uce":
|
||||
return "site tests index"
|
||||
if file_name == "io.uce":
|
||||
return "site tests filesystem"
|
||||
if file_name == "websockets.ws.uce":
|
||||
return "site tests websockets page"
|
||||
stem = file_name
|
||||
if stem.endswith(".uce"):
|
||||
stem = stem[:-4]
|
||||
if stem.endswith(".ws"):
|
||||
stem = stem[:-3]
|
||||
return "site tests " + stem.replace("_", " ")
|
||||
|
||||
|
||||
def _make_missing_metadata_case(file_name):
|
||||
def run(context):
|
||||
raise TestFailure("site/tests/%s is missing from site/tests/manifest.txt" % file_name)
|
||||
return run
|
||||
|
||||
|
||||
def _make_suite_case(page_path, expected_title):
|
||||
def run(context):
|
||||
response = context.expect_status(page_path, 200)
|
||||
context.expect_body_contains(response, expected_title)
|
||||
|
||||
body_lower = response.text.lower()
|
||||
for marker in ERROR_MARKERS:
|
||||
if marker in body_lower:
|
||||
raise Exception("response body contained error marker %r for %s" % (marker, page_path))
|
||||
if '<div class="tests-summary">' in body_lower and ('>fail</span>' in body_lower or '>failed 0<' not in body_lower):
|
||||
raise Exception("site suite reported failed cases for %s" % page_path)
|
||||
|
||||
return "HTTP 200 with suite page marker and no failed cases for %s" % page_path
|
||||
|
||||
return run
|
||||
|
||||
|
||||
def register(registry):
|
||||
pages = [
|
||||
("site tests index", "/tests/index.uce", "Coverage Index", ["http", "suite", "uce", "public"]),
|
||||
("site tests core", "/tests/core.uce", "Core APIs", ["http", "suite", "uce", "public"]),
|
||||
("site tests preprocessor", "/tests/preprocessor.uce", "top-level )\" marker", ["http", "suite", "uce", "public"]),
|
||||
("site tests http", "/tests/http.uce", "HTTP And Session", ["http", "suite", "uce", "public"]),
|
||||
("site tests components", "/tests/components.uce", "Components", ["http", "suite", "uce", "public"]),
|
||||
("site tests markdown", "/tests/markdown.uce", "Markdown", ["http", "suite", "uce", "public"]),
|
||||
("site tests units", "/tests/units.uce", "Units", ["http", "suite", "uce", "public"]),
|
||||
("site tests websockets page", "/tests/websockets.ws.uce", "WebSockets", ["http", "suite", "uce", "public", "websocket"]),
|
||||
("site tests filesystem", "/tests/io.uce", "Filesystem", ["http", "suite", "uce", "internal"]),
|
||||
("site tests zip", "/tests/zip.uce", "ZIP", ["http", "suite", "uce", "internal"]),
|
||||
("site tests services", "/tests/services.uce", "Sockets And Services", ["http", "suite", "uce", "internal"]),
|
||||
("site tests tasks", "/tests/tasks.uce", "Tasks", ["http", "suite", "uce", "internal"]),
|
||||
]
|
||||
repo = _repo_root()
|
||||
tests_dir = repo / "site" / "tests"
|
||||
manifest = _parse_manifest(tests_dir / "manifest.txt")
|
||||
|
||||
for name, path, title, tags in pages:
|
||||
def make_case(page_path=path, expected_title=title):
|
||||
def run(context):
|
||||
response = context.expect_status(page_path, 200)
|
||||
context.expect_body_contains(response, expected_title)
|
||||
|
||||
body_lower = response.text.lower()
|
||||
for marker in ERROR_MARKERS:
|
||||
if marker in body_lower:
|
||||
raise Exception("response body contained error marker %r for %s" % (marker, page_path))
|
||||
if '<div class="tests-summary">' in body_lower and ('>fail</span>' in body_lower or '>failed 0<' not in body_lower):
|
||||
raise Exception("site suite reported failed cases for %s" % page_path)
|
||||
|
||||
return "HTTP 200 with suite page marker and no failed cases for %s" % page_path
|
||||
|
||||
return run
|
||||
|
||||
registry.case(name, make_case(), tags=tags)
|
||||
for path in sorted(tests_dir.glob("*.uce")):
|
||||
file_name = path.name
|
||||
meta = manifest.get(file_name)
|
||||
if not meta:
|
||||
registry.case(
|
||||
_case_name(file_name),
|
||||
_make_missing_metadata_case(file_name),
|
||||
tags=["http", "suite", "uce", "metadata", "internal"],
|
||||
)
|
||||
continue
|
||||
if not meta["suite"]:
|
||||
continue
|
||||
tags = list(meta["tags"])
|
||||
for tag in ["http", "suite", "uce"]:
|
||||
if tag not in tags:
|
||||
tags.append(tag)
|
||||
registry.case(
|
||||
_case_name(file_name),
|
||||
_make_suite_case("/tests/" + file_name, meta["expected"] or meta["title"]),
|
||||
tags=tags,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user