fix formatting
[akkoma] / test / web / web_finger / web_finger_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 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 info for an OStatus user" do
49 user = "shp@social.heldscal.la"
50
51 {:ok, data} = WebFinger.finger(user)
52
53 assert data["magic_key"] ==
54 "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB"
55
56 assert data["topic"] == "https://social.heldscal.la/api/statuses/user_timeline/29191.atom"
57 assert data["subject"] == "acct:shp@social.heldscal.la"
58 assert data["salmon"] == "https://social.heldscal.la/main/salmon/user/29191"
59 end
60
61 test "returns the ActivityPub actor URI for an ActivityPub user" do
62 user = "framasoft@framatube.org"
63
64 {:ok, _data} = WebFinger.finger(user)
65 end
66
67 test "returns the ActivityPub actor URI for an ActivityPub user with the ld+json mimetype" do
68 user = "kaniini@gerzilla.de"
69
70 {:ok, data} = WebFinger.finger(user)
71
72 assert data["ap_id"] == "https://gerzilla.de/channel/kaniini"
73 end
74
75 test "returns the correctly for json ostatus users" do
76 user = "winterdienst@gnusocial.de"
77
78 {:ok, data} = WebFinger.finger(user)
79
80 assert data["magic_key"] ==
81 "RSA.qfYaxztz7ZELrE4v5WpJrPM99SKI3iv9Y3Tw6nfLGk-4CRljNYqV8IYX2FXjeucC_DKhPNnlF6fXyASpcSmA_qupX9WC66eVhFhZ5OuyBOeLvJ1C4x7Hi7Di8MNBxY3VdQuQR0tTaS_YAZCwASKp7H6XEid3EJpGt0EQZoNzRd8=.AQAB"
82
83 assert data["topic"] == "https://gnusocial.de/api/statuses/user_timeline/249296.atom"
84 assert data["subject"] == "acct:winterdienst@gnusocial.de"
85 assert data["salmon"] == "https://gnusocial.de/main/salmon/user/249296"
86 assert data["subscribe_address"] == "https://gnusocial.de/main/ostatussub?profile={uri}"
87 end
88
89 test "it work for AP-only user" do
90 user = "kpherox@mstdn.jp"
91
92 {:ok, data} = WebFinger.finger(user)
93
94 assert data["magic_key"] == nil
95 assert data["salmon"] == nil
96
97 assert data["topic"] == "https://mstdn.jp/users/kPherox.atom"
98 assert data["subject"] == "acct:kPherox@mstdn.jp"
99 assert data["ap_id"] == "https://mstdn.jp/users/kPherox"
100 assert data["subscribe_address"] == "https://mstdn.jp/authorize_interaction?acct={uri}"
101 end
102
103 test "it works for friendica" do
104 user = "lain@squeet.me"
105
106 {:ok, _data} = WebFinger.finger(user)
107 end
108
109 test "it gets the xrd endpoint" do
110 {:ok, template} = WebFinger.find_lrdd_template("social.heldscal.la")
111
112 assert template == "https://social.heldscal.la/.well-known/webfinger?resource={uri}"
113 end
114
115 test "it gets the xrd endpoint for hubzilla" do
116 {:ok, template} = WebFinger.find_lrdd_template("macgirvin.com")
117
118 assert template == "https://macgirvin.com/xrd/?uri={uri}"
119 end
120
121 test "it gets the xrd endpoint for statusnet" do
122 {:ok, template} = WebFinger.find_lrdd_template("status.alpicola.com")
123
124 assert template == "http://status.alpicola.com/main/xrd?uri={uri}"
125 end
126
127 test "it works with idna domains as nickname" do
128 nickname = "lain@" <> to_string(:idna.encode("zetsubou.みんな"))
129
130 {:ok, _data} = WebFinger.finger(nickname)
131 end
132
133 test "it works with idna domains as link" do
134 ap_id = "https://" <> to_string(:idna.encode("zetsubou.みんな")) <> "/users/lain"
135 {:ok, _data} = WebFinger.finger(ap_id)
136 end
137 end
138 end