예제 #1
0
 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)
예제 #2
0
    def test_mod_config(self):
        for achall in self.achalls:
            self.sni.add_chall(achall)
        v_addr1 = [obj.Addr(("1.2.3.4", "443")), obj.Addr(("5.6.7.8", "443"))]
        v_addr2 = [obj.Addr(("127.0.0.1", "443"))]
        ll_addr = []
        ll_addr.append(v_addr1)
        ll_addr.append(v_addr2)
        self.sni._mod_config(ll_addr)  # pylint: disable=protected-access
        self.sni.configurator.save()

        self.sni.configurator.parser.find_dir(
            "Include", self.sni.challenge_conf)
        vh_match = self.sni.configurator.aug.match(
            "/files" + self.sni.challenge_conf + "//VirtualHost")

        vhs = []
        for match in vh_match:
            # pylint: disable=protected-access
            vhs.append(self.sni.configurator._create_vhost(match))
        self.assertEqual(len(vhs), 2)
        for vhost in vhs:
            if vhost.addrs == set(v_addr1):
                self.assertEqual(
                    vhost.names,
                    set([self.achalls[0].nonce_domain]))
            else:
                self.assertEqual(vhost.addrs, set(v_addr2))
                self.assertEqual(
                    vhost.names,
                    set([self.achalls[1].nonce_domain]))
예제 #3
0
    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, "")
예제 #4
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")),
              obj.Addr(("satoshi.com", ))]), True, False)
     self.config.vhosts.append(ssl_vh)
     self.assertRaises(errors.PluginError, self.config.enhance,
                       "satoshi.com", "redirect")
예제 #5
0
    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)
예제 #6
0
    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)
예제 #7
0
    def _get_addrs(self, achall):
        """Return the Apache addresses needed for TLS-SNI-01."""
        vhost = self.configurator.choose_vhost(achall.domain, temp=True)
        # TODO: Checkout _default_ rules.
        addrs = set()
        default_addr = obj.Addr(
            ("*", str(self.configurator.config.tls_sni_01_port)))

        for addr in vhost.addrs:
            if "_default_" == addr.get_addr():
                addrs.add(default_addr)
            else:
                addrs.add(
                    addr.get_sni_addr(
                        self.configurator.config.tls_sni_01_port))

        return addrs
예제 #8
0
    def test_add_name_vhost_if_necessary(self):
        # pylint: disable=protected-access
        self.config.save = mock.Mock()
        self.config.version = (2, 2)
        self.config._add_name_vhost_if_necessary(self.vh_truth[0])
        self.assertTrue(self.config.save.called)

        new_addrs = set()
        for addr in self.vh_truth[0].addrs:
            new_addrs.add(obj.Addr((
                "_default_",
                addr.get_port(),
            )))

        self.vh_truth[0].addrs = new_addrs
        self.config._add_name_vhost_if_necessary(self.vh_truth[0])
        self.assertEqual(self.config.save.call_count, 2)
예제 #9
0
    def get_dvsni_addrs(self, achall):
        """Return the Apache addresses needed for DVSNI."""
        vhost = self.configurator.choose_vhost(achall.domain)

        # TODO: Checkout _default_ rules.
        dvsni_addrs = set()
        default_addr = obj.Addr(
            ("*", str(self.configurator.config.dvsni_port)))

        for addr in vhost.addrs:
            if "_default_" == addr.get_addr():
                dvsni_addrs.add(default_addr)
            else:
                dvsni_addrs.add(
                    addr.get_sni_addr(self.configurator.config.dvsni_port))

        return dvsni_addrs
예제 #10
0
    def choose_vhost(self, target_name):
        """Chooses a virtual host based on the given domain name.

        .. todo:: This should maybe return list if no obvious answer
            is presented.

        :param str target_name: domain name

        :returns: ssl vhost associated with name
        :rtype: :class:`~letsencrypt_apache.obj.VirtualHost`

        """
        # Allows for domain names to be associated with a virtual host
        # Client isn't using create_dn_server_assoc(self, dn, vh) yet
        if target_name in self.assoc:
            return self.assoc[target_name]
        # Check for servernames/aliases for ssl hosts
        for vhost in self.vhosts:
            if vhost.ssl and target_name in vhost.names:
                self.assoc[target_name] = vhost
                return vhost
        # Checking for domain name in vhost address
        # This technique is not recommended by Apache but is technically valid
        target_addr = obj.Addr((target_name, "443"))
        for vhost in self.vhosts:
            if target_addr in vhost.addrs:
                self.assoc[target_name] = vhost
                return vhost

        # Check for non ssl vhosts with servernames/aliases == "name"
        for vhost in self.vhosts:
            if not vhost.ssl and target_name in vhost.names:
                vhost = self.make_vhost_ssl(vhost)
                self.assoc[target_name] = vhost
                return vhost

        # No matches, search for the default
        for vhost in self.vhosts:
            if "_default_:443" in vhost.addrs:
                return vhost
        return None