mirror of
https://framagit.org/framasoft/mobilizon.git
synced 2024-12-28 02:40:22 +00:00
f2175c6498
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
52 lines
1.7 KiB
Elixir
52 lines
1.7 KiB
Elixir
defmodule Mobilizon.Web.Plugs.HTTPSignaturesTest do
|
|
use Mobilizon.Web.ConnCase
|
|
import Mock
|
|
|
|
alias Mobilizon.Federation.HTTPSignatures.Signature
|
|
alias Mobilizon.Web.Plugs.HTTPSignatures, as: HTTPSignaturesPlug
|
|
|
|
test "tests that date window is acceptable" do
|
|
date = NaiveDateTime.utc_now() |> Timex.shift(hours: -3) |> Signature.generate_date_header()
|
|
|
|
with_mock HTTPSignatures, validate_conn: fn _ -> true end do
|
|
conn =
|
|
build_conn()
|
|
|> put_req_header("signature", "signature")
|
|
|> put_req_header("date", date)
|
|
|> HTTPSignaturesPlug.call(%{})
|
|
|
|
assert called(HTTPSignatures.validate_conn(:_))
|
|
assert conn.assigns.valid_signature
|
|
end
|
|
end
|
|
|
|
test "tests that date window is not acceptable (already passed)" do
|
|
date = NaiveDateTime.utc_now() |> Timex.shift(hours: -30) |> Signature.generate_date_header()
|
|
|
|
with_mock HTTPSignatures, validate_conn: fn _ -> true end do
|
|
conn =
|
|
build_conn()
|
|
|> put_req_header("signature", "signature")
|
|
|> put_req_header("date", date)
|
|
|> HTTPSignaturesPlug.call(%{})
|
|
|
|
refute conn.assigns.valid_signature
|
|
assert called(HTTPSignatures.validate_conn(:_))
|
|
end
|
|
end
|
|
|
|
test "tests that date window is not acceptable (in the future)" do
|
|
date = NaiveDateTime.utc_now() |> Timex.shift(hours: 30) |> Signature.generate_date_header()
|
|
|
|
with_mock HTTPSignatures, validate_conn: fn _ -> true end do
|
|
conn =
|
|
build_conn()
|
|
|> put_req_header("signature", "signature")
|
|
|> put_req_header("date", date)
|
|
|> HTTPSignaturesPlug.call(%{})
|
|
|
|
refute conn.assigns.valid_signature
|
|
assert called(HTTPSignatures.validate_conn(:_))
|
|
end
|
|
end
|
|
end
|