2018-12-23 21:11:29 +01:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-12-15 16:17:44 +01:00
|
|
|
defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
|
|
|
use Pleroma.Web.ConnCase
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
import Tesla.Mock
|
|
|
|
|
|
|
|
setup do
|
|
|
|
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
2019-07-09 08:30:51 +02:00
|
|
|
|
|
|
|
config_path = [:instance, :federating]
|
|
|
|
initial_setting = Pleroma.Config.get(config_path)
|
|
|
|
|
|
|
|
Pleroma.Config.put(config_path, true)
|
|
|
|
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
2018-12-15 16:17:44 +01:00
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
|
|
|
test "Webfinger JRD" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
response =
|
|
|
|
build_conn()
|
|
|
|
|> put_req_header("accept", "application/jrd+json")
|
|
|
|
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
|
|
|
|
|
|
|
|
assert json_response(response, 200)["subject"] == "acct:#{user.nickname}@localhost"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "Webfinger XML" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
response =
|
|
|
|
build_conn()
|
2018-12-15 17:34:37 +01:00
|
|
|
|> put_req_header("accept", "application/xrd+xml")
|
2018-12-15 16:17:44 +01:00
|
|
|
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
|
|
|
|
|
|
|
|
assert response(response, 200)
|
|
|
|
end
|
2018-12-15 17:34:37 +01:00
|
|
|
|
|
|
|
test "Sends a 400 when resource param is missing" do
|
|
|
|
response =
|
|
|
|
build_conn()
|
|
|
|
|> put_req_header("accept", "application/xrd+xml,application/jrd+json")
|
|
|
|
|> get("/.well-known/webfinger")
|
|
|
|
|
|
|
|
assert response(response, 400)
|
|
|
|
end
|
2018-12-15 16:17:44 +01:00
|
|
|
end
|