From 4f7c20fc268754a9f960d880332759534331a622 Mon Sep 17 00:00:00 2001 From: fdb-hiroshima <35889323+fdb-hiroshima@users.noreply.github.com> Date: Wed, 31 Jul 2019 11:38:49 +0200 Subject: [PATCH] Fix some federation issue (#573) * send scheme as part of webfinger remote follow template fix tsileo/microblog.pub#49 * bump webfinger to 0.4.1 * cargo fmt * revert translations * Use group: prefix for blog webfinger queries --- Cargo.lock | 9 ++++----- Cargo.toml | 2 +- plume-models/Cargo.toml | 2 +- plume-models/src/blogs.rs | 2 +- plume-models/src/users.rs | 2 +- src/routes/well_known.rs | 22 +++++++++++----------- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f7a29c3..0e405dc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1911,7 +1911,7 @@ dependencies = [ "shrinkwraprs 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "validator 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "validator_derive 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "webfinger 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "webfinger 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2009,7 +2009,7 @@ dependencies = [ "shrinkwraprs 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "tantivy 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "webfinger 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "webfinger 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "whatlang 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3413,13 +3413,12 @@ dependencies = [ [[package]] name = "webfinger" -version = "0.3.1" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "reqwest 0.9.17 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3871,7 +3870,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" "checksum want 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "797464475f30ddb8830cc529aaaae648d581f99e2036a928877dfde027ddf6b3" -"checksum webfinger 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edc8f298f29f04bf5b6a85d7d448de4f16b7d45807d0a3ec422efcfbf1960519" +"checksum webfinger 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ec24b1b0700d4b466d280228ed0f62274eedeaa80206820f071fdc8ed787b664" "checksum whatlang 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bf61042986b0f0612917b71609b861d695e76c55f9fc81b8a8f8cd363646816c" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" diff --git a/Cargo.toml b/Cargo.toml index 05f9d3ec..8a716347 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ serde_qs = "0.4" shrinkwraprs = "0.2.1" validator = "0.8" validator_derive = "0.8" -webfinger = "0.3.1" +webfinger = "0.4.1" [[bin]] name = "plume" diff --git a/plume-models/Cargo.toml b/plume-models/Cargo.toml index 1fbb50be..a5155f6f 100644 --- a/plume-models/Cargo.toml +++ b/plume-models/Cargo.toml @@ -23,7 +23,7 @@ serde_derive = "1.0" serde_json = "1.0" tantivy = "0.9.1" url = "1.7" -webfinger = "0.3.1" +webfinger = "0.4.1" whatlang = "0.7.1" shrinkwraprs = "0.2.1" diesel-derive-newtype = "0.1.2" diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index c107954f..8c55f402 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -145,7 +145,7 @@ impl Blog { } fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result { - resolve(acct.to_owned(), true)? + resolve_with_prefix(Prefix::Group, acct.to_owned(), true)? .links .into_iter() .find(|l| l.mime_type == Some(String::from("application/activity+json"))) diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index 2c07353d..4b1d3a54 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -707,7 +707,7 @@ impl User { mime_type: None, href: None, template: Some(format!( - "{}/remote_interact?{{uri}}", + "https://{}/remote_interact?{{uri}}", self.get_instance(conn)?.public_domain )), }, diff --git a/src/routes/well_known.rs b/src/routes/well_known.rs index 56fffa99..723ec1e0 100644 --- a/src/routes/well_known.rs +++ b/src/routes/well_known.rs @@ -48,14 +48,16 @@ impl Resolver for WebfingerResolver { CONFIG.base_url.as_str() } - fn find(acct: String, ctx: PlumeRocket) -> Result { - User::find_by_fqn(&ctx, &acct) - .and_then(|usr| usr.webfinger(&*ctx.conn)) - .or_else(|_| { - Blog::find_by_fqn(&ctx, &acct) - .and_then(|blog| blog.webfinger(&*ctx.conn)) - .or(Err(ResolverError::NotFound)) - }) + fn find(prefix: Prefix, acct: String, ctx: PlumeRocket) -> Result { + match prefix { + Prefix::Acct => User::find_by_fqn(&ctx, &acct) + .and_then(|usr| usr.webfinger(&*ctx.conn)) + .or(Err(ResolverError::NotFound)), + Prefix::Group => Blog::find_by_fqn(&ctx, &acct) + .and_then(|blog| blog.webfinger(&*ctx.conn)) + .or(Err(ResolverError::NotFound)), + Prefix::Custom(_) => Err(ResolverError::NotFound), + } } } @@ -72,9 +74,7 @@ pub fn webfinger(resource: String, rockets: PlumeRocket) -> Content { "Invalid resource. Make sure to request an acct: URI" } ResolverError::NotFound => "Requested resource was not found", - ResolverError::WrongInstance => { - "This is not the instance of the requested resource" - } + ResolverError::WrongDomain => "This is not the instance of the requested resource", }), ), }