Unverified Commit 18a44498 authored by tgmichel's avatar tgmichel Committed by GitHub
Browse files

Remove `deny_unknown_fields` from `Request` and `Response` (#803)

* Remove `deny_unknown_fields`

* Update invalid request tests

* Remove `is_not_request_object` field from req in test

* Remove `deny_unknown_fields` from `Response`

* Add test to verify unknown field results in valid request
parent db00dd84
Pipeline #199893 failed with stages
in 6 minutes and 16 seconds
......@@ -346,12 +346,23 @@ async fn invalid_request_object() {
let (addr, _handle) = server().with_default_timeout().await.unwrap();
let uri = to_http_uri(addr);
let req = r#"{"jsonrpc":"2.0","method":"bar","id":1,"is_not_request_object":1}"#;
let req = r#"{"method":"bar","id":1}"#;
let response = http_request(req.into(), uri).with_default_timeout().await.unwrap().unwrap();
assert_eq!(response.status, StatusCode::OK);
assert_eq!(response.body, invalid_request(Id::Num(1)));
}
#[tokio::test]
async fn unknown_field_is_ok() {
let (addr, _handle) = server().with_default_timeout().await.unwrap();
let uri = to_http_uri(addr);
let req = r#"{"jsonrpc":"2.0","method":"say_hello","id":1,"is_not_request_object":1}"#;
let response = http_request(req.into(), uri).with_default_timeout().await.unwrap().unwrap();
assert_eq!(response.status, StatusCode::OK);
assert_eq!(response.body, ok_response(JsonValue::String("lo".to_owned()), Id::Num(1)));
}
#[tokio::test]
async fn notif_works() {
let (addr, _handle) = server().with_default_timeout().await.unwrap();
......
......@@ -34,7 +34,6 @@ use serde_json::value::RawValue;
/// JSON-RPC request object as defined in the [spec](https://www.jsonrpc.org/specification#request-object).
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct Request<'a> {
/// JSON-RPC version.
pub jsonrpc: TwoPointZero,
......@@ -67,7 +66,6 @@ pub struct InvalidRequest<'a> {
/// JSON-RPC notification (a request object without a request ID) as defined in the
/// [spec](https://www.jsonrpc.org/specification#request-object).
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct Notification<'a, T> {
/// JSON-RPC version.
pub jsonrpc: TwoPointZero,
......
......@@ -34,7 +34,6 @@ use serde::{Deserialize, Serialize};
/// JSON-RPC successful response object as defined in the [spec](https://www.jsonrpc.org/specification#response_object).
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct Response<'a, T> {
/// JSON-RPC version.
pub jsonrpc: TwoPointZero,
......
......@@ -496,11 +496,21 @@ async fn invalid_request_object() {
let addr = server().await;
let mut client = WebSocketTestClient::new(addr).with_default_timeout().await.unwrap().unwrap();
let req = r#"{"jsonrpc":"2.0","method":"bar","id":1,"is_not_request_object":1}"#;
let req = r#"{"method":"bar","id":1}"#;
let response = client.send_request_text(req).with_default_timeout().await.unwrap().unwrap();
assert_eq!(response, invalid_request(Id::Num(1)));
}
#[tokio::test]
async fn unknown_field_is_ok() {
let addr = server().await;
let mut client = WebSocketTestClient::new(addr).with_default_timeout().await.unwrap().unwrap();
let req = r#"{"jsonrpc":"2.0","method":"say_hello","id":1,"is_not_request_object":1}"#;
let response = client.send_request_text(req).with_default_timeout().await.unwrap().unwrap();
assert_eq!(response, ok_response(JsonValue::String("hello".to_owned()), Id::Num(1)));
}
#[tokio::test]
async fn register_methods_works() {
let mut module = RpcModule::new(());
......@@ -545,7 +555,7 @@ async fn invalid_request_should_not_close_connection() {
let addr = server().await;
let mut client = WebSocketTestClient::new(addr).with_default_timeout().await.unwrap().unwrap();
let req = r#"{"jsonrpc":"2.0","method":"bar","id":1,"is_not_request_object":1}"#;
let req = r#"{"method":"bar","id":1}"#;
let response = client.send_request_text(req).with_default_timeout().await.unwrap().unwrap();
assert_eq!(response, invalid_request(Id::Num(1)));
let request = r#"{"jsonrpc":"2.0","method":"say_hello","id":33}"#;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment