add test for frontend URL
This commit is contained in:
parent
730d6dd49b
commit
09b6380cdf
2 changed files with 58 additions and 9 deletions
|
@ -2409,7 +2409,10 @@ defp maybe_validate_rel_me_field(changeset, %User{ap_id: _ap_id} = struct) do
|
|||
defp maybe_validate_rel_me_field(changeset, _), do: changeset
|
||||
|
||||
@spec validate_rel_me_field(Changeset.t(), [Map.t()], [Map.t()], User.t()) :: Changeset.t()
|
||||
defp validate_rel_me_field(changeset, fields, raw_fields, %User{ap_id: ap_id}) do
|
||||
defp validate_rel_me_field(changeset, fields, raw_fields, %User{
|
||||
nickname: nickname,
|
||||
ap_id: ap_id
|
||||
}) do
|
||||
fields =
|
||||
fields
|
||||
|> Enum.with_index()
|
||||
|
@ -2417,7 +2420,16 @@ defp validate_rel_me_field(changeset, fields, raw_fields, %User{ap_id: ap_id}) d
|
|||
raw_value = Enum.at(raw_fields, index)["value"]
|
||||
|
||||
if is_url(raw_value) do
|
||||
with "me" <- RelMe.maybe_put_rel_me(raw_value, [ap_id]) do
|
||||
frontend_url =
|
||||
Pleroma.Web.Router.Helpers.redirect_url(
|
||||
Pleroma.Web.Endpoint,
|
||||
:redirector_with_meta,
|
||||
nickname
|
||||
)
|
||||
|
||||
possible_urls = [ap_id, frontend_url]
|
||||
|
||||
with "me" <- RelMe.maybe_put_rel_me(raw_value, possible_urls) do
|
||||
%{
|
||||
"name" => name,
|
||||
"value" => value,
|
||||
|
|
|
@ -465,7 +465,7 @@ test "update fields", %{conn: conn} do
|
|||
]
|
||||
end
|
||||
|
||||
test "update fields with a link to content with rel=me", %{user: user, conn: conn} do
|
||||
test "update fields with a link to content with rel=me, with ap id", %{user: user, conn: conn} do
|
||||
Tesla.Mock.mock(fn
|
||||
%{url: "http://example.com/rel_me/ap_id"} ->
|
||||
%Tesla.Env{
|
||||
|
@ -481,12 +481,49 @@ test "update fields with a link to content with rel=me", %{user: user, conn: con
|
|||
|> patch("/api/v1/accounts/update_credentials", %{fields_attributes: [field]})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{
|
||||
"name" => "Website",
|
||||
"value" =>
|
||||
~s[<a href="http://example.com/rel_me/ap_id" rel="ugc">http://example.com/rel_me/ap_id</a>],
|
||||
"verified_at" => verified_at
|
||||
}] = account_data["fields"]
|
||||
assert [
|
||||
%{
|
||||
"name" => "Website",
|
||||
"value" =>
|
||||
~s[<a href="http://example.com/rel_me/ap_id" rel="ugc">http://example.com/rel_me/ap_id</a>],
|
||||
"verified_at" => verified_at
|
||||
}
|
||||
] = account_data["fields"]
|
||||
|
||||
{:ok, verified_at, _} = DateTime.from_iso8601(verified_at)
|
||||
assert DateTime.diff(DateTime.utc_now(), verified_at) < 10
|
||||
end
|
||||
|
||||
test "update fields with a link to content with rel=me, with frontend path", %{
|
||||
user: user,
|
||||
conn: conn
|
||||
} do
|
||||
fe_url = "#{Pleroma.Web.Endpoint.url()}/#{user.nickname}"
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{url: "http://example.com/rel_me/fe_path"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: ~s[<html><head><link rel="me" href="#{fe_url}"></head></html>]
|
||||
}
|
||||
end)
|
||||
|
||||
field = %{name: "Website", value: "http://example.com/rel_me/fe_path"}
|
||||
|
||||
account_data =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{fields_attributes: [field]})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [
|
||||
%{
|
||||
"name" => "Website",
|
||||
"value" =>
|
||||
~s[<a href="http://example.com/rel_me/fe_path" rel="ugc">http://example.com/rel_me/fe_path</a>],
|
||||
"verified_at" => verified_at
|
||||
}
|
||||
] = account_data["fields"]
|
||||
|
||||
{:ok, verified_at, _} = DateTime.from_iso8601(verified_at)
|
||||
assert DateTime.diff(DateTime.utc_now(), verified_at) < 10
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue