client-api: Fix get_login_types::CustomLoginType

Add test for it.
This commit is contained in:
Kévin Commaille 2022-01-01 12:54:59 +01:00
parent 9ee0436eb8
commit fac7d53134
No known key found for this signature in database
GPG Key ID: DD507DAE96E8245C
2 changed files with 28 additions and 2 deletions

View File

@ -1,5 +1,9 @@
# [unreleased]
Bug fixes:
* Fix deserialization of `r0::session::get_login_types::CustomLoginType`.
Breaking changes:
* Use an enum for user-interactive auth stage type (used to be `&str` / `String`)

View File

@ -242,7 +242,7 @@ pub struct CustomLoginType {
///
/// This field is named `type_` instead of `type` because the latter is a reserved
/// keyword in Rust.
#[serde(rename = "override")]
#[serde(rename = "type")]
pub type_: String,
/// Remaining type content
@ -260,9 +260,9 @@ mod tests {
use serde_json::to_value as to_json_value;
use serde_json::{from_value as from_json_value, json};
use super::{CustomLoginType, LoginType, PasswordLoginType};
#[cfg(feature = "unstable-pre-spec")]
use super::{IdentityProvider, IdentityProviderBrand, SsoLoginType, TokenLoginType};
use super::{LoginType, PasswordLoginType};
#[derive(Debug, Deserialize, Serialize)]
struct Wrapper {
@ -283,6 +283,28 @@ mod tests {
);
}
#[test]
fn deserialize_custom_login_type() {
assert_matches!(
from_json_value::<Wrapper>(json!({
"flows": [
{
"type": "io.ruma.custom",
"color": "green",
}
],
})),
Ok(Wrapper { flows })
if flows.len() == 1
&& matches!(
&flows[0],
LoginType::_Custom(CustomLoginType { type_, data })
if type_ == "io.ruma.custom"
&& data == json!({ "color": "green" }).as_object().unwrap()
)
);
}
#[test]
#[cfg(feature = "unstable-pre-spec")]
fn deserialize_sso_login_type() {