Fix merge conflicts with upstream
[akkoma] / test / pleroma / web / plugs / digest_plug_test.exs
1 defmodule Pleroma.Web.Plugs.DigestPlugTest do
2 use ExUnit.Case, async: true
3 use Plug.Test
4
5 test "digest algorithm is taken from digest header" do
6 body = "{\"hello\": \"world\"}"
7 digest = "X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE="
8
9 {:ok, ^body, conn} =
10 :get
11 |> conn("/", body)
12 |> put_req_header("content-type", "application/json")
13 |> put_req_header("digest", "sha-256=" <> digest)
14 |> Pleroma.Web.Plugs.DigestPlug.read_body([])
15
16 assert conn.assigns[:digest] == "sha-256=" <> digest
17
18 {:ok, ^body, conn} =
19 :get
20 |> conn("/", body)
21 |> put_req_header("content-type", "application/json")
22 |> put_req_header("digest", "SHA-256=" <> digest)
23 |> Pleroma.Web.Plugs.DigestPlug.read_body([])
24
25 assert conn.assigns[:digest] == "SHA-256=" <> digest
26 end
27
28 test "error if digest algorithm is invalid" do
29 body = "{\"hello\": \"world\"}"
30 digest = "X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE="
31
32 assert_raise ArgumentError, "invalid value for digest algorithm, got: MD5", fn ->
33 :get
34 |> conn("/", body)
35 |> put_req_header("content-type", "application/json")
36 |> put_req_header("digest", "MD5=" <> digest)
37 |> Pleroma.Web.Plugs.DigestPlug.read_body([])
38 end
39
40 assert_raise ArgumentError, "invalid value for digest algorithm, got: md5", fn ->
41 :get
42 |> conn("/", body)
43 |> put_req_header("content-type", "application/json")
44 |> put_req_header("digest", "md5=" <> digest)
45 |> Pleroma.Web.Plugs.DigestPlug.read_body([])
46 end
47 end
48 end