1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.WebFingerTest do
7 alias Pleroma.Web.WebFinger
12 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
16 describe "host meta" do
17 test "returns a link to the xml lrdd" do
18 host_info = WebFinger.host_meta()
20 assert String.contains?(host_info, Pleroma.Web.base_url())
24 describe "incoming webfinger request" do
25 test "works for fqns" do
29 WebFinger.webfinger("#{user.nickname}@#{Pleroma.Web.Endpoint.host()}", "XML")
31 assert is_binary(result)
34 test "works for ap_ids" do
37 {:ok, result} = WebFinger.webfinger(user.ap_id, "XML")
38 assert is_binary(result)
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")
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)
53 test "returns the ActivityPub actor URI for an ActivityPub user" do
54 user = "framasoft@framatube.org"
56 {:ok, _data} = WebFinger.finger(user)
59 test "returns the ActivityPub actor URI for an ActivityPub user with the ld+json mimetype" do
60 user = "kaniini@gerzilla.de"
62 {:ok, data} = WebFinger.finger(user)
64 assert data["ap_id"] == "https://gerzilla.de/channel/kaniini"
67 test "it work for AP-only user" do
68 user = "kpherox@mstdn.jp"
70 {:ok, data} = WebFinger.finger(user)
72 assert data["magic_key"] == nil
73 assert data["salmon"] == nil
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}"
81 test "it works for friendica" do
82 user = "lain@squeet.me"
84 {:ok, _data} = WebFinger.finger(user)
87 test "it gets the xrd endpoint" do
88 {:ok, template} = WebFinger.find_lrdd_template("social.heldscal.la")
90 assert template == "https://social.heldscal.la/.well-known/webfinger?resource={uri}"
93 test "it gets the xrd endpoint for hubzilla" do
94 {:ok, template} = WebFinger.find_lrdd_template("macgirvin.com")
96 assert template == "https://macgirvin.com/xrd/?uri={uri}"
99 test "it gets the xrd endpoint for statusnet" do
100 {:ok, template} = WebFinger.find_lrdd_template("status.alpicola.com")
102 assert template == "http://status.alpicola.com/main/xrd?uri={uri}"
105 test "it works with idna domains as nickname" do
106 nickname = "lain@" <> to_string(:idna.encode("zetsubou.みんな"))
108 {:ok, _data} = WebFinger.finger(nickname)
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)