def get_vh_truth(temp_dir, config_name): """Return the ground truth for the specified directory.""" prefix = os.path.join( temp_dir, config_name, "apache2/vhosts.d") aug_pre = "/files" + prefix vh_truth = [ obj.VirtualHost( os.path.join(prefix, "gentoo.example.com.conf"), os.path.join(aug_pre, "gentoo.example.com.conf/VirtualHost"), set([obj.Addr.fromstring("*:80")]), False, True, "gentoo.example.com"), obj.VirtualHost( os.path.join(prefix, "00_default_vhost.conf"), os.path.join(aug_pre, "00_default_vhost.conf/IfDefine/VirtualHost"), set([obj.Addr.fromstring("*:80")]), False, True, "localhost"), obj.VirtualHost( os.path.join(prefix, "00_default_ssl_vhost.conf"), os.path.join(aug_pre, "00_default_ssl_vhost.conf" + "/IfDefine/IfDefine/IfModule/VirtualHost"), set([obj.Addr.fromstring("_default_:443")]), True, True, "localhost") ] return vh_truth
def test_bad_servername_alias(self): ssl_vh1 = obj.VirtualHost("fp1", "ap1", set([obj.Addr(("*", "443"))]), True, False) # pylint: disable=protected-access self.config._add_servernames(ssl_vh1) self.assertTrue( self.config._add_servername_alias("oy_vey", ssl_vh1) is 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 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, "certbot.conf"), os.path.join(aug_pre, "certbot.conf/VirtualHost"), set([obj.Addr.fromstring("*:80")]), False, True, "certbot.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"]), obj.VirtualHost( os.path.join(prefix, "ocsp-ssl.conf"), os.path.join(aug_pre, "ocsp-ssl.conf/IfModule/VirtualHost"), set([obj.Addr.fromstring("10.2.3.4:443")]), True, True, "ocspvhost.com") ] return vh_truth return None # pragma: no cover
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_http_vhost_third_filter(self): ssl_vh = obj.VirtualHost("fp", "ap", set([obj.Addr(("*", "443"))]), True, False) ssl_vh.name = "satoshi.com" self.config.vhosts.append(ssl_vh) # pylint: disable=protected-access http_vh = self.config._get_http_vhost(ssl_vh) self.assertTrue(http_vh.ssl == False)
def test_enable_site_failure(self): self.config.parser.root = "/tmp/nonexistent" with mock.patch("os.path.isdir") as mock_dir: mock_dir.return_value = True with mock.patch("os.path.islink") as mock_link: mock_link.return_value = False self.assertRaises( errors.NotSupportedError, self.config.enable_site, obj.VirtualHost("asdf", "afsaf", set(), False, False))
def get_vh_truth(temp_dir, config_name): """Return the ground truth for the specified directory.""" prefix = os.path.join(temp_dir, config_name, "httpd/conf.d") aug_pre = "/files" + prefix # TODO: eventually, these tests should have a dedicated configuration instead # of reusing the ones from centos_test vh_truth = [ obj.VirtualHost( os.path.join(prefix, "centos.example.com.conf"), os.path.join(aug_pre, "centos.example.com.conf/VirtualHost"), {obj.Addr.fromstring("*:80")}, False, True, "centos.example.com"), obj.VirtualHost(os.path.join(prefix, "ssl.conf"), os.path.join(aug_pre, "ssl.conf/VirtualHost"), {obj.Addr.fromstring("_default_:443")}, True, True, None) ] return vh_truth
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_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_enable_site_failure(self): self.assertRaises( errors.NotSupportedError, self.config.enable_site, obj.VirtualHost("asdf", "afsaf", set(), False, False))