Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

http_signature_plug_test.exs 1.3KB

6 년 전
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do
  2. use Pleroma.Web.ConnCase
  3. alias Pleroma.Web.HTTPSignatures
  4. alias Pleroma.Web.Plugs.HTTPSignaturePlug
  5. import Plug.Conn
  6. import Mock
  7. test "it call HTTPSignatures to check validity if the actor sighed it" do
  8. params = %{"actor" => "http://mastodon.example.org/users/admin"}
  9. conn = build_conn(:get, "/doesntmattter", params)
  10. with_mock HTTPSignatures, validate_conn: fn _ -> true end do
  11. conn =
  12. conn
  13. |> put_req_header(
  14. "signature",
  15. "keyId=\"http://mastodon.example.org/users/admin#main-key"
  16. )
  17. |> HTTPSignaturePlug.call(%{})
  18. assert conn.assigns.valid_signature == true
  19. assert called(HTTPSignatures.validate_conn(:_))
  20. end
  21. end
  22. test "bails out early if the signature isn't by the activity actor" do
  23. params = %{"actor" => "https://mst3k.interlinked.me/users/luciferMysticus"}
  24. conn = build_conn(:get, "/doesntmattter", params)
  25. with_mock HTTPSignatures, validate_conn: fn _ -> false end do
  26. conn =
  27. conn
  28. |> put_req_header(
  29. "signature",
  30. "keyId=\"http://mastodon.example.org/users/admin#main-key"
  31. )
  32. |> HTTPSignaturePlug.call(%{})
  33. assert conn.assigns.valid_signature == false
  34. refute called(HTTPSignatures.validate_conn(:_))
  35. end
  36. end
  37. end