Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F21968560
digest_plug_test.exs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
digest_plug_test.exs
View Options
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
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
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 28, 3:25 AM (13 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
814956
Default Alt Text
digest_plug_test.exs (1 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment