akkoma/test/pleroma/web/plugs/ensure_http_signature_plug_test.exs
FloatingGhost 98cb255d12 Support elixir1.15
OTP builds to 1.15

Changelog entry

Ensure policies are fully loaded

Fix :warn

use main branch for linkify

Fix warn in tests

Migrations for phoenix 1.17

Revert "Migrations for phoenix 1.17"

This reverts commit 6a3b2f15b7.

Oban upgrade

Add default empty whitelist

mix format

limit test to amd64

OTP 26 tests for 1.15

use OTP_VERSION tag

baka

just 1.15

Massive deps update

Update locale, deps

Mix format

shell????

multiline???

?

max cases 1

use assert_recieve

don't put_env in async tests

don't async conn/fs tests

mix format

FIx some uploader issues

Fix tests
2023-08-03 17:44:09 +01:00

68 lines
1.9 KiB
Elixir

# Akkoma: Magically expressive social media
# Copyright © 2022-2022 Akkoma Authors <https://akkoma.dev/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.EnsureHTTPSignaturePlugTest do
use Pleroma.Web.ConnCase, async: false
alias Pleroma.Web.Plugs.EnsureHTTPSignaturePlug
import Plug.Conn
import Phoenix.Controller, only: [put_format: 2]
import Pleroma.Tests.Helpers, only: [clear_config: 2]
describe "requires a signature when `authorized_fetch_mode` is enabled" do
setup do
clear_config([:activitypub, :authorized_fetch_mode], true)
conn =
build_conn(:get, "/doesntmatter")
|> put_format("activity+json")
[conn: conn]
end
test "and signature has been set as invalid", %{conn: conn} do
conn =
conn
|> assign(:valid_signature, false)
|> EnsureHTTPSignaturePlug.call(%{})
assert conn.halted == true
assert conn.status == 401
assert conn.state == :sent
assert conn.resp_body == "Request not signed"
end
test "and signature has been set as valid", %{conn: conn} do
conn =
conn
|> assign(:valid_signature, true)
|> EnsureHTTPSignaturePlug.call(%{})
assert conn.halted == false
end
test "does nothing for non-ActivityPub content types", %{conn: conn} do
conn =
conn
|> assign(:valid_signature, false)
|> put_format("html")
|> EnsureHTTPSignaturePlug.call(%{})
assert conn.halted == false
end
end
test "does nothing on invalid signature when `authorized_fetch_mode` is disabled" do
clear_config([:activitypub, :authorized_fetch_mode], false)
conn =
build_conn(:get, "/doesntmatter")
|> put_format("activity+json")
|> assign(:valid_signature, false)
|> EnsureHTTPSignaturePlug.call(%{})
assert conn.halted == false
end
end