Add a test regarding ser/de of an UserId in a DirectUserIdentifier (#1968)

Add a test to check that a serialized UserId can be deserialized to an OwnedDirectUserIdentifier.

Also fixes Clippy failures.
This commit is contained in:
Mathieu Velten 2024-12-05 10:27:21 +00:00 committed by strawberry
parent bc8b704e5b
commit 9af36342ff
2 changed files with 7 additions and 1 deletions

View File

@ -722,7 +722,7 @@ impl OutgoingResponse for UiaaResponse {
match self { match self {
UiaaResponse::AuthResponse(authentication_info) => http::Response::builder() UiaaResponse::AuthResponse(authentication_info) => http::Response::builder()
.header(http::header::CONTENT_TYPE, "application/json") .header(http::header::CONTENT_TYPE, "application/json")
.status(&http::StatusCode::UNAUTHORIZED) .status(http::StatusCode::UNAUTHORIZED)
.body(ruma_common::serde::json_to_buf(&authentication_info)?) .body(ruma_common::serde::json_to_buf(&authentication_info)?)
.map_err(Into::into), .map_err(Into::into),
UiaaResponse::MatrixError(error) => error.try_into_http_response(), UiaaResponse::MatrixError(error) => error.try_into_http_response(),

View File

@ -267,5 +267,11 @@ mod tests {
assert_eq!(alice_direct_uid_mail, alice_user_id.to_owned()); assert_eq!(alice_direct_uid_mail, alice_user_id.to_owned());
assert_eq!(alice_user_id, alice_direct_uid_mail); assert_eq!(alice_user_id, alice_direct_uid_mail);
assert_eq!(alice_user_id.to_owned(), alice_direct_uid_mail); assert_eq!(alice_user_id.to_owned(), alice_direct_uid_mail);
let alice_user_id = user_id!("@alice:ruma.io");
let alice_user_id_json = to_json_value(alice_user_id).unwrap();
let alice_direct_uid_mail: OwnedDirectUserIdentifier =
from_json_value(alice_user_id_json).unwrap();
assert_eq!(alice_user_id, alice_direct_uid_mail);
} }
} }