Merge branch 'develop' into feature/gen-magic
[akkoma] / test / pleroma / web / web_finger_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.WebFingerTest do
6 use Pleroma.DataCase
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.base_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 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 end
66
67 test "it work for AP-only user" do
68 user = "kpherox@mstdn.jp"
69
70 {:ok, data} = WebFinger.finger(user)
71
72 assert data["magic_key"] == nil
73 assert data["salmon"] == nil
74
75 assert data["topic"] == nil
76 assert data["subject"] == "acct:kPherox@mstdn.jp"
77 assert data["ap_id"] == "https://mstdn.jp/users/kPherox"
78 assert data["subscribe_address"] == "https://mstdn.jp/authorize_interaction?acct={uri}"
79 end
80
81 test "it works for friendica" do
82 user = "lain@squeet.me"
83
84 {:ok, _data} = WebFinger.finger(user)
85 end
86
87 test "it gets the xrd endpoint" do
88 {:ok, template} = WebFinger.find_lrdd_template("social.heldscal.la")
89
90 assert template == "https://social.heldscal.la/.well-known/webfinger?resource={uri}"
91 end
92
93 test "it gets the xrd endpoint for hubzilla" do
94 {:ok, template} = WebFinger.find_lrdd_template("macgirvin.com")
95
96 assert template == "https://macgirvin.com/xrd/?uri={uri}"
97 end
98
99 test "it gets the xrd endpoint for statusnet" do
100 {:ok, template} = WebFinger.find_lrdd_template("status.alpicola.com")
101
102 assert template == "http://status.alpicola.com/main/xrd?uri={uri}"
103 end
104
105 test "it works with idna domains as nickname" do
106 nickname = "lain@" <> to_string(:idna.encode("zetsubou.みんな"))
107
108 {:ok, _data} = WebFinger.finger(nickname)
109 end
110
111 test "it works with idna domains as link" do
112 ap_id = "https://" <> to_string(:idna.encode("zetsubou.みんな")) <> "/users/lain"
113 {:ok, _data} = WebFinger.finger(ap_id)
114 end
115 end
116 end