logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma
commit: e3a81fe58f42935c6116ccc59c73ae41e99ecaae
parent: d1ee3edd3cf8262520421fda551e931d6a8e5733
Author: lain <lain@soykaf.club>
Date:   Sat, 24 Mar 2018 14:45:21 +0100

Fetch the same data from json webfinger as from xml webfinger.

Diffstat:

Mlib/pleroma/web/web_finger/web_finger.ex15++++++++++++---
Atest/fixtures/httpoison_mock/winterdienst_webfinger.json2++
Mtest/support/httpoison_mock.ex6++++++
Mtest/web/web_finger/web_finger_test.exs12++++++++++++
4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex @@ -118,14 +118,23 @@ defmodule Pleroma.Web.WebFinger do {:ok, data} end - # TODO: maybe fill in other details from JRD webfinger response defp webfinger_from_json(doc) do data = Enum.reduce(doc["links"], %{"subject" => doc["subject"]}, fn (link, data) -> - case link["type"] do - "application/activity+json" -> + case {link["type"], link["rel"]} do + {"application/activity+json", "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) + {"application/atom+xml", "http://schemas.google.com/g/2010#updates-from"} -> + Map.put(data, "topic", link["href"]) + {_, "salmon"} -> + Map.put(data, "salmon", link["href"]) + {_, "http://ostatus.org/schema/1.0/subscribe"} -> + Map.put(data, "subscribe_address", link["template"]) _ -> Logger.debug("Unhandled type: #{inspect(link["type"])}") + data end end) {:ok, data} diff --git a/test/fixtures/httpoison_mock/winterdienst_webfinger.json b/test/fixtures/httpoison_mock/winterdienst_webfinger.json @@ -0,0 +1 @@ +{"subject":"acct:winterdienst@gnusocial.de","aliases":["https:\/\/gnusocial.de\/user\/249296","https:\/\/gnusocial.de\/winterdienst","https:\/\/gnusocial.de\/index.php\/user\/249296","https:\/\/gnusocial.de\/index.php\/winterdienst"],"links":[{"rel":"http:\/\/webfinger.net\/rel\/profile-page","type":"text\/html","href":"https:\/\/gnusocial.de\/winterdienst"},{"rel":"http:\/\/gmpg.org\/xfn\/11","type":"text\/html","href":"https:\/\/gnusocial.de\/winterdienst"},{"rel":"describedby","type":"application\/rdf+xml","href":"https:\/\/gnusocial.de\/winterdienst\/foaf"},{"rel":"http:\/\/apinamespace.org\/atom","type":"application\/atomsvc+xml","href":"https:\/\/gnusocial.de\/api\/statusnet\/app\/service\/winterdienst.xml"},{"rel":"http:\/\/apinamespace.org\/twitter","href":"https:\/\/gnusocial.de\/api\/"},{"rel":"http:\/\/schemas.google.com\/g\/2010#updates-from","type":"application\/atom+xml","href":"https:\/\/gnusocial.de\/api\/statuses\/user_timeline\/249296.atom"},{"rel":"magic-public-key","href":"data:application\/magic-public-key,RSA.qfYaxztz7ZELrE4v5WpJrPM99SKI3iv9Y3Tw6nfLGk-4CRljNYqV8IYX2FXjeucC_DKhPNnlF6fXyASpcSmA_qupX9WC66eVhFhZ5OuyBOeLvJ1C4x7Hi7Di8MNBxY3VdQuQR0tTaS_YAZCwASKp7H6XEid3EJpGt0EQZoNzRd8=.AQAB"},{"rel":"salmon","href":"https:\/\/gnusocial.de\/main\/salmon\/user\/249296"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-replies","href":"https:\/\/gnusocial.de\/main\/salmon\/user\/249296"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-mention","href":"https:\/\/gnusocial.de\/main\/salmon\/user\/249296"},{"rel":"http:\/\/ostatus.org\/schema\/1.0\/subscribe","template":"https:\/\/gnusocial.de\/main\/ostatussub?profile={uri}"}]}+ \ No newline at end of file diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex @@ -9,6 +9,12 @@ defmodule HTTPoisonMock do body: File.read!("test/fixtures/httpoison_mock/framasoft@framatube.org.json") }} end + def get("http://gnusocial.de/.well-known/webfinger?resource=acct:winterdienst@gnusocial.de", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do + {:ok, %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/winterdienst_webfinger.json") + }} + end def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "nonexistant@social.heldscal.la"], follow_redirect: true]) do {:ok, %Response{ diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs @@ -45,6 +45,18 @@ defmodule Pleroma.Web.WebFingerTest do {:ok, _data} = WebFinger.finger(user) end + test "returns the correctly for json ostatus users" do + user = "winterdienst@gnusocial.de" + + {:ok, data} = WebFinger.finger(user) + + assert data["magic_key"] == "RSA.qfYaxztz7ZELrE4v5WpJrPM99SKI3iv9Y3Tw6nfLGk-4CRljNYqV8IYX2FXjeucC_DKhPNnlF6fXyASpcSmA_qupX9WC66eVhFhZ5OuyBOeLvJ1C4x7Hi7Di8MNBxY3VdQuQR0tTaS_YAZCwASKp7H6XEid3EJpGt0EQZoNzRd8=.AQAB" + assert data["topic"] == "https://gnusocial.de/api/statuses/user_timeline/249296.atom" + assert data["subject"] == "acct:winterdienst@gnusocial.de" + assert data["salmon"] == "https://gnusocial.de/main/salmon/user/249296" + assert data["subscribe_address"] == "https://gnusocial.de/main/ostatussub?profile={uri}" + end + test "it works for friendica" do user = "lain@squeet.me"