1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Plugs.MappedSignatureToIdentityPlugTest do
6 use Pleroma.Web.ConnCase
7 alias Pleroma.Web.Plugs.MappedSignatureToIdentityPlug
13 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
17 defp set_signature(conn, key_id) do
19 |> put_req_header("signature", "keyId=\"#{key_id}\"")
20 |> assign(:valid_signature, true)
23 test "it successfully maps a valid identity with a valid signature" do
25 build_conn(:get, "/doesntmattter")
26 |> set_signature("http://mastodon.example.org/users/admin")
27 |> MappedSignatureToIdentityPlug.call(%{})
29 refute is_nil(conn.assigns.user)
32 test "it successfully maps a valid identity with a valid signature with payload" do
34 build_conn(:post, "/doesntmattter", %{"actor" => "http://mastodon.example.org/users/admin"})
35 |> set_signature("http://mastodon.example.org/users/admin")
36 |> MappedSignatureToIdentityPlug.call(%{})
38 refute is_nil(conn.assigns.user)
41 test "it considers a mapped identity to be invalid when it mismatches a payload" do
43 build_conn(:post, "/doesntmattter", %{"actor" => "http://mastodon.example.org/users/admin"})
44 |> set_signature("https://niu.moe/users/rye")
45 |> MappedSignatureToIdentityPlug.call(%{})
47 assert %{valid_signature: false} == conn.assigns
50 @tag skip: "known breakage; the testsuite presently depends on it"
51 test "it considers a mapped identity to be invalid when the identity cannot be found" do
53 build_conn(:post, "/doesntmattter", %{"actor" => "http://mastodon.example.org/users/admin"})
54 |> set_signature("http://niu.moe/users/rye")
55 |> MappedSignatureToIdentityPlug.call(%{})
57 assert %{valid_signature: false} == conn.assigns