2018-12-23 13:11:29 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 13:11:29 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-12-15 08:17:44 -07:00
|
|
|
defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
2023-08-01 04:43:50 -06:00
|
|
|
use Pleroma.Web.ConnCase, async: false
|
2018-12-15 08:17:44 -07:00
|
|
|
|
2019-09-13 09:46:41 -06:00
|
|
|
import ExUnit.CaptureLog
|
2018-12-15 08:17:44 -07:00
|
|
|
import Pleroma.Factory
|
|
|
|
import Tesla.Mock
|
2023-08-07 04:12:14 -06:00
|
|
|
import Pleroma.Test.Matchers.XML
|
2018-12-15 08:17:44 -07:00
|
|
|
|
|
|
|
setup do
|
|
|
|
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2020-03-20 09:33:00 -06:00
|
|
|
setup_all do: clear_config([:instance, :federating], true)
|
2019-08-19 09:34:29 -06:00
|
|
|
|
2019-07-24 09:13:10 -06:00
|
|
|
test "GET host-meta" do
|
|
|
|
response =
|
|
|
|
build_conn()
|
|
|
|
|> get("/.well-known/host-meta")
|
|
|
|
|
|
|
|
assert response.status == 200
|
|
|
|
|
2023-08-07 09:17:17 -06:00
|
|
|
assert_xml_equals(
|
|
|
|
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.Endpoint.url()}/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>)
|
|
|
|
)
|
2019-07-24 09:13:10 -06:00
|
|
|
end
|
|
|
|
|
2018-12-15 08:17:44 -07:00
|
|
|
test "Webfinger JRD" do
|
2020-07-16 21:19:17 -06:00
|
|
|
user =
|
|
|
|
insert(:user,
|
|
|
|
ap_id: "https://hyrule.world/users/zelda",
|
2020-08-07 15:48:03 -06:00
|
|
|
also_known_as: ["https://mushroom.kingdom/users/toad"]
|
2020-07-16 21:19:17 -06:00
|
|
|
)
|
2018-12-15 08:17:44 -07:00
|
|
|
|
|
|
|
response =
|
|
|
|
build_conn()
|
|
|
|
|> put_req_header("accept", "application/jrd+json")
|
|
|
|
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
|
2020-07-16 21:19:17 -06:00
|
|
|
|> json_response(200)
|
|
|
|
|
|
|
|
assert response["subject"] == "acct:#{user.nickname}@localhost"
|
2018-12-15 08:17:44 -07:00
|
|
|
|
2020-07-16 21:19:17 -06:00
|
|
|
assert response["aliases"] == [
|
2024-02-29 12:56:32 -07:00
|
|
|
"https://hyrule.world/users/zelda"
|
2020-07-16 21:19:17 -06:00
|
|
|
]
|
2018-12-15 08:17:44 -07:00
|
|
|
end
|
|
|
|
|
2022-08-02 07:54:22 -06:00
|
|
|
test "reach user on tld, while pleroma is runned on subdomain" do
|
|
|
|
Pleroma.Web.Endpoint.config_change(
|
|
|
|
[{Pleroma.Web.Endpoint, url: [host: "sub.example.com"]}],
|
|
|
|
[]
|
|
|
|
)
|
|
|
|
|
|
|
|
clear_config([Pleroma.Web.Endpoint, :url, :host], "sub.example.com")
|
|
|
|
|
|
|
|
clear_config([Pleroma.Web.WebFinger, :domain], "example.com")
|
|
|
|
|
|
|
|
user = insert(:user, ap_id: "https://sub.example.com/users/bobby", nickname: "bobby")
|
|
|
|
|
|
|
|
response =
|
|
|
|
build_conn()
|
|
|
|
|> put_req_header("accept", "application/jrd+json")
|
|
|
|
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@example.com")
|
|
|
|
|> json_response(200)
|
|
|
|
|
|
|
|
assert response["subject"] == "acct:#{user.nickname}@example.com"
|
|
|
|
assert response["aliases"] == ["https://sub.example.com/users/#{user.nickname}"]
|
|
|
|
|
|
|
|
on_exit(fn ->
|
|
|
|
Pleroma.Web.Endpoint.config_change(
|
|
|
|
[{Pleroma.Web.Endpoint, url: [host: "localhost"]}],
|
|
|
|
[]
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2019-07-24 09:13:10 -06: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 08:17:44 -07:00
|
|
|
test "Webfinger XML" do
|
2020-08-07 15:48:03 -06:00
|
|
|
user =
|
|
|
|
insert(:user,
|
|
|
|
ap_id: "https://hyrule.world/users/zelda",
|
|
|
|
also_known_as: ["https://mushroom.kingdom/users/toad"]
|
|
|
|
)
|
2018-12-15 08:17:44 -07:00
|
|
|
|
|
|
|
response =
|
|
|
|
build_conn()
|
2018-12-15 09:34:37 -07:00
|
|
|
|> put_req_header("accept", "application/xrd+xml")
|
2018-12-15 08:17:44 -07:00
|
|
|
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
|
2020-08-07 15:48:03 -06:00
|
|
|
|> response(200)
|
2018-12-15 08:17:44 -07:00
|
|
|
|
2020-08-07 15:48:03 -06:00
|
|
|
assert response =~ "<Alias>https://hyrule.world/users/zelda</Alias>"
|
2018-12-15 08:17:44 -07:00
|
|
|
end
|
2018-12-15 09:34:37 -07:00
|
|
|
|
2019-07-24 09:13:10 -06: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 09:46:41 -06: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 09:13:10 -06:00
|
|
|
end
|
|
|
|
|
2018-12-15 09:34:37 -07: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 08:17:44 -07:00
|
|
|
end
|