feat: Enable HSTS by default

This enables the HSTS header by default when an SSL certificate is in use. HSTS options can also be managed via the nginx:set command, which also exposes the ability to disable HSTS for your application.
This commit is contained in:
Jose Diaz-Gonzalez
2020-02-01 21:16:39 -05:00
parent d42fb02136
commit 73e7ff7b18
8 changed files with 151 additions and 8 deletions

View File

@@ -107,6 +107,88 @@ assert_error_log() {
assert_failure
}
@test "(nginx-vhosts) nginx:set hsts" {
local HSTS_CONF="/home/dokku/${TEST_APP}/nginx.conf.d/hsts.conf"
run deploy_app
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "Enabling HSTS"
run /bin/bash -c "test -f $HSTS_CONF"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "cat $HSTS_CONF | grep includeSubdomains"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "cat $HSTS_CONF | grep 'max-age=15724800'"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "cat $HSTS_CONF | grep preload"
echo "output: $output"
echo "status: $status"
assert_failure
run /bin/bash -c "dokku nginx:set $TEST_APP hsts-include-subdomains false"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku nginx:build-config $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "cat $HSTS_CONF | grep includeSubdomains"
echo "output: $output"
echo "status: $status"
assert_failure
run /bin/bash -c "dokku nginx:set $TEST_APP hsts-max-age 120"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku nginx:build-config $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "cat $HSTS_CONF | grep 'max-age=120'"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku nginx:set $TEST_APP hsts-preload true"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku nginx:build-config $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "cat $HSTS_CONF | grep preload"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku nginx:set $TEST_APP hsts false"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku nginx:build-config $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "Enabling HSTS" 0
run /bin/bash -c "test -f $DOKKU_ROOT/$TEST_APP/nginx.conf.d/hsts.conf"
echo "output: $output"
echo "status: $status"
assert_failure
}
@test "(nginx-vhosts) nginx:set bind-address" {
run deploy_app
echo "output: $output"