Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

49 lignes
1.5KB

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