Exemplo n.º 1
0
    def test_furl(self):
        basedir = "introducer.IntroducerNode.test_furl"
        os.mkdir(basedir)
        public_fn = os.path.join(basedir, "introducer.furl")
        private_fn = os.path.join(basedir, "private", "introducer.furl")

        q1 = IntroducerNode(basedir)
        del q1
        # new nodes create unguessable furls in private/introducer.furl
        ifurl = fileutil.read(private_fn)
        self.failUnless(ifurl)
        ifurl = ifurl.strip()
        self.failIf(ifurl.endswith("/introducer"), ifurl)

        # old nodes created guessable furls in BASEDIR/introducer.furl
        guessable = ifurl[:ifurl.rfind("/")] + "/introducer"
        fileutil.write(public_fn, guessable + "\n", mode="w")  # text

        # if we see both files, throw an error
        self.failUnlessRaises(FurlFileConflictError, IntroducerNode, basedir)

        # when we see only the public one, move it to private/ and use
        # the existing furl instead of creating a new one
        os.unlink(private_fn)

        q2 = IntroducerNode(basedir)
        del q2
        self.failIf(os.path.exists(public_fn))
        ifurl2 = fileutil.read(private_fn)
        self.failUnless(ifurl2)
        self.failUnlessEqual(ifurl2.strip(), guessable)
Exemplo n.º 2
0
class IntroducerWeb(unittest.TestCase):
    def setUp(self):
        self.node = None

    def tearDown(self):
        d = defer.succeed(None)
        if self.node:
            d.addCallback(lambda ign: self.node.stopService())
        d.addCallback(flushEventualQueue)
        return d

    @defer.inlineCallbacks
    def test_welcome(self):
        basedir = "web.IntroducerWeb.test_welcome"
        os.mkdir(basedir)
        cfg = "\n".join([
            "[node]",
            "tub.location = 127.0.0.1:1",
            "web.port = tcp:0",
        ]) + "\n"
        fileutil.write(os.path.join(basedir, "tahoe.cfg"), cfg)
        self.node = IntroducerNode(basedir)
        self.ws = self.node.getServiceNamed("webish")

        yield fireEventually(None)
        self.node.startService()

        url = "http://localhost:%d/" % self.ws.getPortnum()
        res = yield do_http("get", url)
        self.failUnlessIn('Welcome to the Tahoe-LAFS Introducer', res)
        self.failUnlessIn(FAVICON_MARKUP, res)
        self.failUnlessIn('Page rendered at', res)
        self.failUnlessIn('Tahoe-LAFS code imported from:', res)
Exemplo n.º 3
0
class IntroducerWeb(unittest.TestCase):
    def setUp(self):
        self.node = None

    def tearDown(self):
        d = defer.succeed(None)
        if self.node:
            d.addCallback(lambda ign: self.node.stopService())
        d.addCallback(flushEventualQueue)
        return d

    @defer.inlineCallbacks
    def test_welcome(self):
        config = ("[node]\n"
                  "tub.location = 127.0.0.1:1\n"
                  "web.port = tcp:0\n")
        from allmydata.node import config_from_string
        self.node = IntroducerNode(
            config_from_string(config, portnumfile="introducer.port"), )
        self.ws = self.node.getServiceNamed("webish")

        yield fireEventually(None)
        self.node.startService()

        url = "http://localhost:%d/" % self.ws.getPortnum()
        res = yield do_http("get", url)
        self.failUnlessIn('Welcome to the Tahoe-LAFS Introducer', res)
        self.failUnlessIn(FAVICON_MARKUP, res)
        self.failUnlessIn('Page rendered at', res)
        self.failUnlessIn('Tahoe-LAFS code imported from:', res)
Exemplo n.º 4
0
    def test_welcome(self):
        basedir = "web.IntroducerWeb.test_welcome"
        os.mkdir(basedir)
        cfg = "\n".join([
            "[node]",
            "tub.location = 127.0.0.1:1",
            "web.port = tcp:0",
        ]) + "\n"
        fileutil.write(os.path.join(basedir, "tahoe.cfg"), cfg)
        self.node = IntroducerNode(basedir)
        self.ws = self.node.getServiceNamed("webish")

        d = fireEventually(None)
        d.addCallback(lambda ign: self.node.startService())

        d.addCallback(lambda ign: self.GET("/"))

        def _check(res):
            self.failUnlessIn('Welcome to the Tahoe-LAFS Introducer', res)
            self.failUnlessIn(FAVICON_MARKUP, res)
            self.failUnlessIn('Page rendered at', res)
            self.failUnlessIn('Tahoe-LAFS code imported from:', res)

        d.addCallback(_check)
        return d
Exemplo n.º 5
0
class IntroducerWeb(unittest.TestCase):
    def setUp(self):
        self.node = None

    def tearDown(self):
        d = defer.succeed(None)
        if self.node:
            d.addCallback(lambda ign: self.node.stopService())
        d.addCallback(flushEventualQueue)
        return d

    def test_welcome(self):
        basedir = "web.IntroducerWeb.test_welcome"
        os.mkdir(basedir)
        cfg = "\n".join([
            "[node]",
            "tub.location = 127.0.0.1:1",
            "web.port = tcp:0",
        ]) + "\n"
        fileutil.write(os.path.join(basedir, "tahoe.cfg"), cfg)
        self.node = IntroducerNode(basedir)
        self.ws = self.node.getServiceNamed("webish")

        d = fireEventually(None)
        d.addCallback(lambda ign: self.node.startService())

        d.addCallback(lambda ign: self.GET("/"))

        def _check(res):
            self.failUnlessIn('Welcome to the Tahoe-LAFS Introducer', res)
            self.failUnlessIn(FAVICON_MARKUP, res)
            self.failUnlessIn('Page rendered at', res)
            self.failUnlessIn('Tahoe-LAFS code imported from:', res)

        d.addCallback(_check)
        return d

    def GET(self,
            urlpath,
            followRedirect=False,
            return_response=False,
            **kwargs):
        # if return_response=True, this fires with (data, statuscode,
        # respheaders) instead of just data.
        assert not isinstance(urlpath, unicode)
        url = self.ws.getURL().rstrip('/') + urlpath
        factory = HTTPClientGETFactory(url,
                                       method="GET",
                                       followRedirect=followRedirect,
                                       **kwargs)
        reactor.connectTCP("localhost", self.ws.getPortnum(), factory)
        d = factory.deferred

        def _got_data(data):
            return (data, factory.status, factory.response_headers)

        if return_response:
            d.addCallback(_got_data)
        return factory.deferred
Exemplo n.º 6
0
 def test_loadable(self):
     basedir = "introducer.IntroducerNode.test_loadable"
     os.mkdir(basedir)
     q = IntroducerNode(basedir)
     d = fireEventually(None)
     d.addCallback(lambda res: q.startService())
     d.addCallback(lambda res: q.when_tub_ready())
     d.addCallback(lambda res: q.stopService())
     d.addCallback(flushEventualQueue)
     return d
Exemplo n.º 7
0
 def test_loadable(self):
     basedir = "introducer.IntroducerNode.test_loadable"
     os.mkdir(basedir)
     q = IntroducerNode(basedir)
     d = fireEventually(None)
     d.addCallback(lambda res: q.startService())
     d.addCallback(lambda res: q.when_tub_ready())
     d.addCallback(lambda res: q.stopService())
     d.addCallback(flushEventualQueue)
     return d
Exemplo n.º 8
0
 def test_web_static(self):
     basedir = u"introducer.Node.test_web_static"
     os.mkdir(basedir)
     fileutil.write(os.path.join(basedir, "tahoe.cfg"),
                    "[node]\n" +
                    "web.port = tcp:0:interface=127.0.0.1\n" +
                    "web.static = relative\n")
     c = IntroducerNode(basedir)
     w = c.getServiceNamed("webish")
     abs_basedir = fileutil.abspath_expanduser_unicode(basedir)
     expected = fileutil.abspath_expanduser_unicode(u"relative", abs_basedir)
     self.failUnlessReallyEqual(w.staticdir, expected)
Exemplo n.º 9
0
 def test_web_static(self):
     basedir = u"introducer.Node.test_web_static"
     os.mkdir(basedir)
     fileutil.write(
         os.path.join(basedir, "tahoe.cfg"),
         "[node]\n" + "web.port = tcp:0:interface=127.0.0.1\n" +
         "web.static = relative\n")
     c = IntroducerNode(basedir)
     w = c.getServiceNamed("webish")
     abs_basedir = fileutil.abspath_expanduser_unicode(basedir)
     expected = fileutil.abspath_expanduser_unicode(u"relative",
                                                    abs_basedir)
     self.failUnlessReallyEqual(w.staticdir, expected)
Exemplo n.º 10
0
class IntroducerWeb(unittest.TestCase):
    def setUp(self):
        self.node = None

    def tearDown(self):
        d = defer.succeed(None)
        if self.node:
            d.addCallback(lambda ign: self.node.stopService())
        d.addCallback(flushEventualQueue)
        return d

    def test_welcome(self):
        basedir = "web.IntroducerWeb.test_welcome"
        os.mkdir(basedir)
        cfg = "\n".join(["[node]",
                         "tub.location = 127.0.0.1:1",
                         "web.port = tcp:0",
                         ]) + "\n"
        fileutil.write(os.path.join(basedir, "tahoe.cfg"), cfg)
        self.node = IntroducerNode(basedir)
        self.ws = self.node.getServiceNamed("webish")

        d = fireEventually(None)
        d.addCallback(lambda ign: self.node.startService())

        d.addCallback(lambda ign: self.GET("/"))
        def _check(res):
            self.failUnlessIn('Welcome to the Tahoe-LAFS Introducer', res)
            self.failUnlessIn(FAVICON_MARKUP, res)
            self.failUnlessIn('Page rendered at', res)
            self.failUnlessIn('Tahoe-LAFS code imported from:', res)
        d.addCallback(_check)
        return d

    def GET(self, urlpath, followRedirect=False, return_response=False,
            **kwargs):
        # if return_response=True, this fires with (data, statuscode,
        # respheaders) instead of just data.
        assert not isinstance(urlpath, unicode)
        url = self.ws.getURL().rstrip('/') + urlpath
        factory = HTTPClientGETFactory(url, method="GET",
                                       followRedirect=followRedirect, **kwargs)
        reactor.connectTCP("localhost", self.ws.getPortnum(), factory)
        d = factory.deferred
        def _got_data(data):
            return (data, factory.status, factory.response_headers)
        if return_response:
            d.addCallback(_got_data)
        return factory.deferred
Exemplo n.º 11
0
    def test_welcome(self):
        config = ("[node]\n"
                  "tub.location = 127.0.0.1:1\n"
                  "web.port = tcp:0\n")
        from allmydata.node import config_from_string
        self.node = IntroducerNode(
            config_from_string(config, portnumfile="introducer.port"), )
        self.ws = self.node.getServiceNamed("webish")

        yield fireEventually(None)
        self.node.startService()

        url = "http://localhost:%d/" % self.ws.getPortnum()
        res = yield do_http("get", url)
        self.failUnlessIn('Welcome to the Tahoe-LAFS Introducer', res)
        self.failUnlessIn(FAVICON_MARKUP, res)
        self.failUnlessIn('Page rendered at', res)
        self.failUnlessIn('Tahoe-LAFS code imported from:', res)
Exemplo n.º 12
0
    def test_welcome(self):
        basedir = "web.IntroducerWeb.test_welcome"
        os.mkdir(basedir)
        cfg = "\n".join([
            "[node]",
            "tub.location = 127.0.0.1:1",
            "web.port = tcp:0",
        ]) + "\n"
        fileutil.write(os.path.join(basedir, "tahoe.cfg"), cfg)
        self.node = IntroducerNode(basedir)
        self.ws = self.node.getServiceNamed("webish")

        yield fireEventually(None)
        self.node.startService()

        url = "http://localhost:%d/" % self.ws.getPortnum()
        res = yield do_http("get", url)
        self.failUnlessIn('Welcome to the Tahoe-LAFS Introducer', res)
        self.failUnlessIn(FAVICON_MARKUP, res)
        self.failUnlessIn('Page rendered at', res)
        self.failUnlessIn('Tahoe-LAFS code imported from:', res)
Exemplo n.º 13
0
    def test_welcome(self):
        basedir = "web.IntroducerWeb.test_welcome"
        os.mkdir(basedir)
        cfg = "\n".join(["[node]",
                         "tub.location = 127.0.0.1:1",
                         "web.port = tcp:0",
                         ]) + "\n"
        fileutil.write(os.path.join(basedir, "tahoe.cfg"), cfg)
        self.node = IntroducerNode(basedir)
        self.ws = self.node.getServiceNamed("webish")

        d = fireEventually(None)
        d.addCallback(lambda ign: self.node.startService())

        d.addCallback(lambda ign: self.GET("/"))
        def _check(res):
            self.failUnlessIn('Welcome to the Tahoe-LAFS Introducer', res)
            self.failUnlessIn(FAVICON_MARKUP, res)
            self.failUnlessIn('Page rendered at', res)
            self.failUnlessIn('Tahoe-LAFS code imported from:', res)
        d.addCallback(_check)
        return d