client-api: Add a compat feature for Synapse's upload-signatures response

This commit is contained in:
Jonas Platte 2023-07-04 13:11:46 +02:00
parent 52aa539cf0
commit bbdc0b68e8
No known key found for this signature in database
GPG Key ID: AAA7A61F696C3E0C
3 changed files with 36 additions and 0 deletions

View File

@ -33,6 +33,10 @@ compat-unset-avatar = []
# even if its value is an empty list.
compat-get-3pids = []
# Accept `message` as an alias for `error` in `upload_signatures::v3::Failure`,
# since that's what Synapse sends.
compat-upload-signatures = []
unstable-exhaustive-types = ["ruma-common/unstable-exhaustive-types"]
unstable-msc2666 = []
unstable-msc2448 = []

View File

@ -101,6 +101,7 @@ pub mod v3 {
errcode: FailureErrorCode,
/// Human-readable error message.
#[cfg_attr(feature = "compat-upload-signatures", serde(alias = "message"))]
error: String,
}
@ -116,6 +117,33 @@ pub mod v3 {
#[doc(hidden)]
_Custom(PrivOwnedStr),
}
#[cfg(all(test, feature = "client", feature = "compat-upload-signatures"))]
mod tests {
use ruma_common::user_id;
use super::{FailureErrorCode, ResponseBody};
#[test]
fn deserialize_synapse_response() {
const JSON: &str = r#"{
"failures": {
"@richvdh:sw1v.org": {
"EOZDSWJVGZ": {
"status": 400,
"errcode": "M_INVALID_SIGNATURE",
"message": "400: Invalid signature"
}
}
}
}"#;
let parsed: ResponseBody = serde_json::from_str(JSON).unwrap();
let failure = &parsed.failures[user_id!("@richvdh:sw1v.org")]["EOZDSWJVGZ"];
assert_eq!(failure.errcode, FailureErrorCode::InvalidSignature);
assert_eq!(failure.error, "400: Invalid signature");
}
}
}
mod iter;

View File

@ -123,6 +123,9 @@ compat-unset-avatar = ["ruma-client-api?/compat-unset-avatar"]
# Always serialize the threepids response field in `get_3pids::v3::Response`,
# even if its value is an empty list.
compat-get-3pids = ["ruma-client-api?/compat-get-3pids"]
# Accept `message` as an alias for `error` in `upload_signatures::v3::Failure`,
# since that's what Synapse sends.
compat-upload-signatures = ["ruma-client-api?/compat-upload-signatures"]
# Allow extra characters in signature IDs not allowed in the specification.
compat-signature-id = ["ruma-signatures?/compat-signature-id"]
@ -192,6 +195,7 @@ unstable-unspecified = [
# Private feature, only used in test / benchmarking code
__ci = [
"full",
"compat-upload-signatures",
"unstable-unspecified",
"unstable-sanitize",
"unstable-msc1767",