async_client: add login failure test, make sure we are getting correct error

master
Devin R 2020-04-16 17:03:40 -04:00
parent 07b7cbfe4e
commit bd3b0e7b74
1 changed files with 42 additions and 0 deletions

View File

@ -1105,7 +1105,9 @@ mod test {
use crate::test_builder::EventBuilder; use crate::test_builder::EventBuilder;
use mockito::mock;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::str::FromStr;
#[tokio::test] #[tokio::test]
async fn client_runner() { async fn client_runner() {
@ -1167,4 +1169,44 @@ mod test {
&Url::parse(&mockito::server_url()).unwrap() &Url::parse(&mockito::server_url()).unwrap()
); );
} }
#[tokio::test]
async fn login_error() {
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
let _m = mock("POST", "/_matrix/client/r0/login")
.with_status(403)
.with_body_from_file("tests/data/login_response_error.json")
.create();
let client = AsyncClient::new(homeserver, None).unwrap();
if let Err(err) = client.login("example", "wordpass", None, None).await {
if let crate::Error::RumaResponse(ruma_api::error::FromHttpResponseError::Http(
ruma_api::error::ServerError::Known(ruma_client_api::error::Error {
kind,
message,
status_code,
}),
)) = err
{
if let ruma_client_api::error::ErrorKind::Forbidden = kind {
} else {
panic!(
"found the wrong `ErrorKind` {:?}, expected `Forbidden",
kind
);
}
assert_eq!(message, "Invalid password".to_string());
assert_eq!(status_code, http::StatusCode::from_u16(403).unwrap());
} else {
panic!(
"found the wrong `Error` type {:?}, expected `Error::RumaResponse",
err
);
}
} else {
panic!("this request should return an `Err` variant")
}
}
} }