Commit b7046ffb authored by Jérome Perrin's avatar Jérome Perrin Committed by GitHub

Merge pull request #395 from perrinjerome/backport/314

Zope 2.13: SiteAccess: Make VirtualHostMonster support IPv6
parents 0c4b5d6c 6fbaee13
......@@ -15,6 +15,7 @@ from ZPublisher.BeforeTraverse import queryBeforeTraverse
from ZPublisher.BeforeTraverse import registerBeforeTraverse
from ZPublisher.BeforeTraverse import unregisterBeforeTraverse
from ZPublisher.BaseRequest import quote
from ZPublisher.HTTPRequest import splitport
from zExceptions import BadRequest
class VirtualHostMonster(Persistent, Item, Implicit):
......@@ -150,11 +151,7 @@ class VirtualHostMonster(Persistent, Item, Implicit):
stack.pop()
protocol = stack.pop()
host = stack.pop()
if ':' in host:
host, port = host.split(':')
request.setServerURL(protocol, host, port)
else:
request.setServerURL(protocol, host)
request.setServerURL(protocol, *splitport(host))
path = list(stack)
# Find and convert VirtualHostRoot directive
......
......@@ -97,7 +97,7 @@ class VHMRegressions(unittest.TestCase):
ob = self.traverse('/VirtualHostBase/http/www.mysite.com:80'
'/folder/VirtualHostRoot')
self.assertEqual(self.app.REQUEST['ACTUAL_URL'],
'http://www.mysite.com/')
'http://www.mysite.com/')
def gen_cases():
for vbase, ubase in (
......@@ -139,6 +139,75 @@ for i, (vaddr, vr, _vh, p, ubase) in enumerate(gen_cases()):
setattr(VHMRegressions, 'testTraverse%s' % i, test)
class VHMPort(unittest.TestCase):
def setUp(self):
import transaction
from Testing.makerequest import makerequest
from Testing.ZopeTestCase.ZopeLite import app
transaction.begin()
self.app = makerequest(app())
if 'virtual_hosting' not in self.app.objectIds():
# If ZopeLite was imported, we have no default virtual
# host monster
from Products.SiteAccess.VirtualHostMonster \
import manage_addVirtualHostMonster
manage_addVirtualHostMonster(self.app, 'virtual_hosting')
self.app.manage_addFolder('folder')
self.app.folder.manage_addDTMLMethod('doc', '')
self.app.REQUEST.set('PARENTS', [self.app])
self.traverse = self.app.REQUEST.traverse
def tearDown(self):
import transaction
transaction.abort()
self.app._p_jar.close()
def testHostname(self):
self.traverse('/VirtualHostBase/http/www.mysite.com:80/folder/')
self.assertEqual(self.app.REQUEST['ACTUAL_URL'],
'http://www.mysite.com/folder/')
def testHostnameNoport(self):
self.traverse('/VirtualHostBase/http/www.mysite.com/folder/')
self.assertEqual(self.app.REQUEST['ACTUAL_URL'],
'http://www.mysite.com/folder/')
def testPassedPortHostname(self):
self.traverse('/VirtualHostBase/http/www.mysite.com:81/folder/')
self.assertEqual(self.app.REQUEST['ACTUAL_URL'],
'http://www.mysite.com:81/folder/')
def testIPv4(self):
self.traverse('/VirtualHostBase/http/127.0.0.1:80/folder/')
self.assertEqual(self.app.REQUEST['ACTUAL_URL'],
'http://127.0.0.1/folder/')
def testIPv4Noport(self):
self.traverse('/VirtualHostBase/http/127.0.0.1/folder/')
self.assertEqual(self.app.REQUEST['ACTUAL_URL'],
'http://127.0.0.1/folder/')
def testPassedPortIPv4(self):
self.traverse('/VirtualHostBase/http/127.0.0.1:81/folder/')
self.assertEqual(self.app.REQUEST['ACTUAL_URL'],
'http://127.0.0.1:81/folder/')
def testIPv6(self):
self.traverse('/VirtualHostBase/http/[::1]:80/folder/')
self.assertEqual(self.app.REQUEST['ACTUAL_URL'],
'http://[::1]/folder/')
def testIPv6NoPort(self):
self.traverse('/VirtualHostBase/http/[::1]/folder/')
self.assertEqual(self.app.REQUEST['ACTUAL_URL'],
'http://[::1]/folder/')
def testIPv6PassedPort(self):
self.traverse('/VirtualHostBase/http/[::1]:81/folder/')
self.assertEqual(self.app.REQUEST['ACTUAL_URL'],
'http://[::1]:81/folder/')
class VHMAddingTests(unittest.TestCase):
......@@ -198,8 +267,3 @@ class VHMAddingTests(unittest.TestCase):
hook = queryBeforeTraverse(self.root, VirtualHostMonster.meta_type)
self.assertTrue(hook)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(VHMRegressions))
suite.addTest(unittest.makeSuite(VHMAddingTests))
return suite
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment