def get_vh_truth(temp_dir, config_name): """Return the ground truth for the specified directory.""" if config_name == "debian_apache_2_4/two_vhost_80": prefix = os.path.join(temp_dir, config_name, "apache2/sites-available") aug_pre = "/files" + prefix vh_truth = [ obj.VirtualHost( os.path.join(prefix, "encryption-example.conf"), os.path.join(aug_pre, "encryption-example.conf/VirtualHost"), set([common.Addr.fromstring("*:80")]), False, True, set(["encryption-example.demo"])), obj.VirtualHost( os.path.join(prefix, "default-ssl.conf"), os.path.join(aug_pre, "default-ssl.conf/IfModule/VirtualHost"), set([common.Addr.fromstring("_default_:443")]), True, False), obj.VirtualHost( os.path.join(prefix, "000-default.conf"), os.path.join(aug_pre, "000-default.conf/VirtualHost"), set([common.Addr.fromstring("*:80")]), False, True, set(["ip-172-30-0-17"])), obj.VirtualHost( os.path.join(prefix, "letsencrypt.conf"), os.path.join(aug_pre, "letsencrypt.conf/VirtualHost"), set([common.Addr.fromstring("*:80")]), False, True, set(["letsencrypt.demo"])), ] return vh_truth return None
def test_find_best_vhost_variety(self): # pylint: disable=protected-access ssl_vh = obj.VirtualHost( "fp", "ap", set([obj.Addr(("*", "443")), obj.Addr(("zombo.com",))]), True, False) self.config.vhosts.append(ssl_vh) self.assertEqual(self.config._find_best_vhost("zombo.com"), ssl_vh)
def test_choose_vhost_select_vhost_conflicting_non_ssl(self, mock_select): mock_select.return_value = self.vh_truth[3] conflicting_vhost = obj.VirtualHost( "path", "aug_path", set([obj.Addr.fromstring("*:443")]), True, True) self.config.vhosts.append(conflicting_vhost) self.assertRaises( errors.PluginError, self.config.choose_vhost, "none.com")
def test_get_dvsni_addrs_default(self): self.sni.configurator.choose_vhost = mock.Mock( return_value=obj.VirtualHost( "path", "aug_path", set([obj.Addr.fromstring("_default_:443") ]), False, False)) self.assertEqual(set([obj.Addr.fromstring("*:443")]), self.sni.get_dvsni_addrs(self.achalls[0]))
def test_enhance_unknown_vhost(self, mock_exe): self.config.parser.modules.add("rewrite_module") mock_exe.return_value = True ssl_vh = obj.VirtualHost("fp", "ap", set([obj.Addr(("*", "443"))]), True, False) ssl_vh.name = "satoshi.com" self.config.vhosts.append(ssl_vh) self.assertRaises(errors.PluginError, self.config.enhance, "satoshi.com", "redirect")
def test_multiple_names(self, mock_util): mock_util().menu.return_value = (display_util.OK, 5) self.vhosts.append( obj.VirtualHost("path", "aug_path", set([obj.Addr.fromstring("*:80")]), False, False, "wildcard.com", set(["*.wildcard.com"]))) self.assertEqual(self.vhosts[5], self._call(self.vhosts))
def test_redirect_with_conflict(self): self.config.parser.modules.add("rewrite_module") ssl_vh = obj.VirtualHost( "fp", "ap", set([obj.Addr(("*", "443")), obj.Addr(("zombo.com",))]), True, False) # No names ^ this guy should conflict. # pylint: disable=protected-access self.assertRaises( errors.PluginError, self.config._enable_redirect, ssl_vh, "")
def test_get_all_names_addrs(self, mock_gethost): mock_gethost.side_effect = [("google.com", "", ""), socket.error] vhost = obj.VirtualHost( "fp", "ap", set([obj.Addr(("8.8.8.8", "443")), obj.Addr(("zombo.com",)), obj.Addr(("192.168.1.2"))]), True, False) self.config.vhosts.append(vhost) names = self.config.get_all_names() self.assertEqual(len(names), 5) self.assertTrue("zombo.com" in names) self.assertTrue("google.com" in names) self.assertTrue("letsencrypt.demo" in names)
def get_vh_truth(temp_dir, config_name): """Return the ground truth for the specified directory.""" if config_name == "debian_apache_2_4/multiple_vhosts": prefix = os.path.join(temp_dir, config_name, "apache2/sites-available") aug_pre = "/files" + prefix vh_truth = [ obj.VirtualHost( os.path.join(prefix, "encryption-example.conf"), os.path.join(aug_pre, "encryption-example.conf/VirtualHost"), set([obj.Addr.fromstring("*:80")]), False, True, "encryption-example.demo"), obj.VirtualHost( os.path.join(prefix, "default-ssl.conf"), os.path.join(aug_pre, "default-ssl.conf/IfModule/VirtualHost"), set([obj.Addr.fromstring("_default_:443")]), True, False), obj.VirtualHost( os.path.join(prefix, "000-default.conf"), os.path.join(aug_pre, "000-default.conf/VirtualHost"), set([ obj.Addr.fromstring("*:80"), obj.Addr.fromstring("[::]:80") ]), False, True, "ip-172-30-0-17"), obj.VirtualHost( os.path.join(prefix, "letsencrypt.conf"), os.path.join(aug_pre, "letsencrypt.conf/VirtualHost"), set([obj.Addr.fromstring("*:80")]), False, True, "letsencrypt.demo"), obj.VirtualHost(os.path.join(prefix, "mod_macro-example.conf"), os.path.join( aug_pre, "mod_macro-example.conf/Macro/VirtualHost"), set([obj.Addr.fromstring("*:80")]), False, True, modmacro=True), obj.VirtualHost( os.path.join(prefix, "default-ssl-port-only.conf"), os.path.join(aug_pre, ("default-ssl-port-only.conf/" "IfModule/VirtualHost")), set([obj.Addr.fromstring("_default_:443")]), True, False), obj.VirtualHost(os.path.join(prefix, "wildcard.conf"), os.path.join(aug_pre, "wildcard.conf/VirtualHost"), set([obj.Addr.fromstring("*:80")]), False, False, "ip-172-30-0-17", aliases=["*.blue.purple.com"]) ] return vh_truth return None # pragma: no cover
def test_get_all_names_addrs(self, mock_gethost, mock_getutility): mock_gethost.side_effect = [("google.com", "", ""), socket.error] notification = mock.Mock() notification.notification = mock.Mock(return_value=True) mock_getutility.return_value = notification vhost = obj.VirtualHost( "fp", "ap", set([ obj.Addr(("8.8.8.8", "443")), obj.Addr(("zombo.com", )), obj.Addr(("192.168.1.2")) ]), True, False) self.config.vhosts.append(vhost) names = self.config.get_all_names() self.assertEqual(len(names), 6) self.assertTrue("zombo.com" in names) self.assertTrue("google.com" in names) self.assertTrue("letsencrypt.demo" in names)
def _create_vhost(self, path): """Used by get_virtual_hosts to create vhost objects :param str path: Augeas path to virtual host :returns: newly created vhost :rtype: :class:`~letsencrypt_apache.obj.VirtualHost` """ addrs = set() args = self.aug.match(path + "/arg") for arg in args: addrs.add(common.Addr.fromstring(self.aug.get(arg))) is_ssl = False if self.parser.find_dir(parser.case_i("SSLEngine"), parser.case_i("on"), path): is_ssl = True filename = get_file_path(path) is_enabled = self.is_site_enabled(filename) vhost = obj.VirtualHost(filename, path, addrs, is_ssl, is_enabled) self._add_servernames(vhost) return vhost
def test_enable_site_failure(self): self.assertRaises( errors.NotSupportedError, self.config.enable_site, obj.VirtualHost("asdf", "afsaf", set(), False, False))