2018-12-23 20:11:29 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 22:44:49 +00:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 20:11:29 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-12-15 15:17:44 +00:00
|
|
|
defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
|
|
|
use Pleroma.Web.ConnCase
|
|
|
|
|
2019-09-13 15:46:41 +00:00
|
|
|
import ExUnit.CaptureLog
|
2018-12-15 15:17:44 +00:00
|
|
|
import Pleroma.Factory
|
|
|
|
import Tesla.Mock
|
|
|
|
|
|
|
|
setup do
|
|
|
|
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2020-03-18 17:30:31 +00:00
|
|
|
clear_config_all([:instance, :federating], true)
|
2019-08-19 15:34:29 +00:00
|
|
|
|
2019-07-24 15:13:10 +00:00
|
|
|
test "GET host-meta" do
|
|
|
|
response =
|
|
|
|
build_conn()
|
|
|
|
|> get("/.well-known/host-meta")
|
|
|
|
|
|
|
|
assert response.status == 200
|
|
|
|
|
|
|
|
assert response.resp_body ==
|
|
|
|
~s(<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" template="#{
|
|
|
|
Pleroma.Web.base_url()
|
|
|
|
}/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>)
|
|
|
|
end
|
|
|
|
|
2018-12-15 15:17:44 +00:00
|
|
|
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
|
|
|
|
|
2019-07-24 15:13:10 +00:00
|
|
|
test "it returns 404 when user isn't found (JSON)" do
|
|
|
|
result =
|
|
|
|
build_conn()
|
|
|
|
|> put_req_header("accept", "application/jrd+json")
|
|
|
|
|> get("/.well-known/webfinger?resource=acct:jimm@localhost")
|
|
|
|
|> json_response(404)
|
|
|
|
|
|
|
|
assert result == "Couldn't find user"
|
|
|
|
end
|
|
|
|
|
2018-12-15 15:17:44 +00:00
|
|
|
test "Webfinger XML" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
response =
|
|
|
|
build_conn()
|
2018-12-15 16:34:37 +00:00
|
|
|
|> put_req_header("accept", "application/xrd+xml")
|
2018-12-15 15:17:44 +00:00
|
|
|
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
|
|
|
|
|
|
|
|
assert response(response, 200)
|
|
|
|
end
|
2018-12-15 16:34:37 +00:00
|
|
|
|
2019-07-24 15:13:10 +00:00
|
|
|
test "it returns 404 when user isn't found (XML)" do
|
|
|
|
result =
|
|
|
|
build_conn()
|
|
|
|
|> put_req_header("accept", "application/xrd+xml")
|
|
|
|
|> get("/.well-known/webfinger?resource=acct:jimm@localhost")
|
|
|
|
|> response(404)
|
|
|
|
|
|
|
|
assert result == "Couldn't find user"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "Sends a 404 when invalid format" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2019-09-13 15:46:41 +00:00
|
|
|
assert capture_log(fn ->
|
|
|
|
assert_raise Phoenix.NotAcceptableError, fn ->
|
|
|
|
build_conn()
|
|
|
|
|> put_req_header("accept", "text/html")
|
|
|
|
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
|
|
|
|
end
|
|
|
|
end) =~ "no supported media type in accept header"
|
2019-07-24 15:13:10 +00:00
|
|
|
end
|
|
|
|
|
2018-12-15 16:34:37 +00: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 15:17:44 +00:00
|
|
|
end
|