mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 05:30:33 -04:00
fix(appservice): urldecode ids for user/room queries
This commit is contained in:
@@ -27,6 +27,7 @@ docs = ["warp"]
|
||||
dashmap = "5.1.0"
|
||||
http = "0.2"
|
||||
matrix-sdk = { version = "0.4", path = "../matrix-sdk", default-features = false, features = ["appservice"] }
|
||||
percent-encoding = "2.1.0"
|
||||
regex = "1"
|
||||
ruma = { version = "0.5.0", features = ["client-api-c", "appservice-api-s"] }
|
||||
serde = "1"
|
||||
|
||||
@@ -74,6 +74,9 @@ pub enum Error {
|
||||
#[error(transparent)]
|
||||
SerdeJson(#[from] serde_json::Error),
|
||||
|
||||
#[error(transparent)]
|
||||
Utf8Error(#[from] std::str::Utf8Error),
|
||||
|
||||
#[cfg(feature = "warp")]
|
||||
#[error("warp rejection: {0}")]
|
||||
WarpRejection(String),
|
||||
|
||||
@@ -162,6 +162,8 @@ mod filters {
|
||||
}
|
||||
|
||||
mod handlers {
|
||||
use percent_encoding::percent_decode_str;
|
||||
|
||||
use super::*;
|
||||
|
||||
pub async fn user(
|
||||
@@ -170,6 +172,7 @@ mod handlers {
|
||||
request: http::Request<Bytes>,
|
||||
) -> Result<impl Reply, Rejection> {
|
||||
if let Some(user_exists) = appservice.event_handler.users.lock().await.as_mut() {
|
||||
let user_id = percent_decode_str(&user_id).decode_utf8().map_err(Error::from)?;
|
||||
let request = query_user::IncomingRequest::try_from_http_request(request, &[user_id])
|
||||
.map_err(Error::from)?;
|
||||
return if user_exists(appservice.clone(), request).await {
|
||||
@@ -187,6 +190,7 @@ mod handlers {
|
||||
request: http::Request<Bytes>,
|
||||
) -> Result<impl Reply, Rejection> {
|
||||
if let Some(room_exists) = appservice.event_handler.rooms.lock().await.as_mut() {
|
||||
let room_id = percent_decode_str(&room_id).decode_utf8().map_err(Error::from)?;
|
||||
let request = query_room::IncomingRequest::try_from_http_request(request, &[room_id])
|
||||
.map_err(Error::from)?;
|
||||
return if room_exists(appservice.clone(), request).await {
|
||||
|
||||
@@ -99,6 +99,7 @@ async fn test_put_transaction() -> Result<()> {
|
||||
#[async_test]
|
||||
async fn test_get_user() -> Result<()> {
|
||||
let appservice = appservice(None).await?;
|
||||
appservice.register_user_query(Box::new(|_, _| Box::pin(async move { true }))).await;
|
||||
|
||||
let uri = "/_matrix/app/v1/users/%40_botty_1%3Adev.famedly.local?access_token=hs_token";
|
||||
|
||||
@@ -120,6 +121,7 @@ async fn test_get_user() -> Result<()> {
|
||||
#[async_test]
|
||||
async fn test_get_room() -> Result<()> {
|
||||
let appservice = appservice(None).await?;
|
||||
appservice.register_room_query(Box::new(|_, _| Box::pin(async move { true }))).await;
|
||||
|
||||
let uri = "/_matrix/app/v1/rooms/%23magicforest%3Aexample.com?access_token=hs_token";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user