Skip to content

Commit 33038c0

Browse files
committed
tests/rptest: cover unmatched-route 404 shape on REST proxy and SR
Asserts that GET on a bogus path returns HTTP 404 with the {"error_code": 404, "message": "..."} envelope clients expect, rather than Seastar's fallback {"message": "Not found", "code": 404}. Two assertions, one per port: - Schema registry (8081) in schema_registry_test.py - REST proxy (8082) in pandaproxy_test.py Both subsystems use pandaproxy::server, so the fix in pandaproxy::server::start() lands on both. Locking in both wire formats end-to-end is the test that proves the default_404_handler registration works for both consumers. Removing the add_default_handler line would regress the body shape and fail both assertions in CI.
1 parent c14697b commit 33038c0

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

tests/rptest/tests/pandaproxy_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,25 @@ def test_get_brokers(self):
502502

503503
assert sorted(brokers) == sorted(node_idxs)
504504

505+
@cluster(num_nodes=3)
506+
def test_unmatched_route_404_shape(self):
507+
"""
508+
Unmatched routes on REST proxy must return the standard
509+
{"error_code": <int>, "message": "..."} JSON envelope, not Seastar's
510+
fallback {"message": "Not found", "code": 404}. The fix lives in
511+
pandaproxy::server, which both REST proxy and schema registry share,
512+
so this assertion mirrors the schema-registry-side test.
513+
"""
514+
result_raw = requests.get(f"{self._base_uri()}/_no_such_path")
515+
assert result_raw.status_code == requests.codes.not_found, (
516+
f"expected 404, got {result_raw.status_code}: {result_raw.text}"
517+
)
518+
519+
body = result_raw.json()
520+
assert "error_code" in body, f"expected error_code field, got body={body}"
521+
assert body["error_code"] == 404, f"expected error_code=404, got body={body}"
522+
assert "message" in body, f"expected message field, got body={body}"
523+
505524
@cluster(num_nodes=3)
506525
def test_list_topics_validation(self):
507526
"""

tests/rptest/tests/schema_registry_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,25 @@ def test_schemas_types(self):
15631563
result = result_raw.json()
15641564
assert set(result) == {"JSON", "PROTOBUF", "AVRO"}
15651565

1566+
@cluster(num_nodes=3)
1567+
def test_unmatched_route_404_shape(self):
1568+
"""
1569+
Unmatched routes on schema registry must return the standard
1570+
{"error_code": <int>, "message": "..."} JSON envelope, not Seastar's
1571+
fallback {"message": "Not found", "code": 404}. SR clients parse
1572+
`error_code`; without this shape, fallback paths that inspect 404
1573+
bodies produce a 0-coded error.
1574+
"""
1575+
result_raw = self.sr_client.request("GET", "_no_such_path")
1576+
assert result_raw.status_code == requests.codes.not_found, (
1577+
f"expected 404, got {result_raw.status_code}: {result_raw.text}"
1578+
)
1579+
1580+
body = result_raw.json()
1581+
assert "error_code" in body, f"expected error_code field, got body={body}"
1582+
assert body["error_code"] == 404, f"expected error_code=404, got body={body}"
1583+
assert "message" in body, f"expected message field, got body={body}"
1584+
15661585
@cluster(num_nodes=3)
15671586
def test_get_schema_id_versions(self):
15681587
"""

0 commit comments

Comments
 (0)