Deprecate Pleroma.Web.base_url/0
[akkoma] / test / pleroma / web / web_finger_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.WebFingerTest do
6 use Pleroma.DataCase, async: true
7 alias Pleroma.Web.WebFinger
8 import Pleroma.Factory
9 import Tesla.Mock
10
11 setup do
12 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
13 :ok
14 end
15
16 describe "host meta" do
17 test "returns a link to the xml lrdd" do
18 host_info = WebFinger.host_meta()
19
20 assert String.contains?(host_info, Pleroma.Web.Endpoint.url())
21 end
22 end
23
24 describe "incoming webfinger request" do
25 test "works for fqns" do
26 user = insert(:user)
27
28 {:ok, result} =
29 WebFinger.webfinger("#{user.nickname}@#{Pleroma.Web.Endpoint.host()}", "XML")
30
31 assert is_binary(result)
32 end
33
34 test "works for ap_ids" do
35 user = insert(:user)
36
37 {:ok, result} = WebFinger.webfinger(user.ap_id, "XML")
38 assert is_binary(result)
39 end
40 end
41
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")
46 end
47
48 test "returns error when fails parse xml or json" do
49 user = "invalid_content@social.heldscal.la"
50 assert {:error, %Jason.DecodeError{}} = WebFinger.finger(user)
51 end
52
53 test "returns the ActivityPub actor URI for an ActivityPub user" do
54 user = "framasoft@framatube.org"
55
56 {:ok, _data} = WebFinger.finger(user)
57 end
58
59 test "returns the ActivityPub actor URI and subscribe address for an ActivityPub user with the ld+json mimetype" do
60 user = "kaniini@gerzilla.de"
61
62 {:ok, data} = WebFinger.finger(user)
63
64 assert data["ap_id"] == "https://gerzilla.de/channel/kaniini"
65 assert data["subscribe_address"] == "https://gerzilla.de/follow?f=&url={uri}"
66 end
67
68 test "it work for AP-only user" do
69 user = "kpherox@mstdn.jp"
70
71 {:ok, data} = WebFinger.finger(user)
72
73 assert data["magic_key"] == nil
74 assert data["salmon"] == nil
75
76 assert data["topic"] == nil
77 assert data["subject"] == "acct:kPherox@mstdn.jp"
78 assert data["ap_id"] == "https://mstdn.jp/users/kPherox"
79 assert data["subscribe_address"] == "https://mstdn.jp/authorize_interaction?acct={uri}"
80 end
81
82 test "it works for friendica" do
83 user = "lain@squeet.me"
84
85 {:ok, _data} = WebFinger.finger(user)
86 end
87
88 test "it gets the xrd endpoint" do
89 {:ok, template} = WebFinger.find_lrdd_template("social.heldscal.la")
90
91 assert template == "https://social.heldscal.la/.well-known/webfinger?resource={uri}"
92 end
93
94 test "it gets the xrd endpoint for hubzilla" do
95 {:ok, template} = WebFinger.find_lrdd_template("macgirvin.com")
96
97 assert template == "https://macgirvin.com/xrd/?uri={uri}"
98 end
99
100 test "it gets the xrd endpoint for statusnet" do
101 {:ok, template} = WebFinger.find_lrdd_template("status.alpicola.com")
102
103 assert template == "http://status.alpicola.com/main/xrd?uri={uri}"
104 end
105
106 test "it works with idna domains as nickname" do
107 nickname = "lain@" <> to_string(:idna.encode("zetsubou.みんな"))
108
109 {:ok, _data} = WebFinger.finger(nickname)
110 end
111
112 test "it works with idna domains as link" do
113 ap_id = "https://" <> to_string(:idna.encode("zetsubou.みんな")) <> "/users/lain"
114 {:ok, _data} = WebFinger.finger(ap_id)
115 end
116 end
117 end