From de338c7309bb31244274b1e4f63b59f1f9b72c09 Mon Sep 17 00:00:00 2001 From: sagi Date: Mon, 9 Nov 2015 22:36:00 +0000 Subject: [PATCH] Add tests for Upgrade-Insecure-Requests --- .../tests/configurator_test.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/letsencrypt-apache/letsencrypt_apache/tests/configurator_test.py b/letsencrypt-apache/letsencrypt_apache/tests/configurator_test.py index aa224d1b6..4dd1350ac 100644 --- a/letsencrypt-apache/letsencrypt_apache/tests/configurator_test.py +++ b/letsencrypt-apache/letsencrypt_apache/tests/configurator_test.py @@ -545,6 +545,45 @@ class TwoVhost80Test(util.ApacheTest): self.config.enhance, "encryption-example.demo", "http-header", "Strict-Transport-Security") + @mock.patch("letsencrypt.le_util.run_script") + @mock.patch("letsencrypt.le_util.exe_exists") + def test_http_header_uir(self, mock_exe, _): + self.config.parser.update_runtime_variables = mock.Mock() + self.config.parser.modules.add("mod_ssl.c") + mock_exe.return_value = True + + # This will create an ssl vhost for letsencrypt.demo + self.config.enhance("letsencrypt.demo", "http-header", + "Upgrade-Insecure-Requests") + + self.assertTrue("headers_module" in self.config.parser.modules) + + # Get the ssl vhost for letsencrypt.demo + ssl_vhost = self.config.assoc["letsencrypt.demo"] + + # These are not immediately available in find_dir even with save() and + # load(). They must be found in sites-available + uir_header = self.config.parser.find_dir( + "Header", None, ssl_vhost.path) + + # four args to HSTS header + self.assertEqual(len(uir_header), 4) + + def test_http_header_uir_twice(self): + self.config.parser.modules.add("mod_ssl.c") + # skip the enable mod + self.config.parser.modules.add("headers_module") + + # This will create an ssl vhost for letsencrypt.demo + self.config.enhance("encryption-example.demo", "http-header", + "Upgrade-Insecure-Requests") + + self.assertRaises( + errors.PluginError, + self.config.enhance, "encryption-example.demo", "http-header", + "Upgrade-Insecure-Requests") + + @mock.patch("letsencrypt.le_util.run_script") @mock.patch("letsencrypt.le_util.exe_exists")