Fetch the same data from json webfinger as from xml webfinger.
authorlain <lain@soykaf.club>
Sat, 24 Mar 2018 13:45:21 +0000 (14:45 +0100)
committerlain <lain@soykaf.club>
Sat, 24 Mar 2018 13:45:54 +0000 (14:45 +0100)
lib/pleroma/web/web_finger/web_finger.ex
test/fixtures/httpoison_mock/winterdienst_webfinger.json [new file with mode: 0644]
test/support/httpoison_mock.ex
test/web/web_finger/web_finger_test.exs

index d8eb6f3e0e7a780d80c4660f9d097fc97bdc7d90..7391edcd74fcc70acf4badf433f907cab115b6ea 100644 (file)
@@ -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
new file mode 100644 (file)
index 0000000..e7bfba9
--- /dev/null
@@ -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
index 5d021a3b4ba098de8642a87c0620f950a0eba882..c70598691c71f91714b90a1d76f3e928f099188d 100644 (file)
@@ -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{
index ff60391fdba9e7dada7f20a2b2f96090f81965ab..c7ad206eb2d35ec6f17ed9da37777d4fd482a4af 100644 (file)
@@ -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"