Add specific tests for Webfinger aliases / also_known_as
Also reorganize similar tests to be grouped together
This commit is contained in:
parent
122ad4603a
commit
736686b4e2
1 changed files with 108 additions and 57 deletions
|
|
@ -33,28 +33,46 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
||||||
assert match?(^response_xml, expected_xml)
|
assert match?(^response_xml, expected_xml)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "Webfinger JRD" do
|
describe "Webfinger" do
|
||||||
clear_config([Pleroma.Web.Endpoint, :url, :host], "hyrule.world")
|
test "JRD" do
|
||||||
clear_config([Pleroma.Web.WebFinger, :domain], "hyrule.world")
|
clear_config([Pleroma.Web.Endpoint, :url, :host], "hyrule.world")
|
||||||
|
clear_config([Pleroma.Web.WebFinger, :domain], "hyrule.world")
|
||||||
|
|
||||||
user =
|
user =
|
||||||
insert(:user,
|
insert(:user,
|
||||||
ap_id: "https://hyrule.world/users/zelda",
|
ap_id: "https://hyrule.world/users/zelda"
|
||||||
also_known_as: ["https://mushroom.kingdom/users/toad"]
|
)
|
||||||
)
|
|
||||||
|
|
||||||
response =
|
response =
|
||||||
build_conn()
|
build_conn()
|
||||||
|> put_req_header("accept", "application/jrd+json")
|
|> put_req_header("accept", "application/jrd+json")
|
||||||
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@hyrule.world")
|
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@hyrule.world")
|
||||||
|> json_response(200)
|
|> json_response(200)
|
||||||
|
|
||||||
assert response["subject"] == "acct:#{user.nickname}@hyrule.world"
|
assert response["subject"] == "acct:#{user.nickname}@hyrule.world"
|
||||||
|
|
||||||
assert response["aliases"] == [
|
assert response["aliases"] == [
|
||||||
"https://hyrule.world/users/zelda",
|
"https://hyrule.world/users/zelda"
|
||||||
"https://mushroom.kingdom/users/toad"
|
]
|
||||||
]
|
end
|
||||||
|
|
||||||
|
test "XML" do
|
||||||
|
clear_config([Pleroma.Web.Endpoint, :url, :host], "hyrule.world")
|
||||||
|
clear_config([Pleroma.Web.WebFinger, :domain], "hyrule.world")
|
||||||
|
|
||||||
|
user =
|
||||||
|
insert(:user,
|
||||||
|
ap_id: "https://hyrule.world/users/zelda"
|
||||||
|
)
|
||||||
|
|
||||||
|
response =
|
||||||
|
build_conn()
|
||||||
|
|> put_req_header("accept", "application/xrd+xml")
|
||||||
|
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
|
||||||
|
|> response(200)
|
||||||
|
|
||||||
|
assert response =~ "<Alias>https://hyrule.world/users/zelda</Alias>"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "Webfinger defaults to JSON when no Accept header is provided" do
|
test "Webfinger defaults to JSON when no Accept header is provided" do
|
||||||
|
|
@ -63,8 +81,7 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
||||||
|
|
||||||
user =
|
user =
|
||||||
insert(:user,
|
insert(:user,
|
||||||
ap_id: "https://hyrule.world/users/zelda",
|
ap_id: "https://hyrule.world/users/zelda"
|
||||||
also_known_as: ["https://mushroom.kingdom/users/toad"]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
response =
|
response =
|
||||||
|
|
@ -75,11 +92,63 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
||||||
assert response["subject"] == "acct:#{user.nickname}@hyrule.world"
|
assert response["subject"] == "acct:#{user.nickname}@hyrule.world"
|
||||||
|
|
||||||
assert response["aliases"] == [
|
assert response["aliases"] == [
|
||||||
"https://hyrule.world/users/zelda",
|
"https://hyrule.world/users/zelda"
|
||||||
"https://mushroom.kingdom/users/toad"
|
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "Webfinger returns also_known_as / aliases in the response" do
|
||||||
|
test "JSON" do
|
||||||
|
clear_config([Pleroma.Web.Endpoint, :url, :host], "hyrule.world")
|
||||||
|
clear_config([Pleroma.Web.WebFinger, :domain], "hyrule.world")
|
||||||
|
|
||||||
|
user =
|
||||||
|
insert(:user,
|
||||||
|
ap_id: "https://hyrule.world/users/zelda",
|
||||||
|
also_known_as: [
|
||||||
|
"https://mushroom.kingdom/users/toad",
|
||||||
|
"https://luigi.mansion/users/kingboo"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
response =
|
||||||
|
build_conn()
|
||||||
|
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@hyrule.world")
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
|
assert response["subject"] == "acct:#{user.nickname}@hyrule.world"
|
||||||
|
|
||||||
|
assert response["aliases"] == [
|
||||||
|
"https://hyrule.world/users/zelda",
|
||||||
|
"https://mushroom.kingdom/users/toad",
|
||||||
|
"https://luigi.mansion/users/kingboo"
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "XML" do
|
||||||
|
clear_config([Pleroma.Web.Endpoint, :url, :host], "hyrule.world")
|
||||||
|
clear_config([Pleroma.Web.WebFinger, :domain], "hyrule.world")
|
||||||
|
|
||||||
|
user =
|
||||||
|
insert(:user,
|
||||||
|
ap_id: "https://hyrule.world/users/zelda",
|
||||||
|
also_known_as: [
|
||||||
|
"https://mushroom.kingdom/users/toad",
|
||||||
|
"https://luigi.mansion/users/kingboo"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
response =
|
||||||
|
build_conn()
|
||||||
|
|> put_req_header("accept", "application/xrd+xml")
|
||||||
|
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
|
||||||
|
|> response(200)
|
||||||
|
|
||||||
|
assert response =~ "<Alias>https://hyrule.world/users/zelda</Alias>"
|
||||||
|
assert response =~ "<Alias>https://mushroom.kingdom/users/toad</Alias>"
|
||||||
|
assert response =~ "<Alias>https://luigi.mansion/users/kingboo</Alias>"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "reach user on tld, while pleroma is running on subdomain" do
|
test "reach user on tld, while pleroma is running on subdomain" do
|
||||||
clear_config([Pleroma.Web.Endpoint, :url, :host], "sub.example.com")
|
clear_config([Pleroma.Web.Endpoint, :url, :host], "sub.example.com")
|
||||||
|
|
||||||
|
|
@ -97,44 +166,26 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
||||||
assert response["aliases"] == ["https://sub.example.com/users/#{user.nickname}"]
|
assert response["aliases"] == ["https://sub.example.com/users/#{user.nickname}"]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns 404 when user isn't found (JSON)" do
|
describe "it returns 404 when user isn't found" do
|
||||||
result =
|
test "JSON" do
|
||||||
build_conn()
|
result =
|
||||||
|> put_req_header("accept", "application/jrd+json")
|
build_conn()
|
||||||
|> get("/.well-known/webfinger?resource=acct:jimm@localhost")
|
|> put_req_header("accept", "application/jrd+json")
|
||||||
|> json_response(404)
|
|> get("/.well-known/webfinger?resource=acct:jimm@localhost")
|
||||||
|
|> json_response(404)
|
||||||
|
|
||||||
assert result == "Couldn't find user"
|
assert result == "Couldn't find user"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "Webfinger XML" do
|
test "XML" do
|
||||||
clear_config([Pleroma.Web.Endpoint, :url, :host], "hyrule.world")
|
result =
|
||||||
clear_config([Pleroma.Web.WebFinger, :domain], "hyrule.world")
|
build_conn()
|
||||||
|
|> put_req_header("accept", "application/xrd+xml")
|
||||||
|
|> get("/.well-known/webfinger?resource=acct:jimm@localhost")
|
||||||
|
|> response(404)
|
||||||
|
|
||||||
user =
|
assert result == "Couldn't find user"
|
||||||
insert(:user,
|
end
|
||||||
ap_id: "https://hyrule.world/users/zelda",
|
|
||||||
also_known_as: ["https://mushroom.kingdom/users/toad"]
|
|
||||||
)
|
|
||||||
|
|
||||||
response =
|
|
||||||
build_conn()
|
|
||||||
|> put_req_header("accept", "application/xrd+xml")
|
|
||||||
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
|
|
||||||
|> response(200)
|
|
||||||
|
|
||||||
assert response =~ "<Alias>https://hyrule.world/users/zelda</Alias>"
|
|
||||||
assert response =~ "<Alias>https://mushroom.kingdom/users/toad</Alias>"
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
end
|
||||||
|
|
||||||
test "Returns JSON when format is not supported" do
|
test "Returns JSON when format is not supported" do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue