Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F13523296
http_security_plug_test.exs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
http_security_plug_test.exs
View Options
# Pleroma: A lightweight social networking server
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma.Web.Plugs.HTTPSecurityPlugTest
do
use
Pleroma.Web.ConnCase
alias
Pleroma.Config
alias
Plug.Conn
test
"it sends CSP headers when enabled"
,
%{
conn
:
conn
}
do
Config
.
put
([
:http_security
,
:enabled
],
true
)
conn
=
conn
|>
get
(
"/api/v1/instance"
)
refute
Conn
.
get_resp_header
(
conn
,
"x-xss-protection"
)
==
[]
refute
Conn
.
get_resp_header
(
conn
,
"x-permitted-cross-domain-policies"
)
==
[]
refute
Conn
.
get_resp_header
(
conn
,
"x-frame-options"
)
==
[]
refute
Conn
.
get_resp_header
(
conn
,
"x-content-type-options"
)
==
[]
refute
Conn
.
get_resp_header
(
conn
,
"x-download-options"
)
==
[]
refute
Conn
.
get_resp_header
(
conn
,
"referrer-policy"
)
==
[]
refute
Conn
.
get_resp_header
(
conn
,
"content-security-policy"
)
==
[]
end
test
"it does not send CSP headers when disabled"
,
%{
conn
:
conn
}
do
Config
.
put
([
:http_security
,
:enabled
],
false
)
conn
=
conn
|>
get
(
"/api/v1/instance"
)
assert
Conn
.
get_resp_header
(
conn
,
"x-xss-protection"
)
==
[]
assert
Conn
.
get_resp_header
(
conn
,
"x-permitted-cross-domain-policies"
)
==
[]
assert
Conn
.
get_resp_header
(
conn
,
"x-frame-options"
)
==
[]
assert
Conn
.
get_resp_header
(
conn
,
"x-content-type-options"
)
==
[]
assert
Conn
.
get_resp_header
(
conn
,
"x-download-options"
)
==
[]
assert
Conn
.
get_resp_header
(
conn
,
"referrer-policy"
)
==
[]
assert
Conn
.
get_resp_header
(
conn
,
"content-security-policy"
)
==
[]
end
test
"it sends STS headers when enabled"
,
%{
conn
:
conn
}
do
Config
.
put
([
:http_security
,
:enabled
],
true
)
Config
.
put
([
:http_security
,
:sts
],
true
)
conn
=
conn
|>
get
(
"/api/v1/instance"
)
refute
Conn
.
get_resp_header
(
conn
,
"strict-transport-security"
)
==
[]
refute
Conn
.
get_resp_header
(
conn
,
"expect-ct"
)
==
[]
end
test
"it does not send STS headers when disabled"
,
%{
conn
:
conn
}
do
Config
.
put
([
:http_security
,
:enabled
],
true
)
Config
.
put
([
:http_security
,
:sts
],
false
)
conn
=
conn
|>
get
(
"/api/v1/instance"
)
assert
Conn
.
get_resp_header
(
conn
,
"strict-transport-security"
)
==
[]
assert
Conn
.
get_resp_header
(
conn
,
"expect-ct"
)
==
[]
end
test
"referrer-policy header reflects configured value"
,
%{
conn
:
conn
}
do
Config
.
put
([
:http_security
,
:enabled
],
true
)
conn
=
conn
|>
get
(
"/api/v1/instance"
)
assert
Conn
.
get_resp_header
(
conn
,
"referrer-policy"
)
==
[
"same-origin"
]
Config
.
put
([
:http_security
,
:referrer_policy
],
"no-referrer"
)
conn
=
build_conn
()
|>
get
(
"/api/v1/instance"
)
assert
Conn
.
get_resp_header
(
conn
,
"referrer-policy"
)
==
[
"no-referrer"
]
end
end
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 7, 9:37 PM (12 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
658663
Default Alt Text
http_security_plug_test.exs (2 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment