add test for route aliases
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful

This commit is contained in:
FloatingGhost 2022-08-05 15:44:00 +01:00
parent 4a94bf54a6
commit e4c7828b74
2 changed files with 12 additions and 2 deletions

View file

@ -27,7 +27,7 @@ def call(conn, _opts) do
end
end
defp route_aliases(%{path_info: ["objects", id]} = conn) do
def route_aliases(%{path_info: ["objects", id]} = conn) do
ap_id = Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :object, id)
with %Activity{} = activity <- Activity.get_by_object_ap_id_with_object(ap_id) do
@ -37,7 +37,7 @@ defp route_aliases(%{path_info: ["objects", id]} = conn) do
end
end
defp route_aliases(_), do: []
def route_aliases(_), do: []
defp assign_valid_signature_on_route_aliases(conn, []), do: conn

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
alias Pleroma.Web.Plugs.HTTPSignaturePlug
import Plug.Conn
@ -81,5 +82,14 @@ test "halts the connection when `signature` header is not present", %{conn: conn
assert conn.state == :sent
assert conn.resp_body == "Request not signed"
end
test "aliases redirected /object endpoints", _ do
obj = insert(:note)
act = insert(:note_activity, note: obj)
params = %{"actor" => "http://mastodon.example.org/users/admin"}
path = URI.parse(obj.data["id"]).path
conn = build_conn(:get, path, params)
assert ["/notice/#{act.id}"] == HTTPSignaturePlug.route_aliases(conn)
end
end
end