Example #1
0
 def test_listTwoFactories(self):
     """
     I{axiomatic port list} displays two different factories separately from
     each other.
     """
     store = Store()
     factoryOne = DummyFactory(store=store)
     factoryTwo = DummyFactory(store=store)
     portOne = TCPPort(store=store,
                       factory=factoryOne,
                       portNumber=10,
                       interface=u"foo")
     portTwo = TCPPort(store=store,
                       factory=factoryTwo,
                       portNumber=20,
                       interface=u"bar")
     self.assertSuccessStatus(self._makeConfig(store), ["list"])
     self.assertEqual(
         "%d) %r listening on:\n" % (factoryOne.storeID, factoryOne) +
         "  %d) TCP, interface %s, port %d\n" %
         (portOne.storeID, portOne.interface, portOne.portNumber) +
         "%d) %r listening on:\n" % (factoryTwo.storeID, factoryTwo) +
         "  %d) TCP, interface %s, port %d\n" %
         (portTwo.storeID, portTwo.interface, portTwo.portNumber),
         sys.stdout.getvalue())
Example #2
0
 def test_deletePorts(self):
     """
     I{axiomatic port delete} deletes each ports with a C{storeID} which is
     specified.
     """
     store = Store(filesdir=self.mktemp())
     factory = DummyFactory(store=store)
     deleteTCP = TCPPort(
         store=store, factory=factory, portNumber=10, interface=u"foo")
     keepTCP = TCPPort(
         store=store, factory=factory, portNumber=10, interface=u"bar")
     deleteSSL = SSLPort(
         store=store, factory=factory, portNumber=10, interface=u"baz",
         certificatePath=store.filesdir.child("baz"))
     keepSSL = SSLPort(
         store=store, factory=factory, portNumber=10, interface=u"quux",
         certificatePath=store.filesdir.child("quux"))
     deleteEndpoint = StringEndpointPort(
         store=store, factory=factory, description=u'tcp:1234')
     keepEndpoint = StringEndpointPort(
         store=store, factory=factory, description=u'tcp:1235')
     self.assertSuccessStatus(
         self._makeConfig(store),
         ["delete",
          "--port-identifier", str(deleteTCP.storeID),
          "--port-identifier", str(deleteSSL.storeID),
          "--port-identifier", str(deleteEndpoint.storeID)])
     self.assertEqual("Deleted.\n", sys.stdout.getvalue())
     self.assertEqual(list(store.query(TCPPort)), [keepTCP])
     self.assertEqual(list(store.query(SSLPort)), [keepSSL])
     self.assertEqual(list(store.query(StringEndpointPort)), [keepEndpoint])
Example #3
0
    def installSite(self, siteStore, domain, publicURL, generateCert=True):
        """
        Create the necessary items to run an HTTP server and an SSH server.
        """
        certPath = siteStore.filesdir.child("server.pem")
        if generateCert and not certPath.exists():
            certPath.setContent(self._createCert(domain, genSerial()))

        # Install the base Mantissa offering.
        IOfferingTechnician(siteStore).installOffering(baseOffering)

        # Make the HTTP server baseOffering includes listen somewhere.
        site = siteStore.findUnique(SiteConfiguration)
        site.hostname = domain
        installOn(TCPPort(store=siteStore, factory=site, portNumber=8080),
                  siteStore)
        installOn(
            SSLPort(store=siteStore,
                    factory=site,
                    portNumber=8443,
                    certificatePath=certPath), siteStore)

        # Make the SSH server baseOffering includes listen somewhere.
        shell = siteStore.findUnique(SecureShellConfiguration)
        installOn(TCPPort(store=siteStore, factory=shell, portNumber=8022),
                  siteStore)

        # Install a front page on the top level store so that the
        # developer will have something to look at when they start up
        # the server.
        fp = siteStore.findOrCreate(publicweb.FrontPage, prefixURL=u'')
        installOn(fp, siteStore)
Example #4
0
def pop3listener2to3(oldPOP3):
    """
    Create TCPPort and SSLPort items as appropriate.
    """
    newPOP3 = oldPOP3.upgradeVersion(POP3Listener.typeName,
                                     2,
                                     3,
                                     userbase=oldPOP3.userbase,
                                     certificateFile=oldPOP3.certificateFile)

    if oldPOP3.portNumber is not None:
        port = TCPPort(store=newPOP3.store,
                       portNumber=oldPOP3.portNumber,
                       factory=newPOP3)
        installOn(port, newPOP3.store)

    securePortNumber = oldPOP3.securePortNumber
    certificateFile = oldPOP3.certificateFile
    if securePortNumber is not None and certificateFile:
        oldCertPath = newPOP3.store.dbdir.preauthChild(certificateFile)
        if oldCertPath.exists():
            newCertPath = newPOP3.store.newFilePath('pop3.pem')
            oldCertPath.copyTo(newCertPath)
            port = SSLPort(store=newPOP3.store,
                           portNumber=oldPOP3.securePortNumber,
                           certificatePath=newCertPath,
                           factory=newPOP3)
            installOn(port, newPOP3.store)

    newPOP3.store.powerDown(newPOP3, IService)

    return newPOP3
Example #5
0
    def createPort(self, portNumber, ssl, certPath, factory, interface=u''):
        """
        Create a new listening port.

        @type portNumber: C{int}
        @param portNumber: Port number on which to listen.

        @type ssl: C{bool}
        @param ssl: Indicates whether this should be an SSL port or not.

        @type certPath: C{str}
        @param ssl: If C{ssl} is true, a path to a certificate file somewhere
        within the site store's files directory.  Ignored otherwise.

        @param factory: L{Item} which provides L{IProtocolFactoryFactory} which
        will be used to get a protocol factory to associate with this port.

        @return: C{None}
        """
        store = self.store.parent
        if ssl:
            port = SSLPort(store=store, portNumber=portNumber,
                           certificatePath=FilePath(certPath), factory=factory,
                           interface=interface)
        else:
            port = TCPPort(store=store, portNumber=portNumber, factory=factory,
                           interface=interface)
        installOn(port, store)
Example #6
0
 def test_rootURLNonstandardRequestPort(self):
     """
     L{SiteConfiguration.rootURL} returns C{/} for a request made onto a
     non-standard port which is one on which the L{SiteConfiguration} is
     configured to listen.
     """
     request = FakeRequest(
         headers={'host': '%s:%s' % (self.domain.encode('ascii'), 54321)})
     TCPPort(store=self.store, factory=self.site, portNumber=54321)
     self.assertEqual(self.site.rootURL(request), URL('', ''))
Example #7
0
 def test_listTwoPorts(self):
     """
     I{axiomatic port list} displays two different ports bound to the same
     factory together beneath that factory.
     """
     store = Store()
     factory = DummyFactory(store=store)
     portOne = TCPPort(
         store=store, factory=factory, portNumber=1234, interface=u"foo")
     portTwo = TCPPort(
         store=store, factory=factory, portNumber=2345, interface=u"bar")
     self.assertSuccessStatus(self._makeConfig(store), ["list"])
     self.assertEqual(
         "%d) %r listening on:\n" % (factory.storeID, factory) +
         "  %d) TCP, interface %s, port %d\n" % (
             portOne.storeID, portOne.interface, portOne.portNumber) +
         "  %d) TCP, interface %s, port %d\n" % (
             portTwo.storeID, portTwo.interface, portTwo.portNumber),
         sys.stdout.getvalue())
Example #8
0
 def setUp(self):
     """
     Create a L{Store}, L{WebSite} and necessary request-related objects to
     test L{LoginPage}.
     """
     self.siteStore = Store(filesdir=self.mktemp())
     Mantissa().installSite(self.siteStore, self.domain, u"", False)
     self.site = self.siteStore.findUnique(SiteConfiguration)
     installOn(
         TCPPort(store=self.siteStore, factory=self.site, portNumber=80),
         self.siteStore)
     self.context = WebContext()
     self.request = FakeRequest()
     self.context.remember(self.request)
Example #9
0
 def test_listAnyInterface(self):
     """
     I{axiomatic port list} displays a special string for a port bound to
     C{INADDR_ANY}.
     """
     store = Store()
     factory = DummyFactory(store=store)
     port = TCPPort(
         store=store, factory=factory, portNumber=1234, interface=u"")
     self.assertSuccessStatus(self._makeConfig(store), ["list"])
     self.assertEqual(
         "%d) %r listening on:\n" % (factory.storeID, factory) +
         "  %d) TCP, any interface, port %d\n" % (port.storeID, port.portNumber),
         sys.stdout.getvalue())
Example #10
0
 def test_createNonFactoryIdentifier(self):
     """
     If a storeID which is associated with an item which does not provide
     L{IProtocolFactoryFactory} is given for the C{factory-identifier}
     option of I{axiomatic port create}, a short error is written to
     standard output.
     """
     store = Store()
     storeID = TCPPort(store=store).storeID
     self.assertFailStatus(1, self._makeConfig(store), [
         "create", "--strport", "tcp:8080", "--factory-identifier",
         str(storeID)
     ])
     self.assertEqual("%d does not identify a factory.\n" % (storeID, ),
                      sys.stdout.getvalue())
Example #11
0
 def test_listTCPPort(self):
     """
     When I{axiomatic port list} is invoked for a L{Store} which has a
     L{TCPPort} in it, the details of that port, including its factory, are
     written to stdout.
     """
     store = Store()
     factory = DummyFactory(store=store)
     port = TCPPort(
         store=store, factory=factory, portNumber=1234, interface=u"foo")
     self.assertSuccessStatus(self._makeConfig(store), ["list"])
     self.assertEqual(
         "%d) %r listening on:\n" % (factory.storeID, factory) +
         "  %d) TCP, interface %s, port %d\n" % (
             port.storeID, port.interface, port.portNumber),
         sys.stdout.getvalue())
Example #12
0
def createDatabase(siteStore):
    """
    Populate the given Store with a TCPPort and SSLPort.
    """
    factory = WebSite(store=siteStore)
    installOn(factory, siteStore)
    installOn(TCPPort(store=siteStore, portNumber=TCP_PORT, factory=factory),
              siteStore)
    certificatePath = siteStore.newFilePath('certificate')

    key = KeyPair.generate()
    cert = key.selfSignedCert(1)
    certificatePath.setContent(
        cert.dump(FILETYPE_PEM) + key.dump(FILETYPE_PEM))

    installOn(
        SSLPort(store=siteStore,
                portNumber=SSL_PORT,
                certificatePath=certificatePath,
                factory=factory), siteStore)
Example #13
0
 def test_cannotDeleteOtherStuff(self):
     """
     I{axiomatic port delete} will not delete something which is neither a
     L{TCPPort} nor an L{SSLPort} and does not delete anything if an invalid
     port identifier is present in the command.
     """
     store = Store()
     factory = DummyFactory(store=store)
     tcp = TCPPort(
         store=store, factory=factory, interface=u"foo", portNumber=1234)
     self.assertFailStatus(
         1,
         self._makeConfig(store),
         ["delete",
          "--port-identifier", str(tcp.storeID),
          "--port-identifier", str(factory.storeID)])
     self.assertEqual(
         "%d does not identify a port.\n" % (factory.storeID,),
         sys.stdout.getvalue())
     self.assertEqual(list(store.query(DummyFactory)), [factory])
     self.assertEqual(list(store.query(TCPPort)), [tcp])
Example #14
0
def upgradeMailTransferAgent3to4(oldMTA):
    """
    Create TCPPort and SSLPort items as appropriate.
    """
    if isinstance(oldMTA, MailDeliveryAgent):
        return oldMTA
    newMTA = oldMTA.upgradeVersion(MailTransferAgent.typeName,
                                   3,
                                   4,
                                   userbase=oldMTA.userbase,
                                   certificateFile=oldMTA.certificateFile,
                                   messageCount=oldMTA.messageCount,
                                   domain=oldMTA.domain)

    if oldMTA.portNumber is not None:
        port = TCPPort(store=newMTA.store,
                       portNumber=oldMTA.portNumber,
                       factory=newMTA)
        installOn(port, newMTA.store)

    securePortNumber = oldMTA.securePortNumber
    certificateFile = oldMTA.certificateFile
    if securePortNumber is not None and certificateFile:
        oldCertPath = newMTA.store.dbdir.preauthChild(certificateFile)
        if oldCertPath.exists():
            newCertPath = newMTA.store.newFilePath('mta.pem')
            oldCertPath.copyTo(newCertPath)
            port = SSLPort(store=newMTA.store,
                           portNumber=securePortNumber,
                           certificatePath=newCertPath,
                           factory=newMTA)
            installOn(port, newMTA.store)

    newMTA.store.powerDown(newMTA, IService)

    return newMTA
Example #15
0
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()