2018-12-27 10:24:04 +00:00
|
|
|
# Portions of this file are derived from Pleroma:
|
|
|
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/web_finger/web_finger_test.exs
|
|
|
|
|
2020-01-26 20:36:50 +00:00
|
|
|
defmodule Mobilizon.Web.WebFingerControllerTest do
|
|
|
|
use Mobilizon.Web.ConnCase
|
2020-01-22 01:14:42 +00:00
|
|
|
|
2018-11-27 17:42:56 +00:00
|
|
|
import Mobilizon.Factory
|
|
|
|
|
2020-01-22 01:14:42 +00:00
|
|
|
alias Mobilizon.Actors.Actor
|
2020-01-22 21:40:40 +00:00
|
|
|
alias Mobilizon.Federation.WebFinger
|
2020-01-22 01:14:42 +00:00
|
|
|
|
2020-01-28 18:18:33 +00:00
|
|
|
alias Mobilizon.Web.Endpoint
|
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
setup_all do
|
|
|
|
Mobilizon.Config.put([:instance, :federating], true)
|
2020-01-22 01:14:42 +00:00
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2018-11-27 17:42:56 +00:00
|
|
|
test "GET /.well-known/host-meta", %{conn: conn} do
|
|
|
|
conn = get(conn, "/.well-known/host-meta")
|
|
|
|
|
|
|
|
assert response(conn, 200) ==
|
2021-06-07 14:39:44 +00:00
|
|
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><XRD xmlns=\"http://docs.oasis-open.org/ns/xri/xrd-1.0\" xmlns:hm=\"http://host-meta.net/ns/1.0\"><hm:Host>mobilizon.test</hm:Host><Link rel=\"lrdd\" template=\"#{Endpoint.url()}/.well-known/webfinger?resource={uri}\" type=\"application/jrd+json\" /></XRD>"
|
2018-11-27 17:42:56 +00:00
|
|
|
|
|
|
|
assert {"content-type", "application/xrd+xml; charset=utf-8"} in conn.resp_headers
|
|
|
|
end
|
|
|
|
|
|
|
|
test "GET /.well-known/webfinger with local actor", %{conn: conn} do
|
|
|
|
%Actor{preferred_username: username} = actor = insert(:actor)
|
2019-01-03 10:34:31 +00:00
|
|
|
conn = get(conn, "/.well-known/webfinger?resource=acct:#{username}@mobilizon.test")
|
2021-10-05 13:29:06 +00:00
|
|
|
assert json_response(conn, 200) == WebFinger.represent_actor(actor, "JSON")
|
2018-11-27 17:42:56 +00:00
|
|
|
end
|
|
|
|
|
2018-11-28 09:49:16 +00:00
|
|
|
test "GET /.well-known/webfinger with non existent actor", %{conn: conn} do
|
2019-01-03 10:34:31 +00:00
|
|
|
conn = get(conn, "/.well-known/webfinger?resource=acct:notme@mobilizon.test")
|
2018-11-28 09:49:16 +00:00
|
|
|
assert response(conn, 404) == "Couldn't find user"
|
|
|
|
end
|
|
|
|
|
2018-11-27 17:42:56 +00:00
|
|
|
test "GET /.well-known/webfinger with no query", %{conn: conn} do
|
|
|
|
conn = get(conn, "/.well-known/webfinger")
|
|
|
|
assert response(conn, 400) == "No query provided"
|
|
|
|
end
|
|
|
|
end
|