diff --git a/letsencrypt/client/apache_configurator.py b/letsencrypt/client/apache_configurator.py index 9f6da6b33..6f575509a 100644 --- a/letsencrypt/client/apache_configurator.py +++ b/letsencrypt/client/apache_configurator.py @@ -225,7 +225,6 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator): return False logger.info("Deploying Certificate to VirtualHost %s" % vhost.file) - print path self.aug.set(path["cert_file"][0], cert) self.aug.set(path["cert_key"][0], key) @@ -537,14 +536,14 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator): def make_server_sni_ready(self, vhost, default_addr="*:443"): """Checks to see if the server is ready for SNI challenges. - .. todo:: This should largely depend on the version of Apache - :param vhost: VHost to check SNI compatibility :type vhost: :class:`VH` :param str default_addr: TODO - investigate function further """ + if self.version >= (2, 4): + return # Check for NameVirtualHost # First see if any of the vhost addresses is a _default_ addr for addr in vhost.addrs: @@ -555,7 +554,6 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator): "%s to be name based vhosts" % default_addr)) self.add_name_vhost(default_addr) - return True # No default addresses... so set each one individually for addr in vhost.addrs: if not self.is_name_vhost(addr): @@ -563,8 +561,6 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator): "to be a name based virtual host" % addr)) self.add_name_vhost(addr) - return True - def _get_ifmod(self, aug_conf_path, mod): """Returns the path to and creates one if it doesn't exist. @@ -585,7 +581,8 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator): def add_dir(self, aug_conf_path, directive, arg): """Appends directive to the end fo the file given by aug_conf_path. - Note: Not added to AugeasConfigurator because it may depend on the lens + .. note:: Not added to AugeasConfigurator because it may depend + on the lens :param str aug_conf_path: Augeas configuration path to add directive :param str directive: Directive to add @@ -662,12 +659,12 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator): for include in includes: # start[6:] to strip off /files matches.extend(self.find_directive( - directive, arg, self.get_include_path(strip_dir(start[6:]), - self.aug.get(include)))) + directive, arg, self._get_include_path(strip_dir(start[6:]), + self.aug.get(include)))) return matches - def get_include_path(self, cur_dir, arg): + def _get_include_path(self, cur_dir, arg): """Converts an Apache Include directive into Augeas path. Converts an Apache Include directive argument into an Augeas @@ -1387,8 +1384,7 @@ LogLevel warn \n\ return None # TODO - @jdkasten review this code to make sure it makes sense - if not self.make_server_sni_ready(vhost, default_addr): - return None + self.make_server_sni_ready(vhost, default_addr) for addr in vhost.addrs: if "_default_" in addr: @@ -1634,6 +1630,7 @@ def get_file_path(vhost_path): break return avail_fp + def get_aug_path(file_path): """Return augeas path for full filepath. @@ -1642,6 +1639,7 @@ def get_aug_path(file_path): """ return "/files%s" % file_path + def strip_dir(path): """Returns directory of file path. diff --git a/letsencrypt/client/tests/apache_configurator_test.py b/letsencrypt/client/tests/apache_configurator_test.py index 18164e290..4189bc2e4 100644 --- a/letsencrypt/client/tests/apache_configurator_test.py +++ b/letsencrypt/client/tests/apache_configurator_test.py @@ -134,6 +134,15 @@ class TwoVhosts_80(unittest.TestCase): self.assertTrue(self.config.is_site_enabled(self.vh_truth[2].file)) self.assertTrue(self.config.is_site_enabled(self.vh_truth[3].file)) + def test_add_dir(self): + """test add_dir.""" + aug_default = "/files" + self.config.location["default"] + self.config.add_dir( + aug_default, "AddDirective", "test") + + self.assertTrue( + self.config.find_directive("AddDirective", "test", aug_default)) + def test_deploy_cert(self): """test deploy_cert. @@ -178,7 +187,7 @@ class TwoVhosts_80(unittest.TestCase): def test_add_name_vhost(self): """test add_name_vhost.""" self.config.add_name_vhost("*:443") - #self.config.save(temporary=True) + # self.config.save(temporary=True) self.assertTrue(self.config.find_directive( "NameVirtualHost", re.escape("*:443"))) @@ -190,14 +199,43 @@ class TwoVhosts_80(unittest.TestCase): """ self.config._add_dir_to_ifmodssl( - self.aug_path + "ports.conf", "FakeDirective", "123") + "/files" + self.config.location["default"], "FakeDirective", "123") matches = self.config.find_directive("FakeDirective", "123") self.assertTrue(len(matches) == 1) self.assertTrue("IfModule" in matches[0]) + def test_make_vhost_ssl(self): + """test make_vhost_ssl.""" + ssl_vhost = self.config.make_vhost_ssl(self.vh_truth[0]) + + self.assertTrue( + ssl_vhost.file == + os.path.join(self.config_path, "sites-available", + "encryption-example-le-ssl.conf")) + + self.assertTrue(ssl_vhost.path == + "/files" + ssl_vhost.file + "/IfModule/VirtualHost") + self.assertTrue(ssl_vhost.addrs == ["*:443"]) + self.assertTrue(ssl_vhost.names == ["encryption-example.demo"]) + self.assertTrue(ssl_vhost.ssl) + self.assertFalse(ssl_vhost.enabled) + + self.assertTrue(self.config.find_directive( + "SSLCertificateFile", None, ssl_vhost.path)) + self.assertTrue(self.config.find_directive( + "SSLCertificateKeyFile", None, ssl_vhost.path)) + self.assertTrue(self.config.find_directive( + "Include", CONFIG.OPTIONS_SSL_CONF, ssl_vhost.path)) + + self.assertTrue(self.config.is_name_vhost(self.vh_truth[0]) == + self.config.is_name_vhost(ssl_vhost)) + + self.assertTrue(len(self.config.vhosts) == 5) + def _verify_redirect(self, config_path): + """Verifies that the vhost contains the REWRITE.""" with open(config_path, 'r') as config_fd: conf = config_fd.read() @@ -205,6 +243,7 @@ class TwoVhosts_80(unittest.TestCase): def debug_file(filepath): + """Print out the file.""" with open(filepath, 'r')as file_d: print file_d.read()