diff options
author | lain <lain@soykaf.club> | 2020-11-27 11:51:24 +0000 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-11-27 11:51:24 +0000 |
commit | 14a2c1da13a855d2daa1fa19a59964496d271950 (patch) | |
tree | 3128cb73856eedd32b5bed1b21a3e1a7c8406434 /test | |
parent | bb522bcc44463d258672f35979a2c939e7199e55 (diff) | |
parent | 6aadb1cb409a80632d17bba487cfabfdb0b13d34 (diff) | |
download | pleroma-14a2c1da13a855d2daa1fa19a59964496d271950.tar.gz |
Merge branch 'fix/2322-digest-algorithm-case-insensitive' into 'develop'
Digest algorithm is taken from header
Closes #2322
See merge request pleroma/pleroma!3176
Diffstat (limited to 'test')
-rw-r--r-- | test/pleroma/web/plugs/digest_plug_test.exs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/pleroma/web/plugs/digest_plug_test.exs b/test/pleroma/web/plugs/digest_plug_test.exs new file mode 100644 index 000000000..629c28c93 --- /dev/null +++ b/test/pleroma/web/plugs/digest_plug_test.exs @@ -0,0 +1,48 @@ +defmodule Pleroma.Web.Plugs.DigestPlugTest do + use ExUnit.Case, async: true + use Plug.Test + + test "digest algorithm is taken from digest header" do + body = "{\"hello\": \"world\"}" + digest = "X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=" + + {:ok, ^body, conn} = + :get + |> conn("/", body) + |> put_req_header("content-type", "application/json") + |> put_req_header("digest", "sha-256=" <> digest) + |> Pleroma.Web.Plugs.DigestPlug.read_body([]) + + assert conn.assigns[:digest] == "sha-256=" <> digest + + {:ok, ^body, conn} = + :get + |> conn("/", body) + |> put_req_header("content-type", "application/json") + |> put_req_header("digest", "SHA-256=" <> digest) + |> Pleroma.Web.Plugs.DigestPlug.read_body([]) + + assert conn.assigns[:digest] == "SHA-256=" <> digest + end + + test "error if digest algorithm is invalid" do + body = "{\"hello\": \"world\"}" + digest = "X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=" + + assert_raise ArgumentError, "invalid value for digest algorithm, got: MD5", fn -> + :get + |> conn("/", body) + |> put_req_header("content-type", "application/json") + |> put_req_header("digest", "MD5=" <> digest) + |> Pleroma.Web.Plugs.DigestPlug.read_body([]) + end + + assert_raise ArgumentError, "invalid value for digest algorithm, got: md5", fn -> + :get + |> conn("/", body) + |> put_req_header("content-type", "application/json") + |> put_req_header("digest", "md5=" <> digest) + |> Pleroma.Web.Plugs.DigestPlug.read_body([]) + end + end +end |