webfinger: fix finding the XRD uri for statusnet instances
authorWilliam Pitcock <nenolod@dereferenced.org>
Mon, 21 May 2018 12:38:12 +0000 (12:38 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Mon, 21 May 2018 12:41:31 +0000 (12:41 +0000)
lib/pleroma/web/web_finger/web_finger.ex
test/fixtures/httpoison_mock/status.alpicola.com_host_meta [new file with mode: 0644]
test/support/httpoison_mock.ex
test/web/web_finger/web_finger_test.exs

index 6e5fc140185dcbfa122c5c701e6232b887e36534..9c6f1cb686583f5a46e6078bb20842ff987bdf11 100644 (file)
@@ -214,7 +214,7 @@ defmodule Pleroma.Web.WebFinger do
   end
 
   def get_template_from_xml(body) do
-    xpath = "//Link[@rel='lrdd' and @type='application/xrd+xml']/@template"
+    xpath = "//Link[@rel='lrdd']/@template"
 
     with doc when doc != :error <- XML.parse_document(body),
          template when template != nil <- XML.string_from_xpath(xpath, doc) do
diff --git a/test/fixtures/httpoison_mock/status.alpicola.com_host_meta b/test/fixtures/httpoison_mock/status.alpicola.com_host_meta
new file mode 100644 (file)
index 0000000..6948c30
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><hm:Host xmlns:hm="http://host-meta.net/xrd/1.0">status.alpicola.com</hm:Host><Link rel="lrdd" template="http://status.alpicola.com/main/xrd?uri={uri}"><Title>Resource Descriptor</Title></Link></XRD>
\ No newline at end of file
index f28557975c7603ed5e74e0b5fce909c9fbb0fa33..6e8336a938ad5010fc9c80385386c8fa5402ee7b 100644 (file)
@@ -531,6 +531,14 @@ defmodule HTTPoisonMock do
      }}
   end
 
+  def get("http://status.alpicola.com/.well-known/host-meta", [], follow_redirect: true) do
+    {:ok,
+     %Response{
+       status_code: 200,
+       body: File.read!("test/fixtures/httpoison_mock/status.alpicola.com_host_meta")
+     }}
+  end
+
   def get("http://macgirvin.com/.well-known/host-meta", [], follow_redirect: true) do
     {:ok,
      %Response{
index 2d6ff2656f345e8efe2794753bc727481711768b..99bf210ea54d957e613182543436909a204a037e 100644 (file)
@@ -88,6 +88,12 @@ defmodule Pleroma.Web.WebFingerTest do
 
       assert template == "https://macgirvin.com/xrd/?uri={uri}"
     end
+
+    test "it gets the xrd endpoint for statusnet" do
+      {:ok, template} = WebFinger.find_lrdd_template("status.alpicola.com")
+
+      assert template == "http://status.alpicola.com/main/xrd?uri={uri}"
+    end
   end
 
   describe "ensure_keys_present" do