Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / test / web / web_finger / 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 when fails parse xml or json" do
44 user = "invalid_content@social.heldscal.la"
45 assert {:error, %Jason.DecodeError{}} = WebFinger.finger(user)
46 end
47
48 test "returns the ActivityPub actor URI for an ActivityPub user" do
49 user = "framasoft@framatube.org"
50
51 {:ok, _data} = WebFinger.finger(user)
52 end
53
54 test "returns the ActivityPub actor URI for an ActivityPub user with the ld+json mimetype" do
55 user = "kaniini@gerzilla.de"
56
57 {:ok, data} = WebFinger.finger(user)
58
59 assert data["ap_id"] == "https://gerzilla.de/channel/kaniini"
60 end
61
62 test "it work for AP-only user" do
63 user = "kpherox@mstdn.jp"
64
65 {:ok, data} = WebFinger.finger(user)
66
67 assert data["magic_key"] == nil
68 assert data["salmon"] == nil
69
70 assert data["topic"] == "https://mstdn.jp/users/kPherox.atom"
71 assert data["subject"] == "acct:kPherox@mstdn.jp"
72 assert data["ap_id"] == "https://mstdn.jp/users/kPherox"
73 assert data["subscribe_address"] == "https://mstdn.jp/authorize_interaction?acct={uri}"
74 end
75
76 test "it works for friendica" do
77 user = "lain@squeet.me"
78
79 {:ok, _data} = WebFinger.finger(user)
80 end
81
82 test "it gets the xrd endpoint" do
83 {:ok, template} = WebFinger.find_lrdd_template("social.heldscal.la")
84
85 assert template == "https://social.heldscal.la/.well-known/webfinger?resource={uri}"
86 end
87
88 test "it gets the xrd endpoint for hubzilla" do
89 {:ok, template} = WebFinger.find_lrdd_template("macgirvin.com")
90
91 assert template == "https://macgirvin.com/xrd/?uri={uri}"
92 end
93
94 test "it gets the xrd endpoint for statusnet" do
95 {:ok, template} = WebFinger.find_lrdd_template("status.alpicola.com")
96
97 assert template == "http://status.alpicola.com/main/xrd?uri={uri}"
98 end
99
100 test "it works with idna domains as nickname" do
101 nickname = "lain@" <> to_string(:idna.encode("zetsubou.みんな"))
102
103 {:ok, _data} = WebFinger.finger(nickname)
104 end
105
106 test "it works with idna domains as link" do
107 ap_id = "https://" <> to_string(:idna.encode("zetsubou.みんな")) <> "/users/lain"
108 {:ok, _data} = WebFinger.finger(ap_id)
109 end
110 end
111 end