コード例 #1
0
def makeService(config, reactor=reactor):
    parent = MultiService()
    basedir = FilePath(os.path.expanduser(config["basedir"]))
    basedir.makedirs(ignoreExistingDirectory=True)
    basedir.chmod(0o700)

    data = Data(basedir.child("config.json"))

    certFile = basedir.child("tub.data").path
    tub = Tub(certFile=certFile)
    tub.setOption("keepaliveTimeout", 60) # ping after 60s of idle
    tub.setOption("disconnectTimeout", 5*60) # disconnect/reconnect after 5m
    tub.listenOn("tcp:6319:interface=127.0.0.1")
    tub.setLocation("tcp:127.0.0.1:6319")
    tub.setServiceParent(parent)

    acme_path = basedir.asTextMode()
    acme_key = maybe_key(acme_path)
    cert_store = FlancerCertificateStore(data, basedir)
    staging = not config["really"]
    if staging:
        print("STAGING mode")
        le_url = LETSENCRYPT_STAGING_DIRECTORY
    else:
        print("REAL CERTIFICATE mode")
        le_url = LETSENCRYPT_DIRECTORY
    client_creator = partial(Client.from_url, reactor=reactor,
                             url=le_url,
                             key=acme_key, alg=RS256)
    r = FlancerResponder(tub, data)
    issuer = AcmeIssuingService(cert_store, client_creator, reactor, [r])
    issuer.setServiceParent(parent)

    if "dyndns_furl" in data:
        start_dyndns_canary(tub, data["dyndns_furl"].encode("ascii"))

    c = Controller(tub, data, issuer)
    tub.registerReference(c, furlFile=basedir.child("controller.furl").path)

    #TimerService(5*60.0, f.timerUpdateStats).setServiceParent(parent)
    return parent
コード例 #2
0
class WebTests(TestCase):

    # XXX: Treq isn't ported yet, so just tie it with the WSGI tests for now
    skip = WSGI_TESTS

    def setUp(self):
        self.cbdir = FilePath(self.mktemp())
        self.cbdir.createDirectory()
        config_extras = DottableDict({
            "node": "testnode",
            "worker": "worker1",
            "cbdir": self.cbdir.path
        })
        self.config = ComponentConfig("realm1", extra=config_extras)

    def test_root_not_required(self):
        """
        Not including a '/' path will mean that path has a 404, but children
        will still be routed correctly.
        """
        temp_reactor = SelectReactor()
        r = router.RouterWorkerSession(config=self.config,
                                       reactor=temp_reactor)

        # Open the transport
        transport = FakeWAMPTransport(r)
        r.onOpen(transport)

        realm_config = {u"name": u"realm1", u'roles': []}

        # Make a file
        self.cbdir.child('file.txt').setContent(b"hello!")

        r.start_router_realm("realm1", realm_config)
        r.start_router_transport(
            "component1", {
                u"type": u"web",
                u"endpoint": {
                    u"type": u"tcp",
                    u"port": 8080
                },
                u"paths": {
                    u"static": {
                        "directory": self.cbdir.asTextMode().path,
                        "type": u"static"
                    }
                }
            })

        # Make a request to the WSGI app.
        d1 = treq.get("http://localhost:8080/", reactor=temp_reactor)
        d1.addCallback(lambda resp: self.assertEqual(resp.code, 404))

        d2 = treq.get("http://localhost:8080/static/file.txt",
                      reactor=temp_reactor)
        d2.addCallback(treq.content)
        d2.addCallback(self.assertEqual, b"hello!")

        def done(results):
            for item in results:
                if not item[0]:
                    raise item[1]

        d = defer.DeferredList([d1, d2])
        d.addCallback(done)
        d.addCallback(lambda _: temp_reactor.stop())

        def escape():
            if temp_reactor.running:
                temp_reactor.stop()

        temp_reactor.callLater(1, escape)
        temp_reactor.run()
コード例 #3
0
class WebTests(TestCase):

    # XXX: Treq isn't ported yet, so just tie it with the WSGI tests for now
    skip = WSGI_TESTS

    def setUp(self):
        self.cbdir = FilePath(self.mktemp())
        self.cbdir.createDirectory()
        config_extras = DottableDict({"node": "testnode",
                                      "worker": "worker1",
                                      "cbdir": self.cbdir.path})
        self.config = ComponentConfig("realm1", extra=config_extras)

    def test_root_not_required(self):
        """
        Not including a '/' path will mean that path has a 404, but children
        will still be routed correctly.
        """
        temp_reactor = SelectReactor()
        r = router.RouterWorkerSession(config=self.config,
                                       reactor=temp_reactor)

        # Open the transport
        transport = FakeWAMPTransport(r)
        r.onOpen(transport)

        realm_config = {
            u"name": u"realm1",
            u'roles': []
        }

        # Make a file
        self.cbdir.child('file.txt').setContent(b"hello!")

        r.start_router_realm("realm1", realm_config)
        r.start_router_transport(
            "component1",
            {
                u"type": u"web",
                u"endpoint": {
                    u"type": u"tcp",
                    u"port": 8080
                },
                u"paths": {
                    u"static": {
                        "directory": self.cbdir.asTextMode().path,
                        "type": u"static"
                    }
                }
            })

        # Make a request to the WSGI app.
        d1 = treq.get("http://localhost:8080/", reactor=temp_reactor)
        d1.addCallback(lambda resp: self.assertEqual(resp.code, 404))

        d2 = treq.get("http://localhost:8080/static/file.txt",
                      reactor=temp_reactor)
        d2.addCallback(treq.content)
        d2.addCallback(self.assertEqual, b"hello!")

        def done(results):
            for item in results:
                if not item[0]:
                    raise item[1]

        d = defer.DeferredList([d1, d2])
        d.addCallback(done)
        d.addCallback(lambda _: temp_reactor.stop())

        def escape():
            if temp_reactor.running:
                temp_reactor.stop()

        temp_reactor.callLater(1, escape)
        temp_reactor.run()