client-api: Split some test assertions
This commit is contained in:
parent
63ec3a43aa
commit
c1d10b1061
@ -57,8 +57,6 @@ pub mod v3 {
|
|||||||
|
|
||||||
#[cfg(all(test, any(feature = "client", feature = "server")))]
|
#[cfg(all(test, any(feature = "client", feature = "server")))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
|
||||||
|
|
||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_request() {
|
fn deserialize_request() {
|
||||||
@ -66,17 +64,15 @@ pub mod v3 {
|
|||||||
|
|
||||||
use super::IncomingRequest;
|
use super::IncomingRequest;
|
||||||
|
|
||||||
let req = assert_matches!(
|
let req = IncomingRequest::try_from_http_request(
|
||||||
IncomingRequest::try_from_http_request(
|
http::Request::builder()
|
||||||
http::Request::builder()
|
.method(http::Method::POST)
|
||||||
.method(http::Method::POST)
|
.uri("https://matrix.org/_matrix/client/r0/user/@foo:bar.com/filter")
|
||||||
.uri("https://matrix.org/_matrix/client/r0/user/@foo:bar.com/filter")
|
.body(b"{}" as &[u8])
|
||||||
.body(b"{}" as &[u8])
|
.unwrap(),
|
||||||
.unwrap(),
|
&["@foo:bar.com"],
|
||||||
&["@foo:bar.com"]
|
)
|
||||||
),
|
.unwrap();
|
||||||
Ok(req) => req
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(req.user_id, "@foo:bar.com");
|
assert_eq!(req.user_id, "@foo:bar.com");
|
||||||
assert!(req.filter.is_empty());
|
assert!(req.filter.is_empty());
|
||||||
@ -92,15 +88,14 @@ pub mod v3 {
|
|||||||
|
|
||||||
use crate::filter::FilterDefinition;
|
use crate::filter::FilterDefinition;
|
||||||
|
|
||||||
assert_matches!(
|
let req = super::Request::new(user_id!("@foo:bar.com"), FilterDefinition::default())
|
||||||
super::Request::new(user_id!("@foo:bar.com"), FilterDefinition::default())
|
.try_into_http_request::<Vec<u8>>(
|
||||||
.try_into_http_request::<Vec<u8>>(
|
"https://matrix.org",
|
||||||
"https://matrix.org",
|
SendAccessToken::IfRequired("tok"),
|
||||||
SendAccessToken::IfRequired("tok"),
|
&[MatrixVersion::V1_1],
|
||||||
&[MatrixVersion::V1_1]
|
)
|
||||||
),
|
.unwrap();
|
||||||
Ok(res) if res.body() == b"{}"
|
assert_eq!(req.body(), b"{}");
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,19 +56,16 @@ pub mod v3 {
|
|||||||
|
|
||||||
#[cfg(all(test, any(feature = "client", feature = "server")))]
|
#[cfg(all(test, any(feature = "client", feature = "server")))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_response() {
|
fn deserialize_response() {
|
||||||
use ruma_common::api::IncomingResponse;
|
use ruma_common::api::IncomingResponse;
|
||||||
|
|
||||||
assert_matches!(
|
let res = super::Response::try_from_http_response(
|
||||||
super::Response::try_from_http_response(
|
http::Response::builder().body(b"{}" as &[u8]).unwrap(),
|
||||||
http::Response::builder().body(b"{}" as &[u8]).unwrap(),
|
)
|
||||||
),
|
.unwrap();
|
||||||
Ok(super::Response { filter }) if filter.is_empty()
|
assert!(res.filter.is_empty());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
@ -78,11 +75,10 @@ pub mod v3 {
|
|||||||
|
|
||||||
use crate::filter::IncomingFilterDefinition;
|
use crate::filter::IncomingFilterDefinition;
|
||||||
|
|
||||||
assert_matches!(
|
let res = super::Response::new(IncomingFilterDefinition::default())
|
||||||
super::Response::new(IncomingFilterDefinition::default())
|
.try_into_http_response::<Vec<u8>>()
|
||||||
.try_into_http_response::<Vec<u8>>(),
|
.unwrap();
|
||||||
Ok(res) if res.body() == b"{}"
|
assert_eq!(res.body(), b"{}");
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,6 @@ pub mod v3 {
|
|||||||
|
|
||||||
#[cfg(all(test, feature = "server"))]
|
#[cfg(all(test, feature = "server"))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
|
||||||
use ruma_common::api::IncomingRequest as _;
|
use ruma_common::api::IncomingRequest as _;
|
||||||
|
|
||||||
use super::{IncomingRequest, MembershipEventFilter};
|
use super::{IncomingRequest, MembershipEventFilter};
|
||||||
@ -123,17 +122,13 @@ pub mod v3 {
|
|||||||
let req = IncomingRequest::try_from_http_request(
|
let req = IncomingRequest::try_from_http_request(
|
||||||
http::Request::builder().uri(uri).body(&[] as &[u8]).unwrap(),
|
http::Request::builder().uri(uri).body(&[] as &[u8]).unwrap(),
|
||||||
&["!dummy:example.org"],
|
&["!dummy:example.org"],
|
||||||
);
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_matches!(
|
assert_eq!(req.room_id, "!dummy:example.org");
|
||||||
req,
|
assert_eq!(req.at.as_deref(), Some("1026"));
|
||||||
Ok(IncomingRequest {
|
assert_eq!(req.membership, None);
|
||||||
room_id,
|
assert_eq!(req.not_membership, Some(MembershipEventFilter::Leave));
|
||||||
at: Some(at),
|
|
||||||
membership: None,
|
|
||||||
not_membership: Some(MembershipEventFilter::Leave),
|
|
||||||
}) if room_id == "!dummy:example.org" && at == "1026"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ pub mod v3 {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
use ruma_common::{thirdparty::Medium, user_id};
|
use ruma_common::thirdparty::Medium;
|
||||||
use serde_json::{from_value as from_json_value, json};
|
use serde_json::{from_value as from_json_value, json};
|
||||||
|
|
||||||
use super::IncomingInvitationRecipient;
|
use super::IncomingInvitationRecipient;
|
||||||
@ -91,11 +91,11 @@ pub mod v3 {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_matches!(
|
let user_id = assert_matches!(
|
||||||
incoming,
|
incoming,
|
||||||
IncomingInvitationRecipient::UserId { user_id }
|
IncomingInvitationRecipient::UserId { user_id } => user_id
|
||||||
if user_id == user_id!("@carl:example.org")
|
|
||||||
);
|
);
|
||||||
|
assert_eq!(user_id, "@carl:example.org");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -108,10 +108,10 @@ pub mod v3 {
|
|||||||
}))
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let third_party_id = match incoming {
|
let third_party_id = assert_matches!(
|
||||||
IncomingInvitationRecipient::UserId { .. } => panic!("wrong variant"),
|
incoming,
|
||||||
IncomingInvitationRecipient::ThirdPartyId(id) => id,
|
IncomingInvitationRecipient::ThirdPartyId(id) => id
|
||||||
};
|
);
|
||||||
|
|
||||||
assert_eq!(third_party_id.id_server, "example.org");
|
assert_eq!(third_party_id.id_server, "example.org");
|
||||||
assert_eq!(third_party_id.id_access_token, "abcdefghijklmnop");
|
assert_eq!(third_party_id.id_access_token, "abcdefghijklmnop");
|
||||||
|
@ -80,36 +80,34 @@ pub mod v3 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use assert_matches::assert_matches;
|
use ruma_common::mxc_uri;
|
||||||
use serde_json::{from_value as from_json_value, json};
|
use serde_json::{from_value as from_json_value, json};
|
||||||
|
|
||||||
use super::RoomMember;
|
use super::RoomMember;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_room_member() {
|
fn deserialize_room_member() {
|
||||||
assert_matches!(
|
let member = from_json_value::<RoomMember>(json!({
|
||||||
from_json_value::<RoomMember>(json!({
|
"display_name": "alice",
|
||||||
"display_name": "alice",
|
"avatar_url": "mxc://localhost/wefuiwegh8742w",
|
||||||
"avatar_url": "mxc://localhost/wefuiwegh8742w",
|
}))
|
||||||
})).unwrap(),
|
.unwrap();
|
||||||
RoomMember {
|
assert_eq!(member.display_name.as_deref(), Some("alice"));
|
||||||
display_name: Some(display_name),
|
assert_eq!(
|
||||||
avatar_url: Some(avatar_url),
|
member.avatar_url.as_deref(),
|
||||||
} if display_name == "alice"
|
Some(mxc_uri!("mxc://localhost/wefuiwegh8742w"))
|
||||||
&& avatar_url == "mxc://localhost/wefuiwegh8742w"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "compat")]
|
#[cfg(feature = "compat")]
|
||||||
assert_matches!(
|
{
|
||||||
from_json_value::<RoomMember>(json!({
|
let member = from_json_value::<RoomMember>(json!({
|
||||||
"display_name": "alice",
|
"display_name": "alice",
|
||||||
"avatar_url": "",
|
"avatar_url": "",
|
||||||
})).unwrap(),
|
}))
|
||||||
RoomMember {
|
.unwrap();
|
||||||
display_name: Some(display_name),
|
assert_eq!(member.display_name.as_deref(), Some("alice"));
|
||||||
avatar_url: None,
|
assert_eq!(member.avatar_url, None);
|
||||||
} if display_name == "alice"
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,36 +84,38 @@ pub mod v3 {
|
|||||||
|
|
||||||
#[cfg(all(test, feature = "server"))]
|
#[cfg(all(test, feature = "server"))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
|
||||||
use ruma_common::api::IncomingRequest as _;
|
use ruma_common::api::IncomingRequest as _;
|
||||||
|
|
||||||
use super::IncomingRequest;
|
use super::IncomingRequest;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_unset_request() {
|
fn deserialize_unset_request() {
|
||||||
assert_matches!(
|
let req = IncomingRequest::try_from_http_request(
|
||||||
IncomingRequest::try_from_http_request(
|
http::Request::builder()
|
||||||
http::Request::builder()
|
.method("PUT")
|
||||||
.method("PUT")
|
.uri("https://bar.org/_matrix/client/r0/profile/@foo:bar.org/avatar_url")
|
||||||
.uri("https://bar.org/_matrix/client/r0/profile/@foo:bar.org/avatar_url")
|
.body(&[] as &[u8])
|
||||||
.body(&[] as &[u8]).unwrap(),
|
.unwrap(),
|
||||||
&["@foo:bar.org"],
|
&["@foo:bar.org"],
|
||||||
).unwrap(),
|
)
|
||||||
IncomingRequest { user_id, avatar_url: None, .. } if user_id == "@foo:bar.org"
|
.unwrap();
|
||||||
);
|
assert_eq!(req.user_id, "@foo:bar.org");
|
||||||
|
assert_eq!(req.avatar_url, None);
|
||||||
|
|
||||||
#[cfg(feature = "compat")]
|
#[cfg(feature = "compat")]
|
||||||
assert_matches!(
|
{
|
||||||
IncomingRequest::try_from_http_request(
|
let req = IncomingRequest::try_from_http_request(
|
||||||
http::Request::builder()
|
http::Request::builder()
|
||||||
.method("PUT")
|
.method("PUT")
|
||||||
.uri("https://bar.org/_matrix/client/r0/profile/@foo:bar.org/avatar_url")
|
.uri("https://bar.org/_matrix/client/r0/profile/@foo:bar.org/avatar_url")
|
||||||
.body(serde_json::to_vec(&serde_json::json!({ "avatar_url": "" })).unwrap())
|
.body(serde_json::to_vec(&serde_json::json!({ "avatar_url": "" })).unwrap())
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
&["@foo:bar.org"],
|
&["@foo:bar.org"],
|
||||||
).unwrap(),
|
)
|
||||||
IncomingRequest { user_id, avatar_url: None, .. } if user_id == "@foo:bar.org"
|
.unwrap();
|
||||||
);
|
assert_eq!(req.user_id, "@foo:bar.org");
|
||||||
|
assert_eq!(req.avatar_url, None);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,12 +286,14 @@ pub mod v3 {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
|
use ruma_common::mxc_uri;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{
|
||||||
|
from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue,
|
||||||
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
CustomLoginType, IdentityProvider, IdentityProviderBrand, LoginType, PasswordLoginType,
|
IdentityProvider, IdentityProviderBrand, LoginType, SsoLoginType, TokenLoginType,
|
||||||
SsoLoginType, TokenLoginType,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
@ -301,43 +303,40 @@ pub mod v3 {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_password_login_type() {
|
fn deserialize_password_login_type() {
|
||||||
assert_matches!(
|
let wrapper = from_json_value::<Wrapper>(json!({
|
||||||
from_json_value::<Wrapper>(json!({
|
"flows": [
|
||||||
"flows": [
|
{ "type": "m.login.password" }
|
||||||
{ "type": "m.login.password" }
|
],
|
||||||
],
|
}))
|
||||||
})),
|
.unwrap();
|
||||||
Ok(Wrapper { flows })
|
assert_eq!(wrapper.flows.len(), 1);
|
||||||
if flows.len() == 1
|
assert_matches!(wrapper.flows[0], LoginType::Password(_));
|
||||||
&& matches!(flows[0], LoginType::Password(PasswordLoginType {}))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_custom_login_type() {
|
fn deserialize_custom_login_type() {
|
||||||
assert_matches!(
|
let wrapper = from_json_value::<Wrapper>(json!({
|
||||||
from_json_value::<Wrapper>(json!({
|
"flows": [
|
||||||
"flows": [
|
{
|
||||||
{
|
"type": "io.ruma.custom",
|
||||||
"type": "io.ruma.custom",
|
"color": "green",
|
||||||
"color": "green",
|
}
|
||||||
}
|
],
|
||||||
],
|
}))
|
||||||
})),
|
.unwrap();
|
||||||
Ok(Wrapper { flows })
|
assert_eq!(wrapper.flows.len(), 1);
|
||||||
if flows.len() == 1
|
let custom = assert_matches!(
|
||||||
&& matches!(
|
&wrapper.flows[0],
|
||||||
&flows[0],
|
LoginType::_Custom(custom) => custom
|
||||||
LoginType::_Custom(CustomLoginType { type_, data })
|
|
||||||
if type_ == "io.ruma.custom"
|
|
||||||
&& data == json!({ "color": "green" }).as_object().unwrap()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
assert_eq!(custom.type_, "io.ruma.custom");
|
||||||
|
assert_eq!(custom.data.len(), 1);
|
||||||
|
assert_eq!(custom.data.get("color"), Some(&JsonValue::from("green")));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_sso_login_type() {
|
fn deserialize_sso_login_type() {
|
||||||
let mut wrapper = from_json_value::<Wrapper>(json!({
|
let wrapper = from_json_value::<Wrapper>(json!({
|
||||||
"flows": [
|
"flows": [
|
||||||
{
|
{
|
||||||
"type": "m.login.sso",
|
"type": "m.login.sso",
|
||||||
@ -357,39 +356,26 @@ pub mod v3 {
|
|||||||
],
|
],
|
||||||
}))
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
assert_eq!(wrapper.flows.len(), 1);
|
||||||
|
let flow = &wrapper.flows[0];
|
||||||
|
|
||||||
let flow = wrapper.flows.pop();
|
let identity_providers = assert_matches!(
|
||||||
assert_matches!(wrapper.flows.as_slice(), []);
|
flow,
|
||||||
|
LoginType::Sso(SsoLoginType { identity_providers }) => identity_providers
|
||||||
let mut identity_providers = match flow {
|
|
||||||
Some(LoginType::Sso(SsoLoginType { identity_providers })) => identity_providers,
|
|
||||||
_ => panic!("unexpected enum variant: {flow:?}"),
|
|
||||||
};
|
|
||||||
|
|
||||||
let provider = identity_providers.pop();
|
|
||||||
assert_matches!(
|
|
||||||
provider,
|
|
||||||
Some(IdentityProvider {
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
icon: None,
|
|
||||||
brand: None,
|
|
||||||
}) if id == "custom"
|
|
||||||
&& name == "Custom"
|
|
||||||
);
|
);
|
||||||
|
assert_eq!(identity_providers.len(), 2);
|
||||||
|
|
||||||
let provider = identity_providers.pop();
|
let provider = &identity_providers[0];
|
||||||
assert_matches!(
|
assert_eq!(provider.id, "oidc-gitlab");
|
||||||
provider,
|
assert_eq!(provider.name, "GitLab");
|
||||||
Some(IdentityProvider {
|
assert_eq!(provider.icon.as_deref(), Some(mxc_uri!("mxc://localhost/gitlab-icon")));
|
||||||
id,
|
assert_eq!(provider.brand, Some(IdentityProviderBrand::GitLab));
|
||||||
name,
|
|
||||||
icon: Some(icon),
|
let provider = &identity_providers[1];
|
||||||
brand: Some(IdentityProviderBrand::GitLab),
|
assert_eq!(provider.id, "custom");
|
||||||
}) if id == "oidc-gitlab"
|
assert_eq!(provider.name, "Custom");
|
||||||
&& name == "GitLab"
|
assert_eq!(provider.icon, None);
|
||||||
&& icon == "mxc://localhost/gitlab-icon"
|
assert_eq!(provider.brand, None);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -323,12 +323,12 @@ pub mod v3 {
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
use serde_json::{from_value as from_json_value, json};
|
use serde_json::{from_value as from_json_value, json};
|
||||||
|
|
||||||
use super::{IncomingLoginInfo, IncomingPassword, IncomingToken};
|
use super::{IncomingLoginInfo, IncomingToken};
|
||||||
use crate::uiaa::IncomingUserIdentifier;
|
use crate::uiaa::IncomingUserIdentifier;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_login_type() {
|
fn deserialize_login_type() {
|
||||||
assert_matches!(
|
let login = assert_matches!(
|
||||||
from_json_value(json!({
|
from_json_value(json!({
|
||||||
"type": "m.login.password",
|
"type": "m.login.password",
|
||||||
"identifier": {
|
"identifier": {
|
||||||
@ -338,19 +338,24 @@ pub mod v3 {
|
|||||||
"password": "ilovebananas"
|
"password": "ilovebananas"
|
||||||
}))
|
}))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
IncomingLoginInfo::Password(IncomingPassword { identifier: IncomingUserIdentifier::UserIdOrLocalpart(user), password })
|
IncomingLoginInfo::Password(login) => login
|
||||||
if user == "cheeky_monkey" && password == "ilovebananas"
|
|
||||||
);
|
);
|
||||||
|
let user = assert_matches!(
|
||||||
|
login.identifier,
|
||||||
|
IncomingUserIdentifier::UserIdOrLocalpart(user) => user
|
||||||
|
);
|
||||||
|
assert_eq!(user, "cheeky_monkey");
|
||||||
|
assert_eq!(login.password, "ilovebananas");
|
||||||
|
|
||||||
assert_matches!(
|
let token = assert_matches!(
|
||||||
from_json_value(json!({
|
from_json_value(json!({
|
||||||
"type": "m.login.token",
|
"type": "m.login.token",
|
||||||
"token": "1234567890abcdef"
|
"token": "1234567890abcdef"
|
||||||
}))
|
}))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
IncomingLoginInfo::Token(IncomingToken { token })
|
IncomingLoginInfo::Token(IncomingToken { token }) => token
|
||||||
if token == "1234567890abcdef"
|
|
||||||
);
|
);
|
||||||
|
assert_eq!(token, "1234567890abcdef");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -612,7 +612,6 @@ pub mod v3 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
|
||||||
use assign::assign;
|
use assign::assign;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
@ -624,14 +623,14 @@ pub mod v3 {
|
|||||||
let timeline_serialized = json!({ "limited": true });
|
let timeline_serialized = json!({ "limited": true });
|
||||||
assert_eq!(to_json_value(timeline).unwrap(), timeline_serialized);
|
assert_eq!(to_json_value(timeline).unwrap(), timeline_serialized);
|
||||||
|
|
||||||
let timeline_deserialized = from_json_value(timeline_serialized);
|
let timeline_deserialized = from_json_value::<Timeline>(timeline_serialized).unwrap();
|
||||||
assert_matches!(timeline_deserialized, Ok(Timeline { limited: true, .. }));
|
assert!(timeline_deserialized.limited);
|
||||||
|
|
||||||
let timeline_default = Timeline::default();
|
let timeline_default = Timeline::default();
|
||||||
assert_eq!(to_json_value(timeline_default).unwrap(), json!({}));
|
assert_eq!(to_json_value(timeline_default).unwrap(), json!({}));
|
||||||
|
|
||||||
let timeline_default_deserialized = from_json_value(json!({}));
|
let timeline_default_deserialized = from_json_value::<Timeline>(json!({})).unwrap();
|
||||||
assert_matches!(timeline_default_deserialized, Ok(Timeline { limited: false, .. }));
|
assert!(!timeline_default_deserialized.limited);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -702,8 +701,9 @@ pub mod v3 {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_matches!(req.filter, Some(IncomingFilter::FilterId(id)) if id == "myfilter");
|
let id = assert_matches!(req.filter, Some(IncomingFilter::FilterId(id)) => id);
|
||||||
assert_eq!(req.since, Some("myts".into()));
|
assert_eq!(id, "myfilter");
|
||||||
|
assert_eq!(req.since.as_deref(), Some("myts"));
|
||||||
assert!(!req.full_state);
|
assert!(!req.full_state);
|
||||||
assert_eq!(req.set_presence, PresenceState::Offline);
|
assert_eq!(req.set_presence, PresenceState::Offline);
|
||||||
assert_eq!(req.timeout, Some(Duration::from_millis(5000)));
|
assert_eq!(req.timeout, Some(Duration::from_millis(5000)));
|
||||||
@ -750,7 +750,8 @@ pub mod v3 {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_matches!(req.filter, Some(IncomingFilter::FilterId(id)) if id == "EOKFFmdZYF");
|
let id = assert_matches!(req.filter, Some(IncomingFilter::FilterId(id)) => id);
|
||||||
|
assert_eq!(id, "EOKFFmdZYF");
|
||||||
assert_eq!(req.since, None);
|
assert_eq!(req.since, None);
|
||||||
assert!(!req.full_state);
|
assert!(!req.full_state);
|
||||||
assert_eq!(req.set_presence, PresenceState::Online);
|
assert_eq!(req.set_presence, PresenceState::Online);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
use assign::assign;
|
use assign::assign;
|
||||||
use ruma_client_api::{
|
use ruma_client_api::{
|
||||||
error::{ErrorBody, ErrorKind},
|
error::ErrorKind,
|
||||||
uiaa::{
|
uiaa::{
|
||||||
self, AuthData, AuthFlow, AuthType, IncomingAuthData, IncomingUserIdentifier, UiaaInfo,
|
self, AuthData, AuthFlow, AuthType, IncomingAuthData, IncomingUserIdentifier, UiaaInfo,
|
||||||
UiaaResponse,
|
UiaaResponse,
|
||||||
@ -15,15 +15,15 @@ use serde_json::{
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_user_identifier() {
|
fn deserialize_user_identifier() {
|
||||||
assert_matches!(
|
let id = assert_matches!(
|
||||||
from_json_value(json!({
|
from_json_value(json!({
|
||||||
"type": "m.id.user",
|
"type": "m.id.user",
|
||||||
"user": "cheeky_monkey"
|
"user": "cheeky_monkey"
|
||||||
}))
|
}))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
IncomingUserIdentifier::UserIdOrLocalpart(id)
|
IncomingUserIdentifier::UserIdOrLocalpart(id) => id
|
||||||
if id == "cheeky_monkey"
|
|
||||||
);
|
);
|
||||||
|
assert_eq!(id, "cheeky_monkey");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -32,9 +32,9 @@ fn serialize_auth_data_registration_token() {
|
|||||||
assign!(uiaa::RegistrationToken::new("mytoken"), { session: Some("session") }),
|
assign!(uiaa::RegistrationToken::new("mytoken"), { session: Some("session") }),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_matches!(
|
assert_eq!(
|
||||||
to_json_value(auth_data),
|
to_json_value(auth_data).unwrap(),
|
||||||
Ok(val) if val == json!({
|
json!({
|
||||||
"type": "m.login.registration_token",
|
"type": "m.login.registration_token",
|
||||||
"token": "mytoken",
|
"token": "mytoken",
|
||||||
"session": "session",
|
"session": "session",
|
||||||
@ -50,13 +50,12 @@ fn deserialize_auth_data_registration_token() {
|
|||||||
"session": "session",
|
"session": "session",
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
let data = assert_matches!(
|
||||||
from_json_value(json),
|
from_json_value(json),
|
||||||
Ok(IncomingAuthData::RegistrationToken(
|
Ok(IncomingAuthData::RegistrationToken(data)) => data
|
||||||
uiaa::IncomingRegistrationToken { token, session: Some(session), .. },
|
|
||||||
))
|
|
||||||
if token == "mytoken" && session == "session"
|
|
||||||
);
|
);
|
||||||
|
assert_eq!(data.token, "mytoken");
|
||||||
|
assert_eq!(data.session.as_deref(), Some("session"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -70,13 +69,11 @@ fn serialize_auth_data_fallback() {
|
|||||||
fn deserialize_auth_data_fallback() {
|
fn deserialize_auth_data_fallback() {
|
||||||
let json = json!({ "session": "opaque_session_id" });
|
let json = json!({ "session": "opaque_session_id" });
|
||||||
|
|
||||||
assert_matches!(
|
let data = assert_matches!(
|
||||||
from_json_value(json).unwrap(),
|
from_json_value(json).unwrap(),
|
||||||
IncomingAuthData::FallbackAcknowledgement(
|
IncomingAuthData::FallbackAcknowledgement(data) => data
|
||||||
uiaa::IncomingFallbackAcknowledgement { session, .. },
|
|
||||||
)
|
|
||||||
if session == "opaque_session_id"
|
|
||||||
);
|
);
|
||||||
|
assert_eq!(data.session, "opaque_session_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -126,32 +123,22 @@ fn deserialize_uiaa_info() {
|
|||||||
"session": "xxxxxx"
|
"session": "xxxxxx"
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
let info = from_json_value::<UiaaInfo>(json).unwrap();
|
||||||
from_json_value::<UiaaInfo>(json).unwrap(),
|
assert_eq!(info.completed, vec![AuthType::ReCaptcha]);
|
||||||
UiaaInfo {
|
assert_eq!(info.flows.len(), 2);
|
||||||
auth_error: Some(ErrorBody {
|
assert_eq!(info.flows[0].stages, vec![AuthType::Password]);
|
||||||
kind: ErrorKind::Forbidden,
|
assert_eq!(info.flows[1].stages, vec![AuthType::EmailIdentity, AuthType::Msisdn]);
|
||||||
message: error_message,
|
assert_eq!(info.session.as_deref(), Some("xxxxxx"));
|
||||||
}),
|
let auth_error = info.auth_error.unwrap();
|
||||||
completed,
|
assert_eq!(auth_error.kind, ErrorKind::Forbidden);
|
||||||
flows,
|
assert_eq!(auth_error.message, "Invalid password");
|
||||||
params,
|
assert_eq!(
|
||||||
session: Some(session),
|
from_json_str::<JsonValue>(info.params.get()).unwrap(),
|
||||||
..
|
json!({
|
||||||
} if error_message == "Invalid password"
|
"example.type.baz": {
|
||||||
&& completed == vec![AuthType::ReCaptcha]
|
"example_key": "foobar"
|
||||||
&& matches!(
|
}
|
||||||
flows.as_slice(),
|
})
|
||||||
[f1, f2]
|
|
||||||
if f1.stages == vec![AuthType::Password]
|
|
||||||
&& f2.stages == vec![AuthType::EmailIdentity, AuthType::Msisdn]
|
|
||||||
)
|
|
||||||
&& from_json_str::<JsonValue>(params.get()).unwrap() == json!({
|
|
||||||
"example.type.baz": {
|
|
||||||
"example_key": "foobar"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
&& session == "xxxxxx"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,24 +157,19 @@ fn try_uiaa_response_into_http_response() {
|
|||||||
let uiaa_response =
|
let uiaa_response =
|
||||||
UiaaResponse::AuthResponse(uiaa_info).try_into_http_response::<Vec<u8>>().unwrap();
|
UiaaResponse::AuthResponse(uiaa_info).try_into_http_response::<Vec<u8>>().unwrap();
|
||||||
|
|
||||||
assert_matches!(
|
let info = from_json_slice::<UiaaInfo>(uiaa_response.body()).unwrap();
|
||||||
from_json_slice::<UiaaInfo>(uiaa_response.body()).unwrap(),
|
assert_eq!(info.flows.len(), 1);
|
||||||
UiaaInfo {
|
assert_eq!(info.flows[0].stages, vec![AuthType::Password, AuthType::Dummy]);
|
||||||
flows,
|
assert_eq!(info.completed, vec![AuthType::ReCaptcha]);
|
||||||
completed,
|
assert_eq!(info.session, None);
|
||||||
params,
|
assert_matches!(info.auth_error, None);
|
||||||
session: None,
|
assert_eq!(
|
||||||
auth_error: None,
|
from_json_str::<JsonValue>(info.params.get()).unwrap(),
|
||||||
..
|
json!({
|
||||||
} if matches!(
|
"example.type.baz": {
|
||||||
flows.as_slice(),
|
"example_key": "foobar"
|
||||||
[flow] if flow.stages == vec![AuthType::Password, AuthType::Dummy]
|
}
|
||||||
) && completed == vec![AuthType::ReCaptcha]
|
})
|
||||||
&& from_json_str::<JsonValue>(params.get()).unwrap() == json!({
|
|
||||||
"example.type.baz": {
|
|
||||||
"example_key": "foobar"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
assert_eq!(uiaa_response.status(), http::status::StatusCode::UNAUTHORIZED);
|
assert_eq!(uiaa_response.status(), http::status::StatusCode::UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
@ -220,36 +202,24 @@ fn try_uiaa_response_from_http_response() {
|
|||||||
.body(json.as_bytes())
|
.body(json.as_bytes())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let parsed_uiaa_info = match UiaaResponse::try_from_http_response(http_response).unwrap() {
|
let info = assert_matches!(
|
||||||
UiaaResponse::AuthResponse(uiaa_info) => uiaa_info,
|
UiaaResponse::try_from_http_response(http_response),
|
||||||
_ => panic!("Expected UiaaResponse::AuthResponse"),
|
Ok(UiaaResponse::AuthResponse(info)) => info
|
||||||
};
|
);
|
||||||
|
assert_eq!(info.completed, vec![AuthType::ReCaptcha]);
|
||||||
assert_matches!(
|
assert_eq!(info.flows.len(), 2);
|
||||||
parsed_uiaa_info,
|
assert_eq!(info.flows[0].stages, vec![AuthType::Password]);
|
||||||
UiaaInfo {
|
assert_eq!(info.flows[1].stages, vec![AuthType::EmailIdentity, AuthType::Msisdn]);
|
||||||
auth_error: Some(ErrorBody {
|
assert_eq!(info.session.as_deref(), Some("xxxxxx"));
|
||||||
kind: ErrorKind::Forbidden,
|
let auth_error = info.auth_error.unwrap();
|
||||||
message: error_message,
|
assert_eq!(auth_error.kind, ErrorKind::Forbidden);
|
||||||
}),
|
assert_eq!(auth_error.message, "Invalid password");
|
||||||
completed,
|
assert_eq!(
|
||||||
flows,
|
from_json_str::<JsonValue>(info.params.get()).unwrap(),
|
||||||
params,
|
json!({
|
||||||
session: Some(session),
|
"example.type.baz": {
|
||||||
..
|
"example_key": "foobar"
|
||||||
} if error_message == "Invalid password"
|
}
|
||||||
&& completed == vec![AuthType::ReCaptcha]
|
})
|
||||||
&& matches!(
|
|
||||||
flows.as_slice(),
|
|
||||||
[f1, f2]
|
|
||||||
if f1.stages == vec![AuthType::Password]
|
|
||||||
&& f2.stages == vec![AuthType::EmailIdentity, AuthType::Msisdn]
|
|
||||||
)
|
|
||||||
&& from_json_str::<JsonValue>(params.get()).unwrap() == json!({
|
|
||||||
"example.type.baz": {
|
|
||||||
"example_key": "foobar"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
&& session == "xxxxxx"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user