Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 2076

Show
Ignore:
Timestamp:
11/08/08 15:51:34
Author:
fumanchu
Message:

Whew. Fixed the whole test suite to properly handle the --host arg.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/test/test_http.py

    r2072 r2076  
    7171        # with 411 Length Required. 
    7272        if self.scheme == "https": 
    73             c = httplib.HTTPSConnection("127.0.0.1:%s" % self.PORT
     73            c = httplib.HTTPSConnection('%s:%s' % (self.interface(), self.PORT)
    7474        else: 
    75             c = httplib.HTTPConnection("127.0.0.1:%s" % self.PORT
     75            c = httplib.HTTPConnection('%s:%s' % (self.interface(), self.PORT)
    7676        c.request("POST", "/") 
    7777        self.assertEqual(c.getresponse().status, 411) 
     
    8888        # post file 
    8989        if self.scheme == 'https': 
    90             c = httplib.HTTPS('127.0.0.1:%s' % self.PORT
     90            c = httplib.HTTPS('%s:%s' % (self.interface(), self.PORT)
    9191        else: 
    92             c = httplib.HTTP('127.0.0.1:%s' % self.PORT
     92            c = httplib.HTTP('%s:%s' % (self.interface(), self.PORT)
    9393        c.putrequest('POST', '/post_multipart') 
    9494        c.putheader('Content-Type', content_type) 
     
    111111        # Test missing version in Request-Line 
    112112        if self.scheme == 'https': 
    113             c = httplib.HTTPSConnection('127.0.0.1:%s' % self.PORT
     113            c = httplib.HTTPSConnection('%s:%s' % (self.interface(), self.PORT)
    114114        else: 
    115             c = httplib.HTTPConnection('127.0.0.1:%s' % self.PORT
     115            c = httplib.HTTPConnection('%s:%s' % (self.interface(), self.PORT)
    116116        c._output('GET /') 
    117117        c._send_output() 
  • trunk/cherrypy/test/test_logging.py

    r1984 r2076  
    8080        self.assertStatus(200) 
    8181         
    82         host = self.HOST 
    83         if host == '0.0.0.0': 
    84             # INADDR_ANY, which should respond on localhost. 
    85             host = "127.0.0.1" 
    86         if host == '::': 
    87             # IN6ADDR_ANY, which should respond on localhost. 
    88             host = "::1" 
    89         intro = '%s - - [' % host 
     82        intro = '%s - - [' % self.interface() 
    9083         
    9184        self.assertLog(-1, intro) 
     
    10699        self.assertStatus(200) 
    107100         
    108         host = self.HOST 
    109         if host == '0.0.0.0': 
    110             # INADDR_ANY, which should respond on localhost. 
    111             host = "127.0.0.1" 
    112         if host == '::': 
    113             # IN6ADDR_ANY, which should respond on localhost. 
    114             host = "::1" 
    115         intro = '%s - - [' % host 
     101        intro = '%s - - [' % self.interface() 
    116102         
    117103        self.assertLog(-1, intro) 
  • trunk/cherrypy/test/test_objectmapping.py

    r2072 r2076  
    245245         
    246246        # Test absoluteURI's in the Request-Line 
    247         self.getPage('http://127.0.0.1/'
     247        self.getPage('http://%s:%s/' % (self.interface(), self.PORT)
    248248        self.assertBody('world') 
    249249         
  • trunk/cherrypy/test/test_refleaks.py

    r2005 r2076  
    8989         
    9090        def getpage(): 
    91             host = '%s:%s' % (self.HOST, self.PORT) 
     91            host = '%s:%s' % (self.interface(), self.PORT) 
    9292            if self.scheme == 'https': 
    9393                c = httplib.HTTPSConnection(host) 
  • trunk/cherrypy/test/test_session.py

    r2062 r2076  
    208208        def request(index): 
    209209            if self.scheme == 'https': 
    210                 c = httplib.HTTPSConnection('127.0.0.1:%s' % self.PORT
     210                c = httplib.HTTPSConnection('%s:%s' % (self.interface(), self.PORT)
    211211            else: 
    212                 c = httplib.HTTPConnection('127.0.0.1:%s' % self.PORT
     212                c = httplib.HTTPConnection('%s:%s' % (self.interface(), self.PORT)
    213213            for i in xrange(request_count): 
    214214                c.putrequest('GET', '/') 
  • trunk/cherrypy/test/test_xmlrpc.py

    r2015 r2076  
    117117            pass 
    118118         
    119         host = self.HOST 
    120         if host == '0.0.0.0': 
    121             # INADDR_ANY, which should respond on localhost. 
    122             host = "127.0.0.1" 
    123         if host == '::': 
    124             # IN6ADDR_ANY, which should respond on localhost. 
    125             host = "::1" 
    126          
    127119        if scheme == "https": 
    128             url = 'https://%s:%s/xmlrpc/' % (host, self.PORT) 
     120            url = 'https://%s:%s/xmlrpc/' % (self.interface(), self.PORT) 
    129121            proxy = xmlrpclib.ServerProxy(url, transport=HTTPSTransport()) 
    130122        else: 
    131             url = 'http://%s:%s/xmlrpc/' % (host, self.PORT) 
     123            url = 'http://%s:%s/xmlrpc/' % (self.interface(), self.PORT) 
    132124            proxy = xmlrpclib.ServerProxy(url) 
    133125         
  • trunk/cherrypy/test/webtest.py

    r2063 r2076  
    192192        self.set_persistent(on) 
    193193    persistent = property(_get_persistent, _set_persistent) 
     194     
     195    def interface(self): 
     196        """Return an IP address for a client connection. 
     197         
     198        If the server is listening on '0.0.0.0' (INADDR_ANY) 
     199        or '::' (IN6ADDR_ANY), this will return the proper localhost.""" 
     200        host = self.HOST 
     201        if host == '0.0.0.0': 
     202            # INADDR_ANY, which should respond on localhost. 
     203            return "127.0.0.1" 
     204        if host == '::': 
     205            # IN6ADDR_ANY, which should respond on localhost. 
     206            return "::1" 
     207        return host 
    194208     
    195209    def getPage(self, url, headers=None, method="GET", body=None, protocol=None): 
  • trunk/cherrypy/wsgiserver/__init__.py

    r2069 r2076  
    16161616            self.socket = SSLConnection(ctx, self.socket) 
    16171617            self.populate_ssl_environ() 
     1618             
     1619            # If listening on the IPV6 any address ('::' = IN6ADDR_ANY), 
     1620            # activate dual-stack. See http://www.cherrypy.org/ticket/871. 
     1621            if (not isinstance(self.bind_addr, basestring) 
     1622                and self.bind_addr[0] == '::' and family == socket.AF_INET6): 
     1623                try: 
     1624                    self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0) 
     1625                except (AttributeError, socket.error): 
     1626                    # Apparently, the socket option is not available in 
     1627                    # this machine's TCP stack 
     1628                    pass 
     1629         
    16181630        self.socket.bind(self.bind_addr) 
    16191631     

Hosted by WebFaction

Log in as guest/cpguest to create tickets