Add a test for ruma_signatures::canonical_json

This commit is contained in:
Jonas Platte 2020-06-06 20:36:01 +02:00
parent f6fb971329
commit db4c0b2134
No known key found for this signature in database
GPG Key ID: 7D261D771D915378

View File

@ -729,3 +729,37 @@ pub fn redact(value: &Value) -> Result<Value, Error> {
Ok(owned_value) Ok(owned_value)
} }
#[cfg(test)]
mod tests {
use serde_json::json;
use super::canonical_json;
#[test]
fn canonical_json_complex() {
let data = json!({
"auth": {
"success": true,
"mxid": "@john.doe:example.com",
"profile": {
"display_name": "John Doe",
"three_pids": [
{
"medium": "email",
"address": "john.doe@example.org"
},
{
"medium": "msisdn",
"address": "123456789"
}
]
}
}
});
let canonical = r#"{"auth":{"mxid":"@john.doe:example.com","profile":{"display_name":"John Doe","three_pids":[{"address":"john.doe@example.org","medium":"email"},{"address":"123456789","medium":"msisdn"}]},"success":true}}"#;
assert_eq!(canonical_json(&data).unwrap(), canonical);
}
}