webfinger: fix finding the XRD uri for statusnet instances
[akkoma] / test / web / web_finger / web_finger_test.exs
1 defmodule Pleroma.Web.WebFingerTest do
2 use Pleroma.DataCase
3 alias Pleroma.Web.WebFinger
4 import Pleroma.Factory
5
6 describe "host meta" do
7 test "returns a link to the xml lrdd" do
8 host_info = WebFinger.host_meta()
9
10 assert String.contains?(host_info, Pleroma.Web.base_url())
11 end
12 end
13
14 describe "incoming webfinger request" do
15 test "works for fqns" do
16 user = insert(:user)
17
18 {:ok, result} =
19 WebFinger.webfinger("#{user.nickname}@#{Pleroma.Web.Endpoint.host()}", "XML")
20
21 assert is_binary(result)
22 end
23
24 test "works for ap_ids" do
25 user = insert(:user)
26
27 {:ok, result} = WebFinger.webfinger(user.ap_id, "XML")
28 assert is_binary(result)
29 end
30 end
31
32 describe "fingering" do
33 test "returns the info for an OStatus user" do
34 user = "shp@social.heldscal.la"
35
36 {:ok, data} = WebFinger.finger(user)
37
38 assert data["magic_key"] ==
39 "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB"
40
41 assert data["topic"] == "https://social.heldscal.la/api/statuses/user_timeline/29191.atom"
42 assert data["subject"] == "acct:shp@social.heldscal.la"
43 assert data["salmon"] == "https://social.heldscal.la/main/salmon/user/29191"
44 end
45
46 test "returns the ActivityPub actor URI for an ActivityPub user" do
47 user = "framasoft@framatube.org"
48
49 {:ok, _data} = WebFinger.finger(user)
50 end
51
52 test "returns the ActivityPub actor URI for an ActivityPub user with the ld+json mimetype" do
53 user = "kaniini@gerzilla.de"
54
55 {:ok, data} = WebFinger.finger(user)
56
57 assert data["ap_id"] == "https://gerzilla.de/channel/kaniini"
58 end
59
60 test "returns the correctly for json ostatus users" do
61 user = "winterdienst@gnusocial.de"
62
63 {:ok, data} = WebFinger.finger(user)
64
65 assert data["magic_key"] ==
66 "RSA.qfYaxztz7ZELrE4v5WpJrPM99SKI3iv9Y3Tw6nfLGk-4CRljNYqV8IYX2FXjeucC_DKhPNnlF6fXyASpcSmA_qupX9WC66eVhFhZ5OuyBOeLvJ1C4x7Hi7Di8MNBxY3VdQuQR0tTaS_YAZCwASKp7H6XEid3EJpGt0EQZoNzRd8=.AQAB"
67
68 assert data["topic"] == "https://gnusocial.de/api/statuses/user_timeline/249296.atom"
69 assert data["subject"] == "acct:winterdienst@gnusocial.de"
70 assert data["salmon"] == "https://gnusocial.de/main/salmon/user/249296"
71 assert data["subscribe_address"] == "https://gnusocial.de/main/ostatussub?profile={uri}"
72 end
73
74 test "it works for friendica" do
75 user = "lain@squeet.me"
76
77 {:ok, _data} = WebFinger.finger(user)
78 end
79
80 test "it gets the xrd endpoint" do
81 {:ok, template} = WebFinger.find_lrdd_template("social.heldscal.la")
82
83 assert template == "https://social.heldscal.la/.well-known/webfinger?resource={uri}"
84 end
85
86 test "it gets the xrd endpoint for hubzilla" do
87 {:ok, template} = WebFinger.find_lrdd_template("macgirvin.com")
88
89 assert template == "https://macgirvin.com/xrd/?uri={uri}"
90 end
91
92 test "it gets the xrd endpoint for statusnet" do
93 {:ok, template} = WebFinger.find_lrdd_template("status.alpicola.com")
94
95 assert template == "http://status.alpicola.com/main/xrd?uri={uri}"
96 end
97 end
98
99 describe "ensure_keys_present" do
100 test "it creates keys for a user and stores them in info" do
101 user = insert(:user)
102 refute is_binary(user.info["keys"])
103 {:ok, user} = WebFinger.ensure_keys_present(user)
104 assert is_binary(user.info["keys"])
105 end
106
107 test "it doesn't create keys if there already are some" do
108 user = insert(:user, %{info: %{"keys" => "xxx"}})
109 {:ok, user} = WebFinger.ensure_keys_present(user)
110 assert user.info["keys"] == "xxx"
111 end
112 end
113 end