Skip to content

Commit

Permalink
Merge pull request #60 from twisted/21-allow-alternate-domains
Browse files Browse the repository at this point in the history
Allow alternative domains without canonicalization
  • Loading branch information
glyph committed Oct 11, 2016
2 parents a143334 + 3b1c660 commit aa900ba
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
24 changes: 13 additions & 11 deletions xmantissa/test/integration/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,19 @@ def setUp(self):
have to be cleaned up.
"""
self.store = Store(filesdir=self.mktemp()) # See #2484
Mantissa().installSite(self.store, self.domain, u'', False) # See #2483
self.site = self.store.findUnique(SiteConfiguration)
self.login = self.store.findUnique(LoginSystem)

# Ports should be offering installation parameters. This assumes a
# TCPPort and an SSLPort are created by Mantissa.installSite. See
# #538. -exarkun
self.store.query(
SSLPort, SSLPort.factory == self.site).deleteFromStore()

self.factory = self.site.getFactory()
def _tx():
Mantissa().installSite(self.store, self.domain, u'', False)
self.site = self.store.findUnique(SiteConfiguration)
self.login = self.store.findUnique(LoginSystem)

# Ports should be offering installation parameters. This assumes a
# TCPPort and an SSLPort are created by Mantissa.installSite. See
# #538. -exarkun
self.store.query(
SSLPort, SSLPort.factory == self.site).deleteFromStore()

self.factory = self.site.getFactory()
self.store.transact(_tx)

self.origFunctions = (GuardSession.checkExpired.im_func,
athena.ReliableMessageDelivery)
Expand Down
13 changes: 13 additions & 0 deletions xmantissa/test/test_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,19 @@ def test_rootURLWWWSubdomain(self):
self.assertEqual(self.site.rootURL(request), URL('', ''))


def test_rootURLAlternateSubdomain(self):
"""
L{SiteConfiguration.rootURL} returns C{/} for a request made onto a
subdomain known as an internal domain.
"""
userbase.LoginMethod(
store=self.store, localpart=u'username', domain=u'example.org',
internal=True, protocol=u'*', verified=True, account=self.store)
request = FakeRequest(headers={
'host': 'example.org'})
self.assertEqual(self.site.rootURL(request), URL('', ''))


def _differentHostnameTest(self, portType, portNumber, isSecure, scheme):
request = FakeRequest(isSecure=isSecure, headers={
'host': 'alice.' + self.domain.encode('ascii')})
Expand Down
16 changes: 8 additions & 8 deletions xmantissa/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from axiom.item import Item
from axiom.attributes import path, text
from axiom.dependency import dependsOn
from axiom.userbase import LoginSystem
from axiom.userbase import LoginSystem, getDomainNames

from xmantissa.ixmantissa import ISiteURLGenerator, IProtocolFactoryFactory, IOfferingTechnician, ISessionlessSiteRootPlugin
from xmantissa.port import TCPPort, SSLPort
Expand Down Expand Up @@ -150,14 +150,14 @@ def rootURL(self, request):
host = request.getHeader('host') or self.hostname
if ':' in host:
host = host.split(':', 1)[0]
if (host == self.hostname or
host.startswith('www.') and host[len('www.'):] == self.hostname):
return URL(scheme='', netloc='', pathsegs=[''])
for domain in [self.hostname] + getDomainNames(self.store):
if (host == domain or
host.startswith('www.') and host[len('www.'):] == domain):
return URL(scheme='', netloc='', pathsegs=[''])
if request.isSecure():
return self.encryptedRoot(self.hostname)
else:
if request.isSecure():
return self.encryptedRoot(self.hostname)
else:
return self.cleartextRoot(self.hostname)
return self.cleartextRoot(self.hostname)


def getFactory(self):
Expand Down

0 comments on commit aa900ba

Please sign in to comment.