Skip to content

Commit afcf2f4

Browse files
test(conformance): cover the REST route and unlisted JSON-RPC methods
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent 49c2ab3 commit afcf2f4

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎tests/suites/conformance/src/network_l7.rs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ async fn graphql_rules_allow_and_deny_operations(cx: &mut Context) -> testkit::R
145145
}
146146

147147
/// JSON-RPC rules allow listed methods whatever their params, deny a
148-
/// deny-rule method, a batch with one denied call, and invalid JSON, through
149-
/// urllib and raw sockets.
148+
/// deny-rule method, an unlisted method, a batch with one denied call, and
149+
/// invalid JSON, through urllib and raw sockets. A REST endpoint on the same
150+
/// port still allows requests outside the RPC path.
150151
#[testkit::test]
151152
async fn jsonrpc_rules_allow_and_deny_methods(cx: &mut Context) -> testkit::Result {
152153
let server = HttpRecorder::serve(jsonrpc_upstream).await?;
@@ -155,6 +156,11 @@ async fn jsonrpc_rules_allow_and_deny_methods(cx: &mut Context) -> testkit::Resu
155156
jsonrpc:
156157
name: jsonrpc
157158
endpoints:
159+
- host: {TEST_HOST}
160+
port: {port}
161+
protocol: rest
162+
enforcement: enforce
163+
access: read-write
158164
- host: {TEST_HOST}
159165
port: {port}
160166
path: /rpc
@@ -194,11 +200,13 @@ async fn jsonrpc_rules_allow_and_deny_methods(cx: &mut Context) -> testkit::Resu
194200
("method_tools_call_allowed", 200),
195201
("method_tools_call_with_unmatched_params_allowed", 200),
196202
("method_tools_delete_denied", 403),
203+
("unlisted_method_denied", 403),
197204
] {
198205
expected.push((format!("{path}_{key}"), status));
199206
}
200207
}
201208
for (key, status) in [
209+
("rest_route_allowed", 200),
202210
("forward_batch_all_allowed", 200),
203211
("forward_batch_one_denied", 403),
204212
("forward_invalid_json_denied", 403),

‎tests/support/sandbox-clients/scripts/jsonrpc_client.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ def raw_jsonrpc_status(method, params, label):
162162
return raw_http_status(label, request)
163163

164164
results = {
165+
# The broad REST endpoint still permits requests outside the RPC route.
166+
"rest_route_allowed": raw_http_status("rest_route_allowed", (
167+
f"POST /api/status HTTP/1.1\r\n"
168+
f"Host: {HOST}:{PORT}\r\n"
169+
f"Content-Length: 0\r\nConnection: close\r\n\r\n"
170+
).encode()),
165171
# forward proxy — method-only allow rules
166172
"forward_method_initialize_allowed": post_jsonrpc("forward_method_initialize_allowed", "initialize", {"protocolVersion": "2025-11-25", "capabilities": {}}),
167173
"forward_method_tools_list_allowed": post_jsonrpc("forward_method_tools_list_allowed", "tools/list"),
@@ -170,6 +176,7 @@ def raw_jsonrpc_status(method, params, label):
170176
"forward_method_tools_call_allowed": post_jsonrpc("forward_method_tools_call_allowed", "tools/call", {"name": "read_status"}),
171177
"forward_method_tools_call_with_unmatched_params_allowed": post_jsonrpc("forward_method_tools_call_with_unmatched_params_allowed", "tools/call", {"name": "blocked_action", "arguments": {"scope": "ignored"}}),
172178
"forward_method_tools_delete_denied": post_jsonrpc("forward_method_tools_delete_denied", "tools/delete", {"name": "purge_cache"}),
179+
"forward_unlisted_method_denied": post_jsonrpc("forward_unlisted_method_denied", "admin.delete"),
173180

174181
# forward proxy — batch: all requests allowed
175182
"forward_batch_all_allowed": post_jsonrpc_batch("forward_batch_all_allowed", [
@@ -192,6 +199,7 @@ def raw_jsonrpc_status(method, params, label):
192199
"raw_method_tools_call_allowed": raw_jsonrpc_status("tools/call", {"name": "read_status"}, "raw_method_tools_call_allowed"),
193200
"raw_method_tools_call_with_unmatched_params_allowed": raw_jsonrpc_status("tools/call", {"name": "blocked_action", "arguments": {"scope": "ignored"}}, "raw_method_tools_call_with_unmatched_params_allowed"),
194201
"raw_method_tools_delete_denied": raw_jsonrpc_status("tools/delete", {"name": "purge_cache"}, "raw_method_tools_delete_denied"),
202+
"raw_unlisted_method_denied": raw_jsonrpc_status("admin.delete", None, "raw_unlisted_method_denied"),
195203
}
196204
results.update(DETAILS)
197205
print(json.dumps(results, sort_keys=True))

0 commit comments

Comments
 (0)