This commit is contained in:
Felix Ableitner 2023-12-12 11:17:00 +01:00
parent b479e9ac95
commit 7509ed6425
2 changed files with 7 additions and 7 deletions

View file

@ -122,17 +122,15 @@ mod test {
let incoming_request = construct_request(&body, &actor).await; let incoming_request = construct_request(&body, &actor).await;
// intentionally cause a parse error by using wrong type for deser // intentionally cause a parse error by using wrong type for deser
let err = receive_activity::<Follow, DbUser, DbConnection>( let res = receive_activity::<Follow, DbUser, DbConnection>(
incoming_request.to_http_request(), incoming_request.to_http_request(),
body, body,
&config.to_request_data(), &config.to_request_data(),
) )
.await .await;
.err()
.unwrap();
match err { match res {
Error::ParseReceivedActivity(url, _) => { Err(Error::ParseReceivedActivity(url, _)) => {
assert_eq!(id, url.as_str()); assert_eq!(id, url.as_str());
} }
_ => unreachable!(), _ => unreachable!(),

View file

@ -37,6 +37,8 @@ use url::Url;
/// Mime type for Activitypub data, used for `Accept` and `Content-Type` HTTP headers /// Mime type for Activitypub data, used for `Accept` and `Content-Type` HTTP headers
pub static FEDERATION_CONTENT_TYPE: &str = "application/activity+json"; pub static FEDERATION_CONTENT_TYPE: &str = "application/activity+json";
/// Deserialize incoming inbox activity to the given type, perform basic
/// validation and extract the actor.
async fn parse_received_activity<Activity, ActorT, Datatype>( async fn parse_received_activity<Activity, ActorT, Datatype>(
body: &[u8], body: &[u8],
data: &Data<Datatype>, data: &Data<Datatype>,
@ -50,7 +52,7 @@ where
Datatype: Clone, Datatype: Clone,
{ {
let activity: Activity = serde_json::from_slice(body).map_err(|e| { let activity: Activity = serde_json::from_slice(body).map_err(|e| {
// Attempt to parse only activity id for error message // Attempt to include activity id in error message
#[derive(Deserialize)] #[derive(Deserialize)]
struct Id { struct Id {
id: Url, id: Url,