mirror of
https://github.com/LemmyNet/activitypub-federation-rust.git
synced 2024-05-23 11:28:05 +00:00
comments
This commit is contained in:
parent
b479e9ac95
commit
7509ed6425
|
@ -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!(),
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue