This commit is contained in:
parent
b16c2a8518
commit
bd84329a08
1 changed files with 55 additions and 2 deletions
|
|
@ -473,3 +473,31 @@ def test_sse_message_id_coercion():
|
|||
json_message = '{"jsonrpc": "2.0", "id": "123", "method": "ping", "params": null}'
|
||||
msg = types.JSONRPCMessage.model_validate_json(json_message)
|
||||
assert msg == snapshot(types.JSONRPCMessage(root=types.JSONRPCRequest(method="ping", jsonrpc="2.0", id=123)))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"endpoint, expected_result",
|
||||
[
|
||||
# Valid endpoints - should normalize and work
|
||||
("/messages/", "/messages/"),
|
||||
("messages/", "/messages/"),
|
||||
("/", "/"),
|
||||
# Invalid endpoints - should raise ValueError
|
||||
("http://example.com/messages/", ValueError),
|
||||
("//example.com/messages/", ValueError),
|
||||
("ftp://example.com/messages/", ValueError),
|
||||
("/messages/?param=value", ValueError),
|
||||
("/messages/#fragment", ValueError),
|
||||
],
|
||||
)
|
||||
def test_sse_server_transport_endpoint_validation(endpoint: str, expected_result: str | type[Exception]):
|
||||
"""Test that SseServerTransport properly validates and normalizes endpoints."""
|
||||
if isinstance(expected_result, type) and issubclass(expected_result, Exception):
|
||||
# Test invalid endpoints that should raise an exception
|
||||
with pytest.raises(expected_result, match="is not a relative path.*expecting a relative path"):
|
||||
SseServerTransport(endpoint)
|
||||
else:
|
||||
# Test valid endpoints that should normalize correctly
|
||||
sse = SseServerTransport(endpoint)
|
||||
assert sse._endpoint == expected_result
|
||||
assert sse._endpoint.startswith("/")
|
||||
|
|
|
|||
Loading…
Reference in a new issue