1 defmodule Pleroma.Web.Plugs.DigestPlugTest do
2 use ExUnit.Case, async: true
5 test "digest algorithm is taken from digest header" do
6 body = "{\"hello\": \"world\"}"
7 digest = "X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE="
12 |> put_req_header("content-type", "application/json")
13 |> put_req_header("digest", "sha-256=" <> digest)
14 |> Pleroma.Web.Plugs.DigestPlug.read_body([])
16 assert conn.assigns[:digest] == "sha-256=" <> digest
21 |> put_req_header("content-type", "application/json")
22 |> put_req_header("digest", "SHA-256=" <> digest)
23 |> Pleroma.Web.Plugs.DigestPlug.read_body([])
25 assert conn.assigns[:digest] == "SHA-256=" <> digest
28 test "error if digest algorithm is invalid" do
29 body = "{\"hello\": \"world\"}"
30 digest = "X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE="
32 assert_raise ArgumentError, "invalid value for digest algorithm, got: MD5", fn ->
35 |> put_req_header("content-type", "application/json")
36 |> put_req_header("digest", "MD5=" <> digest)
37 |> Pleroma.Web.Plugs.DigestPlug.read_body([])
40 assert_raise ArgumentError, "invalid value for digest algorithm, got: md5", fn ->
43 |> put_req_header("content-type", "application/json")
44 |> put_req_header("digest", "md5=" <> digest)
45 |> Pleroma.Web.Plugs.DigestPlug.read_body([])