1 defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do
2 use Pleroma.Web.ConnCase
3 alias Pleroma.Web.HTTPSignatures
4 alias Pleroma.Web.Plugs.HTTPSignaturePlug
9 test "it call HTTPSignatures to check validity if the actor sighed it" do
10 params = %{"actor" => "http://mastodon.example.org/users/admin"}
11 conn = build_conn(:get, "/doesntmattter", params)
13 with_mock HTTPSignatures, validate_conn: fn _ -> true end do
18 "keyId=\"http://mastodon.example.org/users/admin#main-key"
20 |> HTTPSignaturePlug.call(%{})
22 assert conn.assigns.valid_signature == true
23 assert called(HTTPSignatures.validate_conn(:_))
27 test "bails out early if the signature isn't by the activity actor" do
28 params = %{"actor" => "https://mst3k.interlinked.me/users/luciferMysticus"}
29 conn = build_conn(:get, "/doesntmattter", params)
31 with_mock HTTPSignatures, validate_conn: fn _ -> false end do
36 "keyId=\"http://mastodon.example.org/users/admin#main-key"
38 |> HTTPSignaturePlug.call(%{})
40 assert conn.assigns.valid_signature == false
41 refute called(HTTPSignatures.validate_conn(:_))