From deb9b01a2a816faee8185709a3ddacea489cbd5c Mon Sep 17 00:00:00 2001 From: Timo Date: Wed, 12 Aug 2020 14:08:24 +0200 Subject: [PATCH] Remove origin field from transactions and pdus See https://github.com/matrix-org/synapse/issues/3816 --- ruma-events/Cargo.toml | 3 +++ ruma-events/src/pdu.rs | 6 ++++++ ruma-events/tests/pdu.rs | 10 ++++++++++ .../src/membership/create_join_event/mod.rs | 2 -- ruma-federation-api/src/serde/room_state.rs | 14 +++++--------- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/ruma-events/Cargo.toml b/ruma-events/Cargo.toml index a8255d3f49..accbd730ee 100644 --- a/ruma-events/Cargo.toml +++ b/ruma-events/Cargo.toml @@ -32,3 +32,6 @@ trybuild = "1.0.30" [[bench]] name = "event_deserialize" harness = false + +[features] +unstable-pre-spec = [] diff --git a/ruma-events/src/pdu.rs b/ruma-events/src/pdu.rs index 9bc411fff4..ae4970ba5d 100644 --- a/ruma-events/src/pdu.rs +++ b/ruma-events/src/pdu.rs @@ -38,6 +38,7 @@ pub struct RoomV1Pdu { /// The user id of the user who sent this event. pub sender: UserId, + #[cfg(not(feature = "unstable-pre-spec"))] /// The `server_name` of the homeserver that created this event. pub origin: String, @@ -96,6 +97,7 @@ pub struct RoomV3Pdu { /// The user id of the user who sent this event. pub sender: UserId, + #[cfg(not(feature = "unstable-pre-spec"))] /// The `server_name` of the homeserver that created this event. pub origin: String, @@ -172,6 +174,7 @@ pub struct RoomV1PduStub { /// The user id of the user who sent this event. pub sender: UserId, + #[cfg(not(feature = "unstable-pre-spec"))] /// The `server_name` of the homeserver that created this event. pub origin: String, @@ -226,6 +229,7 @@ impl RoomV1PduStub { event_id, room_id, sender: self.sender, + #[cfg(not(feature = "unstable-pre-spec"))] origin: self.origin, origin_server_ts: self.origin_server_ts, kind: self.kind, @@ -248,6 +252,7 @@ pub struct RoomV3PduStub { /// The user id of the user who sent this event. pub sender: UserId, + #[cfg(not(feature = "unstable-pre-spec"))] /// The `server_name` of the homeserver that created this event. pub origin: String, @@ -301,6 +306,7 @@ impl RoomV3PduStub { RoomV3Pdu { room_id, sender: self.sender, + #[cfg(not(feature = "unstable-pre-spec"))] origin: self.origin, origin_server_ts: self.origin_server_ts, kind: self.kind, diff --git a/ruma-events/tests/pdu.rs b/ruma-events/tests/pdu.rs index d4e7f25c26..4738bfee8c 100644 --- a/ruma-events/tests/pdu.rs +++ b/ruma-events/tests/pdu.rs @@ -12,6 +12,7 @@ use ruma_events::{ use ruma_identifiers::{event_id, room_id, user_id}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; +#[cfg(not(feature = "unstable-pre-spec"))] #[test] fn serialize_stub_as_v1() { let mut signatures = BTreeMap::new(); @@ -73,6 +74,7 @@ fn serialize_stub_as_v1() { assert_eq!(to_json_value(&pdu_stub).unwrap(), json); } +#[cfg(not(feature = "unstable-pre-spec"))] #[test] fn serialize_stub_as_v3() { let mut signatures = BTreeMap::new(); @@ -124,6 +126,7 @@ fn serialize_stub_as_v3() { assert_eq!(to_json_value(&pdu_stub).unwrap(), json); } +#[cfg(not(feature = "unstable-pre-spec"))] #[test] fn deserialize_stub_as_v1() { let json = json!({ @@ -181,6 +184,7 @@ fn deserialize_stub_as_v1() { } } +#[cfg(not(feature = "unstable-pre-spec"))] #[test] fn deserialize_stub_as_v3() { let json = json!({ @@ -224,6 +228,7 @@ fn deserialize_stub_as_v3() { } } +#[cfg(not(feature = "unstable-pre-spec"))] #[test] fn serialize_pdu_as_v1() { let mut signatures = BTreeMap::new(); @@ -289,6 +294,7 @@ fn serialize_pdu_as_v1() { assert_eq!(to_json_value(&pdu).unwrap(), json); } +#[cfg(not(feature = "unstable-pre-spec"))] #[test] fn serialize_pdu_as_v3() { let mut signatures = BTreeMap::new(); @@ -342,6 +348,7 @@ fn serialize_pdu_as_v3() { assert_eq!(to_json_value(&pdu_stub).unwrap(), json); } +#[cfg(not(feature = "unstable-pre-spec"))] #[test] fn test_deserialize_pdu_as_v1() { let json = json!({ @@ -401,6 +408,7 @@ fn test_deserialize_pdu_as_v1() { } } +#[cfg(not(feature = "unstable-pre-spec"))] #[test] fn deserialize_pdu_as_v3() { let json = json!({ @@ -445,6 +453,7 @@ fn deserialize_pdu_as_v3() { } } +#[cfg(not(feature = "unstable-pre-spec"))] #[test] fn convert_v1_stub_to_pdu() { let mut signatures = BTreeMap::new(); @@ -519,6 +528,7 @@ fn convert_v1_stub_to_pdu() { ); } +#[cfg(not(feature = "unstable-pre-spec"))] #[test] fn convert_v3_stub_to_pdu() { let mut signatures = BTreeMap::new(); diff --git a/ruma-federation-api/src/membership/create_join_event/mod.rs b/ruma-federation-api/src/membership/create_join_event/mod.rs index f216186f04..698296b8e2 100644 --- a/ruma-federation-api/src/membership/create_join_event/mod.rs +++ b/ruma-federation-api/src/membership/create_join_event/mod.rs @@ -9,8 +9,6 @@ use serde::{Deserialize, Serialize}; /// Full state of the room. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct RoomState { - /// The resident server's DNS name. - pub origin: String, /// The full set of authorization events that make up the state of the room, /// and their authorization events, recursively. pub auth_chain: Vec>, diff --git a/ruma-federation-api/src/serde/room_state.rs b/ruma-federation-api/src/serde/room_state.rs index 516e0717be..d857755376 100644 --- a/ruma-federation-api/src/serde/room_state.rs +++ b/ruma-federation-api/src/serde/room_state.rs @@ -69,7 +69,6 @@ mod tests { let response = json!([ 200, { - "origin": "example.com", "auth_chain": [], "state": [] } @@ -79,17 +78,15 @@ mod tests { assert_matches!( parsed, - RoomState { origin, auth_chain, state } - if origin == "example.com" - && auth_chain.is_empty() + RoomState { auth_chain, state } + if auth_chain.is_empty() && state.is_empty() ); } #[test] fn test_serialize_response() { - let room_state = - RoomState { origin: "matrix.org".into(), auth_chain: Vec::new(), state: Vec::new() }; + let room_state = RoomState { auth_chain: Vec::new(), state: Vec::new() }; let serialized = serialize(&room_state, serde_json::value::Serializer).unwrap(); let expected = to_json_value(&json!( @@ -137,9 +134,8 @@ mod tests { let json = json!([200, {"origin": "", "auth_chain": [], "state": []}, 200]); assert_matches!( deserialize(json).unwrap(), - RoomState { origin, auth_chain, state } - if origin == "" - && auth_chain.is_empty() + RoomState { auth_chain, state } + if auth_chain.is_empty() && state.is_empty() ); }