Update http-signatures dep, allow created header #800
2 changed files with 22 additions and 3 deletions
|
@ -54,6 +54,16 @@ def maybe_put_created_psudoheader(conn) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def maybe_put_expires_psudoheader(conn) do
|
||||||
|
case HTTPSignatures.signature_for_conn(conn) do
|
||||||
|
%{"expires" => expires} ->
|
||||||
|
put_req_header(conn, "(expires)", expires)
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
conn
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp assign_valid_signature_on_route_aliases(conn, []), do: conn
|
defp assign_valid_signature_on_route_aliases(conn, []), do: conn
|
||||||
|
|
||||||
defp assign_valid_signature_on_route_aliases(%{assigns: %{valid_signature: true}} = conn, _),
|
defp assign_valid_signature_on_route_aliases(%{assigns: %{valid_signature: true}} = conn, _),
|
||||||
|
@ -66,6 +76,7 @@ defp assign_valid_signature_on_route_aliases(conn, [path | rest]) do
|
||||||
conn
|
conn
|
||||||
|> put_req_header("(request-target)", request_target)
|
|> put_req_header("(request-target)", request_target)
|
||||||
|> maybe_put_created_psudoheader()
|
|> maybe_put_created_psudoheader()
|
||||||
|
|> maybe_put_expires_psudoheader()
|
||||||
|> case do
|
|> case do
|
||||||
%{assigns: %{digest: digest}} = conn -> put_req_header(conn, "digest", digest)
|
%{assigns: %{digest: digest}} = conn -> put_req_header(conn, "digest", digest)
|
||||||
conn -> conn
|
conn -> conn
|
||||||
|
|
|
@ -19,9 +19,10 @@ defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do
|
||||||
[
|
[
|
||||||
signature_for_conn: fn _ ->
|
signature_for_conn: fn _ ->
|
||||||
%{
|
%{
|
||||||
"keyId" => "http://mastodon.example.org/users/admin#main-key",
|
"keyId" => "http://mastodon.example.org/users/admin#main-key",
|
||||||
"created" => "1234567890",
|
"created" => "1234567890",
|
||||||
}
|
"expires" => "1234567890"
|
||||||
|
}
|
||||||
end,
|
end,
|
||||||
validate_conn: fn conn ->
|
validate_conn: fn conn ->
|
||||||
Map.get(conn.assigns, :valid_signature, true)
|
Map.get(conn.assigns, :valid_signature, true)
|
||||||
|
@ -151,4 +152,11 @@ test "(created) psudoheader", _ do
|
||||||
created_header = List.keyfind(conn.req_headers, "(created)", 0)
|
created_header = List.keyfind(conn.req_headers, "(created)", 0)
|
||||||
assert {_, "1234567890"} = created_header
|
assert {_, "1234567890"} = created_header
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "(expires) psudoheader", _ do
|
||||||
|
conn = build_conn(:get, "/doesntmattter")
|
||||||
|
conn = HTTPSignaturePlug.maybe_put_expires_psudoheader(conn)
|
||||||
|
expires_header = List.keyfind(conn.req_headers, "(expires)", 0)
|
||||||
|
assert {_, "1234567890"} = expires_header
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue