webfinger: support JSON output
[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} = WebFinger.webfinger("#{user.nickname}@#{Pleroma.Web.Endpoint.host}", "XML")
19 assert is_binary(result)
20 end
21
22 test "works for ap_ids" do
23 user = insert(:user)
24
25 {:ok, result} = WebFinger.webfinger(user.ap_id, "XML")
26 assert is_binary(result)
27 end
28 end
29
30 describe "fingering" do
31 test "returns the info for a user" do
32 user = "shp@social.heldscal.la"
33
34 {:ok, data} = WebFinger.finger(user)
35
36 assert data["magic_key"] == "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB"
37 assert data["topic"] == "https://social.heldscal.la/api/statuses/user_timeline/29191.atom"
38 assert data["subject"] == "acct:shp@social.heldscal.la"
39 assert data["salmon"] == "https://social.heldscal.la/main/salmon/user/29191"
40 end
41
42 test "it works for friendica" do
43 user = "lain@squeet.me"
44
45 {:ok, _data} = WebFinger.finger(user)
46 end
47
48 test "it gets the xrd endpoint" do
49 {:ok, template} = WebFinger.find_lrdd_template("social.heldscal.la")
50
51 assert template == "https://social.heldscal.la/.well-known/webfinger?resource={uri}"
52 end
53
54 test "it gets the xrd endpoint for hubzilla" do
55 {:ok, template} = WebFinger.find_lrdd_template("macgirvin.com")
56
57 assert template == "https://macgirvin.com/xrd/?uri={uri}"
58 end
59 end
60
61 describe "ensure_keys_present" do
62 test "it creates keys for a user and stores them in info" do
63 user = insert(:user)
64 refute is_binary(user.info["keys"])
65 {:ok, user} = WebFinger.ensure_keys_present(user)
66 assert is_binary(user.info["keys"])
67 end
68
69 test "it doesn't create keys if there already are some" do
70 user = insert(:user, %{info: %{"keys" => "xxx"}})
71 {:ok, user} = WebFinger.ensure_keys_present(user)
72 assert user.info["keys"] == "xxx"
73 end
74 end
75 end