test_webserver/test/security_test.rb

62 lines
1.6 KiB
Ruby
Raw Permalink Normal View History

2016-04-28 18:11:22 +02:00
require 'test_helper'
require 'mechanize'
class SecurityTest < Minitest::Test
include WebserverHelper
2017-02-01 23:32:41 +01:00
include SSLHelper
def domain
"ssl.evolix.net".freeze
end
2016-04-28 18:11:22 +02:00
def test_certificate_level
level = "intermediate"
2017-02-01 23:32:41 +01:00
command = analyze_cmd(domain: domain, level: level)
output = `#{command}`
2016-04-28 18:11:22 +02:00
assert_match %r|has intermediate ssl/tls\nand complies with the '#{level}' level|, output, "Expected to comply with #{level} level :\n#{output.inspect}"
refute_match %r|consider enabling OCSP Stapling|, output, 'Expected to have OCSP stapling enabled'
end
def test_certificate
2017-02-01 23:32:41 +01:00
options = {
domain: "ssl.evolix.net",
issuer: %Q("Let's Encrypt Authority X3"),
cn: "ssl.evolix.net",
}
command = check_ssl_cert_cmd(options)
output = `#{command}`
2016-04-28 18:11:22 +02:00
2016-04-28 22:58:19 +02:00
assert_match(/\ASSL_CERT OK/, output, output)
2016-04-28 18:11:22 +02:00
end
def test_accepts_tls_v1
2017-02-01 23:32:41 +01:00
command = openssl_verify_cmd(domain, "-tls1")
output = `#{command}`
2016-04-28 18:11:22 +02:00
2016-04-28 22:58:19 +02:00
assert_match(/Verify return code: 0 \(ok\)/, output, "Expected to accept TLSv1")
2016-04-28 18:11:22 +02:00
end
def test_refuse_ssl_v3
2017-02-01 23:32:41 +01:00
command = openssl_verify_cmd(domain, "-ssl3")
output = `#{command}`
2016-04-28 18:11:22 +02:00
2016-04-28 22:58:19 +02:00
assert_match(/sslv3 alert handshake failure/, output, "Expected to refuse SSLv3")
2016-04-28 18:11:22 +02:00
end
def test_hsts_header
agent = Mechanize.new { |a|
2017-02-01 23:32:41 +01:00
a.follow_redirect = true
2016-04-28 18:11:22 +02:00
}
2017-02-01 23:32:41 +01:00
url = "https://#{domain}/"
page = agent.get(url)
context = "for #{url}"
assert_status_ok page, context
assert_has_hsts page, context
assert_hsts_max_age "315360000", page, context
refute_hsts_include_subdomains page, context
2016-04-28 18:11:22 +02:00
end
end