Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

45 líneas
1.3KB

  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