예제 #1
0
 def test_select_correct(self, mock_util):
     mock_util().checklist.return_value = (display_util.OK, [
         self.vhosts[3].display_repr(), self.vhosts[2].display_repr()
     ])
     vhs = select_vhost_multiple(
         [self.vhosts[3], self.vhosts[2], self.vhosts[1]])
     self.assertTrue(self.vhosts[2] in vhs)
     self.assertTrue(self.vhosts[3] in vhs)
     self.assertFalse(self.vhosts[1] in vhs)
예제 #2
0
 def test_select_correct(self, mock_util):
     mock_util().checklist.return_value = (
         display_util.OK, [self.vhosts[3].display_repr(),
                           self.vhosts[2].display_repr()])
     vhs = select_vhost_multiple([self.vhosts[3],
                                  self.vhosts[2],
                                  self.vhosts[1]])
     self.assertTrue(self.vhosts[2] in vhs)
     self.assertTrue(self.vhosts[3] in vhs)
     self.assertFalse(self.vhosts[1] in vhs)
예제 #3
0
    def _choose_vhosts_wildcard(self,
                                domain,
                                prefer_ssl,
                                no_ssl_filter_port=None):
        """Prompts user to choose vhosts to install a wildcard certificate for"""
        if prefer_ssl:
            vhosts_cache = self._wildcard_vhosts
            preference_test = lambda x: x.ssl
        else:
            vhosts_cache = self._wildcard_redirect_vhosts
            preference_test = lambda x: not x.ssl

        # Caching!
        if domain in vhosts_cache:
            # Vhosts for a wildcard domain were already selected
            return vhosts_cache[domain]

        # Get all vhosts whether or not they are covered by the wildcard domain
        vhosts = self.parser.get_vhosts()

        # Go through the vhosts, making sure that we cover all the names
        # present, but preferring the SSL or non-SSL vhosts
        filtered_vhosts = {}
        for vhost in vhosts:
            # Ensure we're listening non-sslishly on no_ssl_filter_port
            if no_ssl_filter_port is not None:
                if not self._vhost_listening_on_port_no_ssl(
                        vhost, no_ssl_filter_port):
                    continue
            for name in vhost.names:
                if preference_test(vhost):
                    # Prefer either SSL or non-SSL vhosts
                    filtered_vhosts[name] = vhost
                elif name not in filtered_vhosts:
                    # Add if not in list previously
                    filtered_vhosts[name] = vhost

        # Only unique VHost objects
        dialog_input = set([vhost for vhost in filtered_vhosts.values()])

        # Ask the user which of names to enable, expect list of names back
        return_vhosts = display_ops.select_vhost_multiple(list(dialog_input))

        for vhost in return_vhosts:
            if domain not in vhosts_cache:
                vhosts_cache[domain] = []
            vhosts_cache[domain].append(vhost)

        return return_vhosts
예제 #4
0
    def _choose_vhosts_wildcard(self, domain, prefer_ssl, no_ssl_filter_port=None):
        """Prompts user to choose vhosts to install a wildcard certificate for"""
        if prefer_ssl:
            vhosts_cache = self._wildcard_vhosts
            preference_test = lambda x: x.ssl
        else:
            vhosts_cache = self._wildcard_redirect_vhosts
            preference_test = lambda x: not x.ssl

        # Caching!
        if domain in vhosts_cache:
            # Vhosts for a wildcard domain were already selected
            return vhosts_cache[domain]

        # Get all vhosts whether or not they are covered by the wildcard domain
        vhosts = self.parser.get_vhosts()

        # Go through the vhosts, making sure that we cover all the names
        # present, but preferring the SSL or non-SSL vhosts
        filtered_vhosts = {}
        for vhost in vhosts:
            # Ensure we're listening non-sslishly on no_ssl_filter_port
            if no_ssl_filter_port is not None:
                if not self._vhost_listening_on_port_no_ssl(vhost, no_ssl_filter_port):
                    continue
            for name in vhost.names:
                if preference_test(vhost):
                    # Prefer either SSL or non-SSL vhosts
                    filtered_vhosts[name] = vhost
                elif name not in filtered_vhosts:
                    # Add if not in list previously
                    filtered_vhosts[name] = vhost

        # Only unique VHost objects
        dialog_input = set([vhost for vhost in filtered_vhosts.values()])

        # Ask the user which of names to enable, expect list of names back
        return_vhosts = display_ops.select_vhost_multiple(list(dialog_input))

        for vhost in return_vhosts:
            if domain not in vhosts_cache:
                vhosts_cache[domain] = []
            vhosts_cache[domain].append(vhost)

        return return_vhosts
예제 #5
0
 def test_select_cancel(self, mock_util):
     mock_util().checklist.return_value = (display_util.CANCEL, "whatever")
     vhs = select_vhost_multiple([self.vhosts[2], self.vhosts[3]])
     self.assertFalse(vhs)
예제 #6
0
 def test_select_no_input(self):
     self.assertFalse(select_vhost_multiple([]))
예제 #7
0
 def test_select_cancel(self, mock_util):
     mock_util().checklist.return_value = (display_util.CANCEL, "whatever")
     vhs = select_vhost_multiple([self.vhosts[2], self.vhosts[3]])
     self.assertFalse(vhs)
예제 #8
0
 def test_select_no_input(self):
     self.assertFalse(select_vhost_multiple([]))