def setUp(self): """ Create a resource and a wrapper to test. """ self.store = Store() self.urlGenerator = SiteConfiguration(store=self.store, hostname=u"example.com") self.child = StubResource(None, None, None) self.childSegments = ("baz", "quux") self.content = "some bytes perhaps" self.resource = StubResource(self.child, self.childSegments, self.content) self.wrapper = SecuringWrapper(self.urlGenerator, self.resource)
def setUp(self): self.domain = u"example.com" self.store = Store() self.site = SiteConfiguration(store=self.store, hostname=self.domain)
def _makeSiteConfiguration(currentVersion, oldSite, couldHavePorts): from xmantissa.publicweb import AnonymousSite newSite = oldSite.upgradeVersion( 'mantissa_web_powerup', currentVersion, 6, hitCount=oldSite.hitCount) if newSite.store.parent is not None: return newSite # SiteConfiguration dependsOn LoginSystem. LoginSystem was probably # installed by the mantissa axiomatic command. During the dependency # system conversion, that command was changed to use installOn on the # LoginSystem. However, no upgrader was supplied to create the new # dependency state. Consequently, there may be none. Consequently, a new # LoginSystem will be created if an item which dependsOn LoginSystem is # installed. This would be bad. So, set up the necessary dependency state # here, before instantiating SiteConfiguration. -exarkun # Addendum: it is almost certainly the case that there are not legitimate # configurations which lack a LoginSystem. However, a large number of # database upgrade tests construct unrealistic databases. One aspect of # the unrealism is that they lack a LoginSystem. Therefore, rather than # changing all the bogus stubs and regenerating the stubs, I will just # support the case where LoginSystem is missing. However, note that a # LoginSystem upgrader may invalidate this check and result in a duplicate # being created anyway. -exarkun loginSystem = oldSite.store.findUnique(LoginSystem, default=None) if loginSystem is not None and installedOn(loginSystem) is None: installOn(loginSystem, oldSite.store) uninstallFrom(oldSite.store, oldSite) site = SiteConfiguration( store=oldSite.store, httpLog=oldSite.store.filesdir.child('httpd.log'), hostname=getattr(oldSite, "hostname", None) or u"localhost") installOn(site, site.store) anonymousAvatar = AnonymousSite(store=oldSite.store) installOn(anonymousAvatar, oldSite.store) if couldHavePorts: for tcp in site.store.query(TCPPort, TCPPort.factory == oldSite): tcp.factory = site for ssl in site.store.query(SSLPort, SSLPort.factory == oldSite): ssl.factory = site else: if oldSite.portNumber is not None: port = TCPPort( store=oldSite.store, portNumber=oldSite.portNumber, factory=site) installOn(port, oldSite.store) securePortNumber = oldSite.securePortNumber certificateFile = oldSite.certificateFile if securePortNumber is not None and certificateFile: oldCertPath = site.store.dbdir.preauthChild(certificateFile) newCertPath = site.store.newFilePath('server.pem') oldCertPath.moveTo(newCertPath) port = SSLPort( store=site.store, portNumber=oldSite.securePortNumber, certificatePath=newCertPath, factory=site) installOn(port, site.store) newSite.deleteFromStore()