1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.WebFingerTest do
6 use Pleroma.DataCase, async: true
7 alias Pleroma.Web.WebFinger
12 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
16 describe "host meta" do
17 test "returns a link to the xml lrdd" do
18 host_info = WebFinger.host_meta()
20 assert String.contains?(host_info, Pleroma.Web.Endpoint.url())
24 describe "incoming webfinger request" do
25 test "works for fqns" do
29 WebFinger.webfinger("#{user.nickname}@#{Pleroma.Web.Endpoint.host()}", "XML")
31 assert is_binary(result)
34 test "works for ap_ids" do
37 {:ok, result} = WebFinger.webfinger(user.ap_id, "XML")
38 assert is_binary(result)
42 describe "fingering" do
43 test "returns error for nonsensical input" do
44 assert {:error, _} = WebFinger.finger("bliblablu")
45 assert {:error, _} = WebFinger.finger("pleroma.social")
48 test "returns error when there is no content-type header" do
50 %{url: "https://social.heldscal.la/.well-known/host-meta"} ->
54 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
59 "https://social.heldscal.la/.well-known/webfinger?resource=acct:invalid_content@social.heldscal.la"
61 {:ok, %Tesla.Env{status: 200, body: ""}}
64 user = "invalid_content@social.heldscal.la"
65 assert {:error, {:content_type, nil}} = WebFinger.finger(user)
68 test "returns error when fails parse xml or json" do
69 user = "invalid_content@social.heldscal.la"
70 assert {:error, %Jason.DecodeError{}} = WebFinger.finger(user)
73 test "returns the ActivityPub actor URI for an ActivityPub user" do
74 user = "framasoft@framatube.org"
76 {:ok, _data} = WebFinger.finger(user)
79 test "returns the ActivityPub actor URI and subscribe address for an ActivityPub user with the ld+json mimetype" do
80 user = "kaniini@gerzilla.de"
82 {:ok, data} = WebFinger.finger(user)
84 assert data["ap_id"] == "https://gerzilla.de/channel/kaniini"
85 assert data["subscribe_address"] == "https://gerzilla.de/follow?f=&url={uri}"
88 test "it work for AP-only user" do
89 user = "kpherox@mstdn.jp"
91 {:ok, data} = WebFinger.finger(user)
93 assert data["magic_key"] == nil
94 assert data["salmon"] == nil
96 assert data["topic"] == nil
97 assert data["subject"] == "acct:kPherox@mstdn.jp"
98 assert data["ap_id"] == "https://mstdn.jp/users/kPherox"
99 assert data["subscribe_address"] == "https://mstdn.jp/authorize_interaction?acct={uri}"
102 test "it works for friendica" do
103 user = "lain@squeet.me"
105 {:ok, _data} = WebFinger.finger(user)
108 test "it gets the xrd endpoint" do
109 {:ok, template} = WebFinger.find_lrdd_template("social.heldscal.la")
111 assert template == "https://social.heldscal.la/.well-known/webfinger?resource={uri}"
114 test "it gets the xrd endpoint for hubzilla" do
115 {:ok, template} = WebFinger.find_lrdd_template("macgirvin.com")
117 assert template == "https://macgirvin.com/xrd/?uri={uri}"
120 test "it gets the xrd endpoint for statusnet" do
121 {:ok, template} = WebFinger.find_lrdd_template("status.alpicola.com")
123 assert template == "https://status.alpicola.com/main/xrd?uri={uri}"
126 test "it works with idna domains as nickname" do
127 nickname = "lain@" <> to_string(:idna.encode("zetsubou.みんな"))
129 {:ok, _data} = WebFinger.finger(nickname)
132 test "it works with idna domains as link" do
133 ap_id = "https://" <> to_string(:idna.encode("zetsubou.みんな")) <> "/users/lain"
134 {:ok, _data} = WebFinger.finger(ap_id)
137 test "respects json content-type" do
141 "https://mastodon.social/.well-known/webfinger?resource=acct:emelie@mastodon.social"
146 body: File.read!("test/fixtures/tesla_mock/webfinger_emelie.json"),
147 headers: [{"content-type", "application/jrd+json"}]
150 %{url: "https://mastodon.social/.well-known/host-meta"} ->
154 body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
158 {:ok, _data} = WebFinger.finger("emelie@mastodon.social")
161 test "respects xml content-type" do
164 url: "https://pawoo.net/.well-known/webfinger?resource=acct:pekorino@pawoo.net"
169 body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.xml"),
170 headers: [{"content-type", "application/xrd+xml"}]
173 %{url: "https://pawoo.net/.well-known/host-meta"} ->
177 body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
181 {:ok, _data} = WebFinger.finger("pekorino@pawoo.net")