1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Plugs.DigestPlugTest do
6 use ExUnit.Case, async: true
9 test "digest algorithm is taken from digest header" do
10 body = "{\"hello\": \"world\"}"
11 digest = "X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE="
16 |> put_req_header("content-type", "application/json")
17 |> put_req_header("digest", "sha-256=" <> digest)
18 |> Pleroma.Web.Plugs.DigestPlug.read_body([])
20 assert conn.assigns[:digest] == "sha-256=" <> digest
25 |> put_req_header("content-type", "application/json")
26 |> put_req_header("digest", "SHA-256=" <> digest)
27 |> Pleroma.Web.Plugs.DigestPlug.read_body([])
29 assert conn.assigns[:digest] == "SHA-256=" <> digest
32 test "error if digest algorithm is invalid" do
33 body = "{\"hello\": \"world\"}"
34 digest = "X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE="
36 assert_raise ArgumentError, "invalid value for digest algorithm, got: MD5", fn ->
39 |> put_req_header("content-type", "application/json")
40 |> put_req_header("digest", "MD5=" <> digest)
41 |> Pleroma.Web.Plugs.DigestPlug.read_body([])
44 assert_raise ArgumentError, "invalid value for digest algorithm, got: md5", fn ->
47 |> put_req_header("content-type", "application/json")
48 |> put_req_header("digest", "md5=" <> digest)
49 |> Pleroma.Web.Plugs.DigestPlug.read_body([])