From cce5a9cb1ce0555277d11004bcedc9e7460f4ed8 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 05:43:13 +0000 Subject: [PATCH 1/5] webfinger: expose the application/ld+json link alongside the older application/activity+json link --- lib/pleroma/web/web_finger/web_finger.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 6ffa80a43..241dfb4c8 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -86,6 +86,7 @@ defmodule Pleroma.Web.WebFinger do "href" => "data:application/magic-public-key,#{magic_key}" }, %{"rel" => "self", "type" => "application/activity+json", "href" => user.ap_id}, + %{"rel" => "self", "type" => "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", "href" => user.ap_id}, %{ "rel" => "http://ostatus.org/schema/1.0/subscribe", "template" => OStatus.remote_follow_path() @@ -117,6 +118,7 @@ defmodule Pleroma.Web.WebFinger do {:Link, %{rel: "magic-public-key", href: "data:application/magic-public-key,#{magic_key}"}}, {:Link, %{rel: "self", type: "application/activity+json", href: user.ap_id}}, + {:Link, %{rel: "self", type: "application/ld+json; profile="https://www.w3.org/ns/activitystreams"", href: user.ap_id}}, {:Link, %{rel: "http://ostatus.org/schema/1.0/subscribe", template: OStatus.remote_follow_path()}} ] From d1f6ecf607954e725e72b8e91be5f969eebe997f Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 05:46:13 +0000 Subject: [PATCH 2/5] webfinger: interpret application/ld+json links as an alternate to application/activity+json --- lib/pleroma/web/web_finger/web_finger.ex | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 241dfb4c8..b955bc43f 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -166,6 +166,14 @@ defmodule Pleroma.Web.WebFinger do doc ) + if ap_id == nil do + ap_id = + XML.string_from_xpath( + ~s{//Link[@rel="self" and @type="application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""]/@href}, + doc + ) + end + data = %{ "magic_key" => magic_key, "topic" => topic, @@ -185,6 +193,9 @@ defmodule Pleroma.Web.WebFinger do {"application/activity+json", "self"} -> Map.put(data, "ap_id", link["href"]) + {"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", "self"} -> + Map.put(data, "ap_id", link["href"]) + {_, "magic-public-key"} -> "data:application/magic-public-key," <> magic_key = link["href"] Map.put(data, "magic_key", magic_key) From 1a250d65afa6de25c3395fa1fad0e1d57e9ee1d2 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 06:15:21 +0000 Subject: [PATCH 3/5] webfinger: only do ld+json on modern json webfinger --- lib/pleroma/web/web_finger/web_finger.ex | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index b955bc43f..3744dd62f 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -118,7 +118,6 @@ defmodule Pleroma.Web.WebFinger do {:Link, %{rel: "magic-public-key", href: "data:application/magic-public-key,#{magic_key}"}}, {:Link, %{rel: "self", type: "application/activity+json", href: user.ap_id}}, - {:Link, %{rel: "self", type: "application/ld+json; profile="https://www.w3.org/ns/activitystreams"", href: user.ap_id}}, {:Link, %{rel: "http://ostatus.org/schema/1.0/subscribe", template: OStatus.remote_follow_path()}} ] @@ -166,14 +165,6 @@ defmodule Pleroma.Web.WebFinger do doc ) - if ap_id == nil do - ap_id = - XML.string_from_xpath( - ~s{//Link[@rel="self" and @type="application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""]/@href}, - doc - ) - end - data = %{ "magic_key" => magic_key, "topic" => topic, From f32e19f66881ed0939d83e2810c29081d5b11e16 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 06:11:45 +0000 Subject: [PATCH 4/5] webfinger: add tests --- .../fixtures/httpoison_mock/kaniini@gerzilla.de.json | 1 + test/support/httpoison_mock.ex | 12 ++++++++++++ test/web/web_finger/web_finger_test.exs | 8 ++++++++ 3 files changed, 21 insertions(+) create mode 100644 test/fixtures/httpoison_mock/kaniini@gerzilla.de.json diff --git a/test/fixtures/httpoison_mock/kaniini@gerzilla.de.json b/test/fixtures/httpoison_mock/kaniini@gerzilla.de.json new file mode 100644 index 000000000..be2f69b18 --- /dev/null +++ b/test/fixtures/httpoison_mock/kaniini@gerzilla.de.json @@ -0,0 +1 @@ +{"subject":"acct:kaniini","aliases":["https:\/\/gerzilla.de\/channel\/kaniini","https:\/\/gerzilla.de\/~kaniini","acct:kaniini@gerzilla.de"],"properties":{"http:\/\/webfinger.net\/ns\/name":"kaniini","http:\/\/xmlns.com\/foaf\/0.1\/name":"kaniini","https:\/\/w3id.org\/security\/v1#publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAvXCDkQPw+1N8B2CUd5s2\nbYvjHt+t7soMNfUiRy0qGbgW46S45k5lCq1KpbFIX3sgGZ4OWjnXVbvjCJi4kl5M\nfm5DBXzpuu05AmjVl8hqk4GejajiE\/1Nq0uWHPiOSFWispUjCzzCu65V+IsiE5JU\nvcL6WEf\/pYNRq7gYqyT693F7+cO5\/rVv9OScx5UOxbIuU1VXYhdHCqAMDJWadC89\nhePrcD3HOQKl06W2tDxHcWk6QjrdsUQGbNOgK\/QIN9gSxA+rCFEvH5O0HAhI0aXq\ncOB+vysJUFLeQOAqmAKvKS5V6RqE1GqqT0pDWHack4EmQi0gkgVzo+45xoP6wfDl\nWwG88w21LNxGvGHuN4I8mg6cEoApqKQBSOj086UtfDfSlPC1B+PRD2phE5etucHd\nF\/RIWN3SxVzU9BKIiaDm2gwOpvI8QuorQb6HDtZFO5NsSN3PnMnSywPe7kXl\/469\nuQRYXrseqyOVIi6WjhvXkyWVKVE5CBz+S8wXHfKph+9YOyUcJeAVMijp9wrjBlMc\noSzOGu79oM7tpMSq\/Xo6ePJ\/glNOwZR+OKrg92Qp9BGTKDNwGrxuxP\/9KwWtGLNf\nOMTtIkxtC3ubhxL3lBxOd7l+Bmum0UJV2f8ogkCgvTpIz05jMoyU8qWl6kkWNQlY\nDropXWaOfy7Lac+G4qlfSgsCAwEAAQ==\n-----END PUBLIC KEY-----\n","http:\/\/purl.org\/zot\/federation":"zot,activitypub"},"links":[{"rel":"http:\/\/webfinger.net\/rel\/avatar","type":"image\/png","href":"https:\/\/gerzilla.de\/photo\/profile\/l\/281"},{"rel":"http:\/\/microformats.org\/profile\/hcard","type":"text\/html","href":"https:\/\/gerzilla.de\/hcard\/kaniini"},{"rel":"http:\/\/webfinger.net\/rel\/profile-page","href":"https:\/\/gerzilla.de\/profile\/kaniini"},{"rel":"http:\/\/schemas.google.com\/g\/2010#updates-from","type":"application\/atom+xml","href":"https:\/\/gerzilla.de\/ofeed\/kaniini"},{"rel":"http:\/\/webfinger.net\/rel\/blog","href":"https:\/\/gerzilla.de\/channel\/kaniini"},{"rel":"http:\/\/ostatus.org\/schema\/1.0\/subscribe","template":"https:\/\/gerzilla.de\/follow?f=&url={uri}"},{"rel":"http:\/\/purl.org\/zot\/protocol","href":"https:\/\/gerzilla.de\/.well-known\/zot-info?address=kaniini@gerzilla.de"},{"rel":"http:\/\/purl.org\/openwebauth\/v1","type":"application\/x-zot+json","href":"https:\/\/gerzilla.de\/owa"},{"rel":"magic-public-key","href":"data:application\/magic-public-key,RSA.AL1wg5ED8PtTfAdglHebNm2L4x7fre7KDDX1IkctKhm4FuOkuOZOZQqtSqWxSF97IBmeDlo511W74wiYuJJeTH5uQwV86brtOQJo1ZfIapOBno2o4hP9TatLlhz4jkhVorKVIws8wruuVfiLIhOSVL3C-lhH_6WDUau4GKsk-vdxe_nDuf61b_TknMeVDsWyLlNVV2IXRwqgDAyVmnQvPYXj63A9xzkCpdOltrQ8R3FpOkI63bFEBmzToCv0CDfYEsQPqwhRLx-TtBwISNGl6nDgfr8rCVBS3kDgKpgCrykuVekahNRqqk9KQ1h2nJOBJkItIJIFc6PuOcaD-sHw5VsBvPMNtSzcRrxh7jeCPJoOnBKAKaikAUjo9POlLXw30pTwtQfj0Q9qYROXrbnB3Rf0SFjd0sVc1PQSiImg5toMDqbyPELqK0G-hw7WRTuTbEjdz5zJ0ssD3u5F5f-OvbkEWF67HqsjlSIulo4b15MllSlROQgc_kvMFx3yqYfvWDslHCXgFTIo6fcK4wZTHKEszhru_aDO7aTEqv16Onjyf4JTTsGUfjiq4PdkKfQRkygzcBq8bsT__SsFrRizXzjE7SJMbQt7m4cS95QcTne5fgZrptFCVdn_KIJAoL06SM9OYzKMlPKlpepJFjUJWA66KV1mjn8uy2nPhuKpX0oL.AQAB"},{"rel":"self","type":"application\/ld+json; profile=\"https:\/\/www.w3.org\/ns\/activitystreams\"","href":"https:\/\/gerzilla.de\/channel\/kaniini"}]} diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index 4a5a9ea85..e733afa59 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -3,6 +3,18 @@ defmodule HTTPoisonMock do def get(url, body \\ [], headers \\ []) + def get( + "http://gerzilla.de/.well-known/webfinger?resource=acct:kaniini@gerzilla.de", + [Accept: "application/xrd+xml,application/jrd+json"], + follow_redirect: true + ) do + {:ok, + %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/kaniini@gerzilla.de.json") + }} + end + def get( "http://framatube.org/.well-known/webfinger?resource=acct:framasoft@framatube.org", [Accept: "application/xrd+xml,application/jrd+json"], diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs index 69216f393..2d6ff2656 100644 --- a/test/web/web_finger/web_finger_test.exs +++ b/test/web/web_finger/web_finger_test.exs @@ -49,6 +49,14 @@ defmodule Pleroma.Web.WebFingerTest do {:ok, _data} = WebFinger.finger(user) end + test "returns the ActivityPub actor URI for an ActivityPub user with the ld+json mimetype" do + user = "kaniini@gerzilla.de" + + {:ok, data} = WebFinger.finger(user) + + assert data["ap_id"] == "https://gerzilla.de/channel/kaniini" + end + test "returns the correctly for json ostatus users" do user = "winterdienst@gnusocial.de" From 725b05d04aecaa00d5b79c81958267444bf3c91d Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 08:48:15 +0000 Subject: [PATCH 5/5] run mix format --- lib/pleroma/user.ex | 24 ++++++++++++++---------- lib/pleroma/web/web_finger/web_finger.ex | 6 +++++- test/support/httpoison_mock.ex | 10 +++++----- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 399a66787..6a8129ac8 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -404,18 +404,22 @@ defmodule Pleroma.User do from( u in User, select_merge: %{ - search_distance: fragment( - "? <-> (? || ?)", - ^query, - u.nickname, - u.name - )} + search_distance: + fragment( + "? <-> (? || ?)", + ^query, + u.nickname, + u.name + ) + } ) - q = from(s in subquery(inner), - order_by: s.search_distance, - limit: 20 - ) + q = + from( + s in subquery(inner), + order_by: s.search_distance, + limit: 20 + ) Repo.all(q) end diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 3744dd62f..6e5fc1401 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -86,7 +86,11 @@ defmodule Pleroma.Web.WebFinger do "href" => "data:application/magic-public-key,#{magic_key}" }, %{"rel" => "self", "type" => "application/activity+json", "href" => user.ap_id}, - %{"rel" => "self", "type" => "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", "href" => user.ap_id}, + %{ + "rel" => "self", + "type" => "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", + "href" => user.ap_id + }, %{ "rel" => "http://ostatus.org/schema/1.0/subscribe", "template" => OStatus.remote_follow_path() diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index e733afa59..a1a542103 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -8,11 +8,11 @@ defmodule HTTPoisonMock do [Accept: "application/xrd+xml,application/jrd+json"], follow_redirect: true ) do - {:ok, - %Response{ - status_code: 200, - body: File.read!("test/fixtures/httpoison_mock/kaniini@gerzilla.de.json") - }} + {:ok, + %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/kaniini@gerzilla.de.json") + }} end def get(