From cbd02f2a8794eb7c3bb3b8a53bdc34fd3fef2586 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 16 Dec 2020 16:30:44 +0100 Subject: [PATCH 1/5] Use correct content-type headers for apub inbox (ref #1220) --- lemmy_apub/src/activity_queue.rs | 3 ++- src/routes/federation.rs | 26 ++++++++++++-------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lemmy_apub/src/activity_queue.rs b/lemmy_apub/src/activity_queue.rs index 467802794..4915baea7 100644 --- a/lemmy_apub/src/activity_queue.rs +++ b/lemmy_apub/src/activity_queue.rs @@ -3,6 +3,7 @@ use crate::{ extensions::signatures::sign_and_send, insert_activity, ActorType, + APUB_JSON_CONTENT_TYPE, }; use activitystreams::{ base::{BaseExt, Extends, ExtendsExt}, @@ -261,7 +262,7 @@ impl ActixJob for SendActivityTask { fn run(self, state: Self::State) -> Self::Future { Box::pin(async move { let mut headers = BTreeMap::::new(); - headers.insert("Content-Type".into(), "application/json".into()); + headers.insert("Content-Type".into(), APUB_JSON_CONTENT_TYPE.to_string()); let result = sign_and_send( &state.client, headers, diff --git a/src/routes/federation.rs b/src/routes/federation.rs index 4d03de770..7ee7e45e4 100644 --- a/src/routes/federation.rs +++ b/src/routes/federation.rs @@ -22,13 +22,18 @@ pub fn config(cfg: &mut web::ServiceConfig) { println!("federation enabled, host is {}", Settings::get().hostname); let digest_verifier = VerifyDigest::new(Sha256::new()); - let header_guard = guard::Any(guard::Header("Accept", APUB_JSON_CONTENT_TYPE)) + let header_guard_accept = guard::Any(guard::Header("Accept", APUB_JSON_CONTENT_TYPE)) .or(guard::Header("Accept", APUB_JSON_CONTENT_TYPE_LONG)); + let header_guard_content_type = + guard::Any(guard::Header("Content-Type", APUB_JSON_CONTENT_TYPE)) + .or(guard::Header("Content-Type", APUB_JSON_CONTENT_TYPE_LONG)) + // TODO: compatibility with previous lemmy versions, remove this later + .or(guard::Header("Content-Type", "application/json")); cfg .service( web::scope("/") - .guard(header_guard) + .guard(header_guard_accept) .route( "/c/{community_name}", web::get().to(get_apub_community_http), @@ -49,19 +54,12 @@ pub fn config(cfg: &mut web::ServiceConfig) { ) // Inboxes dont work with the header guard for some reason. .service( - web::resource("/c/{community_name}/inbox") - .wrap(digest_verifier.clone()) - .route(web::post().to(community_inbox)), - ) - .service( - web::resource("/u/{user_name}/inbox") - .wrap(digest_verifier.clone()) - .route(web::post().to(user_inbox)), - ) - .service( - web::resource("/inbox") + web::scope("/") .wrap(digest_verifier) - .route(web::post().to(shared_inbox)), + .guard(header_guard_content_type) + .route("/c/{community_name}/inbox", web::post().to(community_inbox)) + .route("/u/{user_name}/inbox", web::post().to(user_inbox)) + .route("/inbox", web::post().to(shared_inbox)), ); } } From 4bf0ec94c8c0b87375aea5f147b48139361bc481 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 16 Dec 2020 21:07:48 +0100 Subject: [PATCH 2/5] Create empty inbox collections for actors (ref #1322) --- docker/prod/deploy-federation-test.sh | 14 ++++++++++++++ lemmy_apub/src/http/community.rs | 16 ++++++++++++++++ lemmy_apub/src/http/user.rs | 16 ++++++++++++++++ src/routes/federation.rs | 14 ++++++++++++-- 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100755 docker/prod/deploy-federation-test.sh diff --git a/docker/prod/deploy-federation-test.sh b/docker/prod/deploy-federation-test.sh new file mode 100755 index 000000000..e9d9aef89 --- /dev/null +++ b/docker/prod/deploy-federation-test.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -e + +TAG="federation-test" + +sudo docker build ../../ --file Dockerfile -t "dessalines/lemmy:$TAG" +sudo docker save "dessalines/lemmy:$TAG" -o "$TAG.tar" +sudo chown "$(id -u):$(id -g)" "$TAG.tar" + +scp "$TAG.tar" enterprise.lemmy.ml: +rm "$TAG.tar" +ssh lemmy-test "cat $TAG.tar | docker load" +ssh lemmy-test "rm $TAG.tar" +ssh lemmy-test "cd /lemmy/enterprise.lemmy.ml && docker-compose up -d" \ No newline at end of file diff --git a/lemmy_apub/src/http/community.rs b/lemmy_apub/src/http/community.rs index 0a90571ff..eb23a7edd 100644 --- a/lemmy_apub/src/http/community.rs +++ b/lemmy_apub/src/http/community.rs @@ -94,3 +94,19 @@ pub async fn get_apub_community_outbox( .set_total_items(len as u64); Ok(create_apub_response(&collection)) } + +pub async fn get_apub_community_inbox( + info: web::Path, + context: web::Data, +) -> Result, LemmyError> { + let community = blocking(context.pool(), move |conn| { + Community::read_from_name(&conn, &info.community_name) + }) + .await??; + + let mut collection = OrderedCollection::new(); + collection + .set_id(format!("{}/inbox", community.actor_id).parse()?) + .set_many_contexts(lemmy_context()?); + Ok(create_apub_response(&collection)) +} diff --git a/lemmy_apub/src/http/user.rs b/lemmy_apub/src/http/user.rs index 1e546d953..5acdd28d3 100644 --- a/lemmy_apub/src/http/user.rs +++ b/lemmy_apub/src/http/user.rs @@ -52,3 +52,19 @@ pub async fn get_apub_user_outbox( .set_total_items(0_u64); Ok(create_apub_response(&collection)) } + +pub async fn get_apub_user_inbox( + info: web::Path, + context: web::Data, +) -> Result, LemmyError> { + let user = blocking(context.pool(), move |conn| { + User_::read_from_name(&conn, &info.user_name) + }) + .await??; + + let mut collection = OrderedCollection::new(); + collection + .set_id(format!("{}/inbox", user.actor_id).parse()?) + .set_many_contexts(lemmy_context()?); + Ok(create_apub_response(&collection)) +} diff --git a/src/routes/federation.rs b/src/routes/federation.rs index 4d03de770..2cad8bc08 100644 --- a/src/routes/federation.rs +++ b/src/routes/federation.rs @@ -3,10 +3,15 @@ use http_signature_normalization_actix::digest::middleware::VerifyDigest; use lemmy_apub::{ http::{ comment::get_apub_comment, - community::{get_apub_community_followers, get_apub_community_http, get_apub_community_outbox}, + community::{ + get_apub_community_followers, + get_apub_community_http, + get_apub_community_inbox, + get_apub_community_outbox, + }, get_activity, post::get_apub_post, - user::{get_apub_user_http, get_apub_user_outbox}, + user::{get_apub_user_http, get_apub_user_inbox, get_apub_user_outbox}, }, inbox::{community_inbox::community_inbox, shared_inbox::shared_inbox, user_inbox::user_inbox}, APUB_JSON_CONTENT_TYPE, @@ -41,8 +46,13 @@ pub fn config(cfg: &mut web::ServiceConfig) { "/c/{community_name}/outbox", web::get().to(get_apub_community_outbox), ) + .route( + "/c/{community_name}/inbox", + web::get().to(get_apub_community_inbox), + ) .route("/u/{user_name}", web::get().to(get_apub_user_http)) .route("/u/{user_name}/outbox", web::get().to(get_apub_user_outbox)) + .route("/u/{user_name}/inbox", web::get().to(get_apub_user_inbox)) .route("/post/{post_id}", web::get().to(get_apub_post)) .route("/comment/{comment_id}", web::get().to(get_apub_comment)) .route("/activities/{type_}/{id}", web::get().to(get_activity)), From dd069de519fb53047a7b0a194ff051000e07bb5b Mon Sep 17 00:00:00 2001 From: "D.Loh" Date: Mon, 4 Jan 2021 07:26:43 -0800 Subject: [PATCH 3/5] add User_ missing field 'deleted' in tests (#1338) per rust-analyzer tips --- lemmy_db/src/user.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/lemmy_db/src/user.rs b/lemmy_db/src/user.rs index d8e833e6e..1ec94f376 100644 --- a/lemmy_db/src/user.rs +++ b/lemmy_db/src/user.rs @@ -274,6 +274,7 @@ mod tests { private_key: None, public_key: None, last_refreshed_at: inserted_user.published, + deleted: false, }; let read_user = User_::read(&conn, inserted_user.id).unwrap(); From 632d8f384abfa3040c3844b30b6de346429683f2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Jan 2021 11:29:04 -0500 Subject: [PATCH 4/5] Bump node-notifier from 8.0.0 to 8.0.1 in /api_tests (#1332) Bumps [node-notifier](https://github.com/mikaelbr/node-notifier) from 8.0.0 to 8.0.1. - [Release notes](https://github.com/mikaelbr/node-notifier/releases) - [Changelog](https://github.com/mikaelbr/node-notifier/blob/v8.0.1/CHANGELOG.md) - [Commits](https://github.com/mikaelbr/node-notifier/compare/v8.0.0...v8.0.1) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- api_tests/yarn.lock | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/api_tests/yarn.lock b/api_tests/yarn.lock index e1ee01ac3..be9a578f1 100644 --- a/api_tests/yarn.lock +++ b/api_tests/yarn.lock @@ -2405,6 +2405,13 @@ lodash@^4.17.19: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== +lru-cache@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" + integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA== + dependencies: + yallist "^4.0.0" + make-dir@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f" @@ -2563,9 +2570,9 @@ node-modules-regexp@^1.0.0: integrity sha1-jZ2+KJZKSsVxLpExZCEHxx6Q7EA= node-notifier@^8.0.0: - version "8.0.0" - resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-8.0.0.tgz#a7eee2d51da6d0f7ff5094bc7108c911240c1620" - integrity sha512-46z7DUmcjoYdaWyXouuFNNfUo6eFa94t23c53c+lG/9Cvauk4a98rAUp9672X5dxGdQmLpPzTxzu8f/OeEPaFA== + version "8.0.1" + resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-8.0.1.tgz#f86e89bbc925f2b068784b31f382afdc6ca56be1" + integrity sha512-BvEXF+UmsnAfYfoapKM9nGxnP+Wn7P91YfXmrKnfcYCx6VBeoN5Ez5Ogck6I8Bi5k4RlpqRYaw75pAwzX9OphA== dependencies: growly "^1.3.0" is-wsl "^2.2.0" @@ -3018,9 +3025,11 @@ saxes@^5.0.0: integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== semver@7.x, semver@^7.3.2: - version "7.3.2" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938" - integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ== + version "7.3.4" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.4.tgz#27aaa7d2e4ca76452f98d3add093a72c943edc97" + integrity sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw== + dependencies: + lru-cache "^6.0.0" semver@^6.0.0, semver@^6.3.0: version "6.3.0" @@ -3491,9 +3500,9 @@ uuid@^3.3.2: integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== uuid@^8.3.0: - version "8.3.0" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.0.tgz#ab738085ca22dc9a8c92725e459b1d507df5d6ea" - integrity sha512-fX6Z5o4m6XsXBdli9g7DtWgAx+osMsRRZFKma1mIUsLCz6vRvv+pz5VNbyu9UEDzpMWulZfvpgb/cmDXVulYFQ== + version "8.3.2" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" + integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== v8-to-istanbul@^5.0.1: version "5.0.1" @@ -3641,6 +3650,11 @@ y18n@^4.0.0: resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b" integrity sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w== +yallist@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" + integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== + yargs-parser@20.x: version "20.2.0" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.0.tgz#944791ca2be2e08ddadd3d87e9de4c6484338605" From d300968ee8a71f189208d78c97b0d88f4c1b3858 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 4 Jan 2021 19:53:15 +0100 Subject: [PATCH 5/5] Return http status code 410 with apub tombstone (ref #1256) --- lemmy_apub/src/http/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lemmy_apub/src/http/mod.rs b/lemmy_apub/src/http/mod.rs index 4f31f6a5e..44835bf89 100644 --- a/lemmy_apub/src/http/mod.rs +++ b/lemmy_apub/src/http/mod.rs @@ -5,6 +5,7 @@ use lemmy_structs::blocking; use lemmy_utils::{settings::Settings, LemmyError}; use lemmy_websocket::LemmyContext; use serde::{Deserialize, Serialize}; +use http::StatusCode; pub mod comment; pub mod community; @@ -28,6 +29,7 @@ where { HttpResponse::Gone() .content_type(APUB_JSON_CONTENT_TYPE) + .status(StatusCode::GONE) .json(data) }