Ejemplo n.º 1
0
    def testhandle_dir_abstracts(self):
        proto = GopherProtocol("", self.server, self.handler, self.rfile,
                               self.wfile, self.config)
        proto.handle()
        self.assertEquals(proto.selector, '/')
        self.assertEquals(self.logfile.getvalue(),
                          "10.77.77.77 [GopherProtocol/UMNDirHandler]: /\n")
        # Try to make this easy on us to fix.
        actualarr = self.wfile.getvalue().splitlines()
        expectedarr = [
'iThis is the abstract for the testdata directory.\tfake\t(NULL)\t0',
'0README\t/README\tHOSTNAME\t64777\t+',
'1pygopherd\t/pygopherd\tHOSTNAME\t64777\t+',
'9symlinktest\t/symlinktest.zip\tHOSTNAME\t64777\t+',
'9testarchive\t/testarchive.tar\tHOSTNAME\t64777\t+',
'9testarchive.tar.gz\t/testarchive.tar.gz\tHOSTNAME\t64777\t+',
'9testarchive.tgz\t/testarchive.tgz\tHOSTNAME\t64777\t+',
'9testdata\t/testdata.zip\tHOSTNAME\t64777\t+',
'9testdata2\t/testdata2.zip\tHOSTNAME\t64777\t+',
'0testfile\t/testfile.txt\tHOSTNAME\t64777\t+',
'9testfile.txt.gz\t/testfile.txt.gz\tHOSTNAME\t64777\t+',
'iThis is the abstract\tfake\t(NULL)\t0',
'ifor testfile.txt.gz\tfake\t(NULL)\t0',
'9ziptorture\t/ziptorture.zip\tHOSTNAME\t64777\t+']
        expectedarr = [re.sub('HOSTNAME', self.server.server_name, x) for \
                      x in expectedarr]
        self.assertEquals(len(actualarr), len(expectedarr), str(actualarr))
        for i in range(len(actualarr)):
            self.assertEquals(actualarr[i], expectedarr[i])
        # Make sure proper line endings are present.
        self.assertEquals("\r\n".join(actualarr) + "\r\n", self.wfile.getvalue())
Ejemplo n.º 2
0
 def testhandle_dir_abstracts(self):
     proto = GopherProtocol("", self.server, self.handler, self.rfile,
                            self.wfile, self.config)
     proto.handle()
     self.assertEqual(proto.selector, '/')
     self.assertEqual(self.logfile.getvalue(),
                      "10.77.77.77 [GopherProtocol/UMNDirHandler]: /\n")
     # Try to make this easy on us to fix.
     actualarr = self.wfile.getvalue().decode('ascii').splitlines()
     expectedarr = [
         'iThis is the abstract for the testdata directory.\tfake\t(NULL)\t0',
         '0README\t/README\tHOSTNAME\t64777\t+',
         '1pygopherd\t/pygopherd\tHOSTNAME\t64777\t+',
         '9symlinktest\t/symlinktest.zip\tHOSTNAME\t64777\t+',
         '9testarchive\t/testarchive.tar\tHOSTNAME\t64777\t+',
         '9testarchive.tar.gz\t/testarchive.tar.gz\tHOSTNAME\t64777\t+',
         '9testarchive.tgz\t/testarchive.tgz\tHOSTNAME\t64777\t+',
         '9testdata\t/testdata.zip\tHOSTNAME\t64777\t+',
         '9testdata2\t/testdata2.zip\tHOSTNAME\t64777\t+',
         '0testfile\t/testfile.txt\tHOSTNAME\t64777\t+',
         '9testfile.txt.gz\t/testfile.txt.gz\tHOSTNAME\t64777\t+',
         'iThis is the abstract\tfake\t(NULL)\t0',
         'ifor testfile.txt.gz\tfake\t(NULL)\t0',
         '9ziptorture\t/ziptorture.zip\tHOSTNAME\t64777\t+'
     ]
     expectedarr = [re.sub('HOSTNAME', self.server.server_name, x) for \
                   x in expectedarr]
     self.assertEqual(len(actualarr), len(expectedarr), str(actualarr))
     for i in range(len(actualarr)):
         self.assertEqual(actualarr[i], expectedarr[i])
     # Make sure proper line endings are present.
     self.assertEqual("\r\n".join(actualarr) + "\r\n",
                      self.wfile.getvalue())
Ejemplo n.º 3
0
 def testcanhandlerequest(self):
     assert self.proto.canhandlerequest()
     proto = GopherProtocol("/testfile.txt\tsearch\n",
                            self.server, self.handler, self.rfile,
                            self.wfile, self.config)
     assert proto.canhandlerequest()
     self.assertEquals(proto.selector, '/testfile.txt')
     self.assertEquals(proto.searchrequest, "search")
Ejemplo n.º 4
0
 def testcanhandlerequest(self):
     assert self.proto.canhandlerequest()
     proto = GopherProtocol("/testfile.txt\tsearch\n", self.server,
                            self.handler, self.rfile, self.wfile,
                            self.config)
     assert proto.canhandlerequest()
     self.assertEqual(proto.selector, '/testfile.txt')
     self.assertEqual(proto.searchrequest, "search")
Ejemplo n.º 5
0
 def setUp(self):
     self.config = testutil.getconfig()
     self.rfile = BytesIO(b"/testfile.txt\n")
     self.wfile = BytesIO()
     self.logfile = testutil.getstringlogger()
     self.handler = testutil.gettestinghandler(self.rfile, self.wfile,
                                               self.config)
     self.server = self.handler.server
     self.proto = GopherProtocol("/testfile.txt\n", self.server,
                                 self.handler, self.rfile, self.wfile,
                                 self.config)
Ejemplo n.º 6
0
    def testhandle_file_zipped(self):
        self.config.set("handlers.ZIP.ZIPHandler", "enabled", "true")
        self.inject_handler("ZIP.ZIPHandler", index=0)

        self.proto = GopherProtocol(
            "/testdata.zip/pygopherd/ziponly\n",
            self.server,
            self.handler,
            self.rfile,
            self.wfile,
            self.config,
        )
        self.proto.handle()
        self.assertEqual(self.wfile.getvalue(), b"ZIPonly\n")
        self.config.set("handlers.ZIP.ZIPHandler", "enabled", "false")
Ejemplo n.º 7
0
 def testhandle_file_zipped(self):
     self.config.set("handlers.ZIP.ZIPHandler", "enabled", 'true')
     from pygopherd.handlers import HandlerMultiplexer
     HandlerMultiplexer.handlers = None
     handlerlist = self.config.get("handlers.HandlerMultiplexer",
                                   "handlers")
     handlerlist = handlerlist.strip()
     handlerlist = handlerlist[0] + 'ZIP.ZIPHandler, ' + handlerlist[1:]
     self.config.set("handlers.HandlerMultiplexer", "handlers", handlerlist)
     self.proto = GopherProtocol("/testdata.zip/pygopherd/ziponly\n",
                                 self.server, self.handler, self.rfile,
                                 self.wfile, self.config)
     self.proto.handle()
     self.assertEqual(self.wfile.getvalue(), b"ZIPonly\n")
     self.config.set("handlers.ZIP.ZIPHandler", "enabled", "false")
Ejemplo n.º 8
0
 def testopen3(self):
     from pygopherd.protocols.rfc1436 import GopherProtocol
     self.proto = GopherProtocol("/foo.zip/www/apache2-default/manual/platforms/index.html\n",
                                 self.server,
                                 self.handler, self.rfile, self.wfile,
                                 self.config)
     self.proto.handle()
Ejemplo n.º 9
0
 def testopen2(self):
     from pygopherd.protocols.rfc1436 import GopherProtocol
     self.proto = GopherProtocol("/foo.zip/games/bsdgames/snake.log\n",
                                 self.server,
                                 self.handler, self.rfile, self.wfile,
                                 self.config)
     self.proto.handle()
Ejemplo n.º 10
0
 def testopen1(self):
     from pygopherd.protocols.rfc1436 import GopherProtocol
     self.proto = GopherProtocol("/foo.zip/lib/dpkg/info/dpkg.list\n",
                                 self.server,
                                 self.handler, self.rfile, self.wfile,
                                 self.config)
     self.proto.handle()
Ejemplo n.º 11
0
 def testlistdir2(self):
     from pygopherd.protocols.rfc1436 import GopherProtocol
     self.proto = GopherProtocol("/foo.zip/lib\n",
                                 self.server,
                                 self.handler, self.rfile, self.wfile,
                                 self.config)
     self.proto.handle()
Ejemplo n.º 12
0
    def testhandle_dir_noabstract(self):
        self.config.set("pygopherd", "abstract_headers", "off")
        self.config.set("pygopherd", "abstract_entries", "off")
        proto = GopherProtocol("", self.server, self.handler, self.rfile,
                               self.wfile, self.config)
        proto.handle()
        actuallines = (self.wfile.getvalue().decode(
            errors="surrogateescape").splitlines())
        expectedlines = [
            "iThis is the abstract for the testdata directory.\tfake\t(NULL)\t0",
            "iThis is the abstract\tfake\t(NULL)\t0",
            "ifor testfile.txt.gz\tfake\t(NULL)\t0",
        ]

        for line in expectedlines:
            self.assertNotIn(line, actuallines)
Ejemplo n.º 13
0
 def renderobjinfo(self, entry):
     if entry.getmimetype("FAKE") == "application/gopher-menu" and entry.getgopherpsupport():
         entry.mimetype = "application/gopher+-menu"
     if self.handlemethod == "documentonly":
         # It's a Gopher+ request for a gopher0 menu entry.
         retstr = GopherProtocol.renderobjinfo(self, entry)
         return retstr
     else:
         return self.getallblocks(entry)
Ejemplo n.º 14
0
 def renderobjinfo(self, entry):
     if entry.getmimetype('FAKE') == 'application/gopher-menu' and \
            entry.getgopherpsupport():
         entry.mimetype = 'application/gopher+-menu'
     if self.handlemethod == 'documentonly':
         # It's a Gopher+ request for a gopher0 menu entry.
         retstr = GopherProtocol.renderobjinfo(self, entry)
         return retstr
     else:
         return self.getallblocks(entry)
Ejemplo n.º 15
0
 def setUp(self):
     self.config = testutil.getconfig()
     self.rfile = StringIO("/testfile.txt\n")
     self.wfile = StringIO()
     self.logfile = testutil.getstringlogger()
     self.handler = testutil.gettestinghandler(self.rfile, self.wfile,
                                               self.config)
     self.server = self.handler.server
     self.proto = GopherProtocol("/testfile.txt\n", self.server,
                                 self.handler, self.rfile, self.wfile,
                                 self.config)
Ejemplo n.º 16
0
 def setUp(self):
     from pygopherd import testutil
     from pygopherd.protocols.rfc1436 import GopherProtocol
     self.config = testutil.getconfig()
     self.rfile = StringIO("/testfile.txt\n")
     self.wfile = StringIO()
     self.logfile = testutil.getstringlogger()
     self.handler = testutil.gettestinghandler(self.rfile, self.wfile,
                                               self.config)
     self.server = self.handler.server
     self.proto = GopherProtocol("/testfile.txt\n", self.server,
                                 self.handler, self.rfile, self.wfile,
                                 self.config)
     self.config.set("handlers.ZIP.ZIPHandler", "enabled", 'true')
     from pygopherd.handlers import HandlerMultiplexer
     HandlerMultiplexer.handlers = None
     handlerlist = self.config.get("handlers.HandlerMultiplexer",
                                   "handlers")
     handlerlist = handlerlist.strip()
     handlerlist = handlerlist[0] + 'ZIP.ZIPHandler, ' + handlerlist[1:]
     self.config.set("handlers.HandlerMultiplexer", "handlers", handlerlist)
Ejemplo n.º 17
0
 def renderobjinfo(self, entry):
     if (
         entry.getmimetype("FAKE") == "application/gopher-menu"
         and entry.getgopherpsupport()
     ):
         entry.mimetype = "application/gopher+-menu"
     if self.handlemethod == "documentonly":
         # It's a Gopher+ request for a gopher0 menu entry.
         retstr = GopherProtocol.renderobjinfo(self, entry)
         return retstr
     else:
         return self.getallblocks(entry)
Ejemplo n.º 18
0
 def testhandle_dir_noabstract(self):
     self.config.set("pygopherd", "abstract_headers", "off")
     self.config.set("pygopherd", "abstract_entries", "off")
     proto = GopherProtocol("", self.server, self.handler, self.rfile,
                            self.wfile, self.config)
     proto.handle()
     actualarr = self.wfile.getvalue().splitlines()
     expectedarr = \
          ['0README\t/README\tHOSTNAME\t64777\t+',
           '1pygopherd\t/pygopherd\tHOSTNAME\t64777\t+',
           '9symlinktest\t/symlinktest.zip\tHOSTNAME\t64777\t+',
           '9testarchive\t/testarchive.tar\tHOSTNAME\t64777\t+',
           '9testarchive.tar.gz\t/testarchive.tar.gz\tHOSTNAME\t64777\t+',
           '9testarchive.tgz\t/testarchive.tgz\tHOSTNAME\t64777\t+',
           '9testdata\t/testdata.zip\tHOSTNAME\t64777\t+',
           '9testdata2\t/testdata2.zip\tHOSTNAME\t64777\t+',
           '0testfile\t/testfile.txt\tHOSTNAME\t64777\t+',
           '9testfile.txt.gz\t/testfile.txt.gz\tHOSTNAME\t64777\t+',
           '9ziptorture\t/ziptorture.zip\tHOSTNAME\t64777\t+']
     expectedarr = [re.sub('HOSTNAME', self.server.server_name, x) for \
                    x in expectedarr]
     self.assertEquals(len(actualarr), len(expectedarr))
     for i in range(len(actualarr)):
         self.assertEquals(actualarr[i], expectedarr[i])
Ejemplo n.º 19
0
    def testhandle_dir_abstracts(self):
        proto = GopherProtocol("", self.server, self.handler, self.rfile,
                               self.wfile, self.config)
        proto.handle()
        self.assertEqual(proto.selector, "/")
        self.assertEqual(self.logfile.getvalue(),
                         "10.77.77.77 [GopherProtocol/UMNDirHandler]: /\n")
        # Try to make this easy on us to fix.
        actuallines = (self.wfile.getvalue().decode(
            errors="surrogateescape").splitlines())
        expectedlines = [
            "iThis is the abstract for the testdata directory.\tfake\t(NULL)\t0",
            "iThis is the abstract\tfake\t(NULL)\t0",
            "ifor testfile.txt.gz\tfake\t(NULL)\t0",
        ]

        for line in expectedlines:
            self.assertIn(line, actuallines)

        # Make sure proper line endings are present.
        self.assertEqual(
            "\r\n".join(actuallines) + "\r\n",
            self.wfile.getvalue().decode(errors="surrogateescape"),
        )
Ejemplo n.º 20
0
 def testhandle_file_zipped(self):
     self.config.set("handlers.ZIP.ZIPHandler", "enabled", 'true')
     from pygopherd.handlers import HandlerMultiplexer
     HandlerMultiplexer.handlers = None
     handlerlist = self.config.get("handlers.HandlerMultiplexer", "handlers")
     handlerlist = handlerlist.strip()
     handlerlist = handlerlist[0] + 'ZIP.ZIPHandler, ' + handlerlist[1:]
     self.config.set("handlers.HandlerMultiplexer", "handlers", handlerlist)
     self.proto = GopherProtocol("/testdata.zip/pygopherd/ziponly\n",
                                 self.server,
                                 self.handler, self.rfile, self.wfile,
                                 self.config)
     self.proto.handle()
     self.assertEquals(self.wfile.getvalue(), "ZIPonly\n")
     self.config.set("handlers.ZIP.ZIPHandler", "enabled", "false")
Ejemplo n.º 21
0
 def testhandle_dir_noabstract(self):
     self.config.set("pygopherd", "abstract_headers", "off")
     self.config.set("pygopherd", "abstract_entries", "off")
     proto = GopherProtocol("", self.server, self.handler, self.rfile,
                            self.wfile, self.config)
     proto.handle()
     actualarr = self.wfile.getvalue().splitlines()
     expectedarr = \
          ['0README\t/README\tHOSTNAME\t64777\t+',
           '1pygopherd\t/pygopherd\tHOSTNAME\t64777\t+',
           '9symlinktest\t/symlinktest.zip\tHOSTNAME\t64777\t+',
           '9testarchive\t/testarchive.tar\tHOSTNAME\t64777\t+',
           '9testarchive.tar.gz\t/testarchive.tar.gz\tHOSTNAME\t64777\t+',
           '9testarchive.tgz\t/testarchive.tgz\tHOSTNAME\t64777\t+',
           '9testdata\t/testdata.zip\tHOSTNAME\t64777\t+',
           '9testdata2\t/testdata2.zip\tHOSTNAME\t64777\t+',
           '0testfile\t/testfile.txt\tHOSTNAME\t64777\t+',
           '9testfile.txt.gz\t/testfile.txt.gz\tHOSTNAME\t64777\t+',
           '9ziptorture\t/ziptorture.zip\tHOSTNAME\t64777\t+']
     expectedarr = [re.sub('HOSTNAME', self.server.server_name, x) for \
                    x in expectedarr]
     self.assertEqual(len(actualarr), len(expectedarr))
     for i in range(len(actualarr)):
         self.assertEqual(actualarr[i], expectedarr[i])
Ejemplo n.º 22
0
 def setUp(self):
     from pygopherd import testutil
     from pygopherd.protocols.rfc1436 import GopherProtocol
     self.config = testutil.getconfig()
     self.rfile = StringIO("/testfile.txt\n")
     self.wfile = StringIO()
     self.logfile = testutil.getstringlogger()
     self.handler = testutil.gettestinghandler(self.rfile, self.wfile,
                                               self.config)
     self.server = self.handler.server
     self.proto = GopherProtocol("/testfile.txt\n", self.server,
                                 self.handler, self.rfile, self.wfile,
                                 self.config)
     self.config.set("handlers.ZIP.ZIPHandler", "enabled", 'true')
     from pygopherd.handlers import HandlerMultiplexer
     HandlerMultiplexer.handlers = None
     handlerlist = self.config.get("handlers.HandlerMultiplexer", "handlers")
     handlerlist = handlerlist.strip()
     handlerlist = handlerlist[0] + 'ZIP.ZIPHandler, ' + handlerlist[1:]
     self.config.set("handlers.HandlerMultiplexer", "handlers", handlerlist)
Ejemplo n.º 23
0
 def testlistdir2(self):
     from pygopherd.protocols.rfc1436 import GopherProtocol
     self.proto = GopherProtocol("/foo.zip/lib\n", self.server,
                                 self.handler, self.rfile, self.wfile,
                                 self.config)
     self.proto.handle()
Ejemplo n.º 24
0
 def getinfoblock(self, entry):
     return "+INFO: " + \
            GopherProtocol.renderobjinfo(self, entry)
Ejemplo n.º 25
0
class RFC1436TestCase(unittest.TestCase):
    def setUp(self):
        self.config = testutil.get_config()
        self.rfile = BytesIO(b"/testfile.txt\n")
        self.wfile = BytesIO()
        self.logfile = testutil.get_string_logger()
        self.handler = testutil.get_testing_handler(self.rfile, self.wfile,
                                                    self.config)
        self.server = self.handler.server
        self.proto = GopherProtocol(
            "/testfile.txt\n",
            self.server,
            self.handler,
            self.rfile,
            self.wfile,
            self.config,
        )

    def inject_handler(self,
                       handler_name: str,
                       index: typing.Optional[int] = None):
        """
        Add a handler to the HandlerMultiplexer in the configuration.
        """
        handlerlist = self.config.get("handlers.HandlerMultiplexer",
                                      "handlers")
        handlers = [x.strip() for x in handlerlist.strip("[] \n").split(",")]
        if index is not None:
            handlers.insert(index, handler_name)
        else:
            handlers.append(handler_name)

        handlerlist = "[" + ",".join(handlers) + "]"
        self.config.set("handlers.HandlerMultiplexer", "handlers", handlerlist)

        # Clear the cache
        HandlerMultiplexer.handlers = None

    def testcanhandlerequest(self):
        assert self.proto.canhandlerequest()
        proto = GopherProtocol(
            "/testfile.txt\tsearch\n",
            self.server,
            self.handler,
            self.rfile,
            self.wfile,
            self.config,
        )
        assert proto.canhandlerequest()
        self.assertEqual(proto.selector, "/testfile.txt")
        self.assertEqual(proto.searchrequest, "search")

    def testrenderobjinfo(self):
        expected = "0testfile.txt\t/testfile.txt\t%s\t%d\t+\r\n" % (
            self.server.server_name,
            self.server.server_port,
        )
        self.assertEqual(
            self.proto.renderobjinfo(self.proto.gethandler().getentry()),
            expected)

    def testhandle_file(self):
        self.proto.handle()
        self.assertEqual(
            self.logfile.getvalue(),
            "10.77.77.77 [GopherProtocol/FileHandler]: /testfile.txt\n",
        )
        self.assertEqual(self.wfile.getvalue(), b"Test\n")

    def testhandle_file_zipped(self):
        self.config.set("handlers.ZIP.ZIPHandler", "enabled", "true")
        self.inject_handler("ZIP.ZIPHandler", index=0)

        self.proto = GopherProtocol(
            "/testdata.zip/pygopherd/ziponly\n",
            self.server,
            self.handler,
            self.rfile,
            self.wfile,
            self.config,
        )
        self.proto.handle()
        self.assertEqual(self.wfile.getvalue(), b"ZIPonly\n")
        self.config.set("handlers.ZIP.ZIPHandler", "enabled", "false")

    def testhandle_dir_abstracts(self):
        proto = GopherProtocol("", self.server, self.handler, self.rfile,
                               self.wfile, self.config)
        proto.handle()
        self.assertEqual(proto.selector, "/")
        self.assertEqual(self.logfile.getvalue(),
                         "10.77.77.77 [GopherProtocol/UMNDirHandler]: /\n")
        # Try to make this easy on us to fix.
        actuallines = (self.wfile.getvalue().decode(
            errors="surrogateescape").splitlines())
        expectedlines = [
            "iThis is the abstract for the testdata directory.\tfake\t(NULL)\t0",
            "iThis is the abstract\tfake\t(NULL)\t0",
            "ifor testfile.txt.gz\tfake\t(NULL)\t0",
        ]

        for line in expectedlines:
            self.assertIn(line, actuallines)

        # Make sure proper line endings are present.
        self.assertEqual(
            "\r\n".join(actuallines) + "\r\n",
            self.wfile.getvalue().decode(errors="surrogateescape"),
        )

    def testhandle_dir_noabstract(self):
        self.config.set("pygopherd", "abstract_headers", "off")
        self.config.set("pygopherd", "abstract_entries", "off")
        proto = GopherProtocol("", self.server, self.handler, self.rfile,
                               self.wfile, self.config)
        proto.handle()
        actuallines = (self.wfile.getvalue().decode(
            errors="surrogateescape").splitlines())
        expectedlines = [
            "iThis is the abstract for the testdata directory.\tfake\t(NULL)\t0",
            "iThis is the abstract\tfake\t(NULL)\t0",
            "ifor testfile.txt.gz\tfake\t(NULL)\t0",
        ]

        for line in expectedlines:
            self.assertNotIn(line, actuallines)
Ejemplo n.º 26
0
class RFC1436TestCase(unittest.TestCase):
    def setUp(self):
        self.config = testutil.getconfig()
        self.rfile = StringIO("/testfile.txt\n")
        self.wfile = StringIO()
        self.logfile = testutil.getstringlogger()
        self.handler = testutil.gettestinghandler(self.rfile, self.wfile,
                                                  self.config)
        self.server = self.handler.server
        self.proto = GopherProtocol("/testfile.txt\n", self.server,
                                    self.handler, self.rfile, self.wfile,
                                    self.config)

    def testcanhandlerequest(self):
        assert self.proto.canhandlerequest()
        proto = GopherProtocol("/testfile.txt\tsearch\n",
                               self.server, self.handler, self.rfile,
                               self.wfile, self.config)
        assert proto.canhandlerequest()
        self.assertEquals(proto.selector, '/testfile.txt')
        self.assertEquals(proto.searchrequest, "search")

    def testrenderobjinfo(self):
        expected = "0testfile.txt\t/testfile.txt\t%s\t%d\t+\r\n" % \
                   (self.server.server_name, self.server.server_port)
        self.assertEquals(self.proto.renderobjinfo(self.proto.gethandler().getentry()),
                          expected)

    def testhandle_file(self):
        self.proto.handle()
        self.assertEquals(self.logfile.getvalue(),
                          "10.77.77.77 [GopherProtocol/FileHandler]: /testfile.txt\n")
        self.assertEquals(self.wfile.getvalue(), "Test\n")

    def testhandle_file_zipped(self):
        self.config.set("handlers.ZIP.ZIPHandler", "enabled", 'true')
        from pygopherd.handlers import HandlerMultiplexer
        HandlerMultiplexer.handlers = None
        handlerlist = self.config.get("handlers.HandlerMultiplexer", "handlers")
        handlerlist = handlerlist.strip()
        handlerlist = handlerlist[0] + 'ZIP.ZIPHandler, ' + handlerlist[1:]
        self.config.set("handlers.HandlerMultiplexer", "handlers", handlerlist)
        self.proto = GopherProtocol("/testdata.zip/pygopherd/ziponly\n",
                                    self.server,
                                    self.handler, self.rfile, self.wfile,
                                    self.config)
        self.proto.handle()
        self.assertEquals(self.wfile.getvalue(), "ZIPonly\n")
        self.config.set("handlers.ZIP.ZIPHandler", "enabled", "false")

    def testhandle_dir_abstracts(self):
        proto = GopherProtocol("", self.server, self.handler, self.rfile,
                               self.wfile, self.config)
        proto.handle()
        self.assertEquals(proto.selector, '/')
        self.assertEquals(self.logfile.getvalue(),
                          "10.77.77.77 [GopherProtocol/UMNDirHandler]: /\n")
        # Try to make this easy on us to fix.
        actualarr = self.wfile.getvalue().splitlines()
        expectedarr = [
'iThis is the abstract for the testdata directory.\tfake\t(NULL)\t0',
'0README\t/README\tHOSTNAME\t64777\t+',
'1pygopherd\t/pygopherd\tHOSTNAME\t64777\t+',
'9symlinktest\t/symlinktest.zip\tHOSTNAME\t64777\t+',
'9testarchive\t/testarchive.tar\tHOSTNAME\t64777\t+',
'9testarchive.tar.gz\t/testarchive.tar.gz\tHOSTNAME\t64777\t+',
'9testarchive.tgz\t/testarchive.tgz\tHOSTNAME\t64777\t+',
'9testdata\t/testdata.zip\tHOSTNAME\t64777\t+',
'9testdata2\t/testdata2.zip\tHOSTNAME\t64777\t+',
'0testfile\t/testfile.txt\tHOSTNAME\t64777\t+',
'9testfile.txt.gz\t/testfile.txt.gz\tHOSTNAME\t64777\t+',
'iThis is the abstract\tfake\t(NULL)\t0',
'ifor testfile.txt.gz\tfake\t(NULL)\t0',
'9ziptorture\t/ziptorture.zip\tHOSTNAME\t64777\t+']
        expectedarr = [re.sub('HOSTNAME', self.server.server_name, x) for \
                      x in expectedarr]
        self.assertEquals(len(actualarr), len(expectedarr), str(actualarr))
        for i in range(len(actualarr)):
            self.assertEquals(actualarr[i], expectedarr[i])
        # Make sure proper line endings are present.
        self.assertEquals("\r\n".join(actualarr) + "\r\n", self.wfile.getvalue())

    def testhandle_dir_noabstract(self):
        self.config.set("pygopherd", "abstract_headers", "off")
        self.config.set("pygopherd", "abstract_entries", "off")
        proto = GopherProtocol("", self.server, self.handler, self.rfile,
                               self.wfile, self.config)
        proto.handle()
        actualarr = self.wfile.getvalue().splitlines()
        expectedarr = \
             ['0README\t/README\tHOSTNAME\t64777\t+',
              '1pygopherd\t/pygopherd\tHOSTNAME\t64777\t+',
              '9symlinktest\t/symlinktest.zip\tHOSTNAME\t64777\t+',
              '9testarchive\t/testarchive.tar\tHOSTNAME\t64777\t+',
              '9testarchive.tar.gz\t/testarchive.tar.gz\tHOSTNAME\t64777\t+',
              '9testarchive.tgz\t/testarchive.tgz\tHOSTNAME\t64777\t+',
              '9testdata\t/testdata.zip\tHOSTNAME\t64777\t+',
              '9testdata2\t/testdata2.zip\tHOSTNAME\t64777\t+',
              '0testfile\t/testfile.txt\tHOSTNAME\t64777\t+',
              '9testfile.txt.gz\t/testfile.txt.gz\tHOSTNAME\t64777\t+',
              '9ziptorture\t/ziptorture.zip\tHOSTNAME\t64777\t+']
        expectedarr = [re.sub('HOSTNAME', self.server.server_name, x) for \
                       x in expectedarr]
        self.assertEquals(len(actualarr), len(expectedarr))
        for i in range(len(actualarr)):
            self.assertEquals(actualarr[i], expectedarr[i])
Ejemplo n.º 27
0
class DISABLED_TestVFS_Zip_huge:
    def setUp(self):
        from pygopherd import testutil
        from pygopherd.protocols.rfc1436 import GopherProtocol
        self.config = testutil.getconfig()
        self.rfile = StringIO("/testfile.txt\n")
        self.wfile = StringIO()
        self.logfile = testutil.getstringlogger()
        self.handler = testutil.gettestinghandler(self.rfile, self.wfile,
                                                  self.config)
        self.server = self.handler.server
        self.proto = GopherProtocol("/testfile.txt\n", self.server,
                                    self.handler, self.rfile, self.wfile,
                                    self.config)
        self.config.set("handlers.ZIP.ZIPHandler", "enabled", 'true')
        from pygopherd.handlers import HandlerMultiplexer
        HandlerMultiplexer.handlers = None
        handlerlist = self.config.get("handlers.HandlerMultiplexer", "handlers")
        handlerlist = handlerlist.strip()
        handlerlist = handlerlist[0] + 'ZIP.ZIPHandler, ' + handlerlist[1:]
        self.config.set("handlers.HandlerMultiplexer", "handlers", handlerlist)


    def testlistdir1(self):
        from pygopherd.protocols.rfc1436 import GopherProtocol
        self.proto = GopherProtocol("/foo.zip\n",
                                    self.server,
                                    self.handler, self.rfile, self.wfile,
                                    self.config)
        self.proto.handle()

    def testlistdir2(self):
        from pygopherd.protocols.rfc1436 import GopherProtocol
        self.proto = GopherProtocol("/foo.zip/lib\n",
                                    self.server,
                                    self.handler, self.rfile, self.wfile,
                                    self.config)
        self.proto.handle()

    def testlistdir3(self):
        from pygopherd.protocols.rfc1436 import GopherProtocol
        self.proto = GopherProtocol("/foo.zip/lib/dpkg/info\n",
                                    self.server,
                                    self.handler, self.rfile, self.wfile,
                                    self.config)
        self.proto.handle()
        
    def testopen1(self):
        from pygopherd.protocols.rfc1436 import GopherProtocol
        self.proto = GopherProtocol("/foo.zip/lib/dpkg/info/dpkg.list\n",
                                    self.server,
                                    self.handler, self.rfile, self.wfile,
                                    self.config)
        self.proto.handle()

    def testopen2(self):
        from pygopherd.protocols.rfc1436 import GopherProtocol
        self.proto = GopherProtocol("/foo.zip/games/bsdgames/snake.log\n",
                                    self.server,
                                    self.handler, self.rfile, self.wfile,
                                    self.config)
        self.proto.handle()

    def testopen3(self):
        from pygopherd.protocols.rfc1436 import GopherProtocol
        self.proto = GopherProtocol("/foo.zip/www/apache2-default/manual/platforms/index.html\n",
                                    self.server,
                                    self.handler, self.rfile, self.wfile,
                                    self.config)
        self.proto.handle()
Ejemplo n.º 28
0
class RFC1436TestCase(unittest.TestCase):
    def setUp(self):
        self.config = testutil.getconfig()
        self.rfile = BytesIO(b"/testfile.txt\n")
        self.wfile = BytesIO()
        self.logfile = testutil.getstringlogger()
        self.handler = testutil.gettestinghandler(self.rfile, self.wfile,
                                                  self.config)
        self.server = self.handler.server
        self.proto = GopherProtocol("/testfile.txt\n", self.server,
                                    self.handler, self.rfile, self.wfile,
                                    self.config)

    def testcanhandlerequest(self):
        assert self.proto.canhandlerequest()
        proto = GopherProtocol("/testfile.txt\tsearch\n", self.server,
                               self.handler, self.rfile, self.wfile,
                               self.config)
        assert proto.canhandlerequest()
        self.assertEqual(proto.selector, '/testfile.txt')
        self.assertEqual(proto.searchrequest, "search")

    def testrenderobjinfo(self):
        expected = "0testfile.txt\t/testfile.txt\t%s\t%d\t+\r\n" % \
                   (self.server.server_name, self.server.server_port)
        self.assertEqual(
            self.proto.renderobjinfo(self.proto.gethandler().getentry()),
            expected)

    def testhandle_file(self):
        self.proto.handle()
        self.assertEqual(
            self.logfile.getvalue(),
            b"10.77.77.77 [GopherProtocol/FileHandler]: /testfile.txt\n")
        self.assertEqual(self.wfile.getvalue(), b"Test\n")

    def testhandle_dir_abstracts(self):
        proto = GopherProtocol("", self.server, self.handler, self.rfile,
                               self.wfile, self.config)
        proto.handle()
        self.assertEqual(proto.selector, '/')
        self.assertEqual(self.logfile.getvalue(),
                         "10.77.77.77 [GopherProtocol/UMNDirHandler]: /\n")
        # Try to make this easy on us to fix.
        actualarr = self.wfile.getvalue().decode('ascii').splitlines()
        expectedarr = [
            'iThis is the abstract for the testdata directory.\tfake\t(NULL)\t0',
            '0README\t/README\tHOSTNAME\t64777\t+',
            '1pygopherd\t/pygopherd\tHOSTNAME\t64777\t+',
            '9symlinktest\t/symlinktest.zip\tHOSTNAME\t64777\t+',
            '9testarchive\t/testarchive.tar\tHOSTNAME\t64777\t+',
            '9testarchive.tar.gz\t/testarchive.tar.gz\tHOSTNAME\t64777\t+',
            '9testarchive.tgz\t/testarchive.tgz\tHOSTNAME\t64777\t+',
            '9testdata\t/testdata.zip\tHOSTNAME\t64777\t+',
            '9testdata2\t/testdata2.zip\tHOSTNAME\t64777\t+',
            '0testfile\t/testfile.txt\tHOSTNAME\t64777\t+',
            '9testfile.txt.gz\t/testfile.txt.gz\tHOSTNAME\t64777\t+',
            'iThis is the abstract\tfake\t(NULL)\t0',
            'ifor testfile.txt.gz\tfake\t(NULL)\t0',
            '9ziptorture\t/ziptorture.zip\tHOSTNAME\t64777\t+'
        ]
        expectedarr = [re.sub('HOSTNAME', self.server.server_name, x) for \
                      x in expectedarr]
        self.assertEqual(len(actualarr), len(expectedarr), str(actualarr))
        for i in range(len(actualarr)):
            self.assertEqual(actualarr[i], expectedarr[i])
        # Make sure proper line endings are present.
        self.assertEqual("\r\n".join(actualarr) + "\r\n",
                         self.wfile.getvalue())

    def testhandle_dir_noabstract(self):
        self.config.set("pygopherd", "abstract_headers", "off")
        self.config.set("pygopherd", "abstract_entries", "off")
        proto = GopherProtocol("", self.server, self.handler, self.rfile,
                               self.wfile, self.config)
        proto.handle()
        actualarr = self.wfile.getvalue().splitlines()
        expectedarr = \
             ['0README\t/README\tHOSTNAME\t64777\t+',
              '1pygopherd\t/pygopherd\tHOSTNAME\t64777\t+',
              '9symlinktest\t/symlinktest.zip\tHOSTNAME\t64777\t+',
              '9testarchive\t/testarchive.tar\tHOSTNAME\t64777\t+',
              '9testarchive.tar.gz\t/testarchive.tar.gz\tHOSTNAME\t64777\t+',
              '9testarchive.tgz\t/testarchive.tgz\tHOSTNAME\t64777\t+',
              '9testdata\t/testdata.zip\tHOSTNAME\t64777\t+',
              '9testdata2\t/testdata2.zip\tHOSTNAME\t64777\t+',
              '0testfile\t/testfile.txt\tHOSTNAME\t64777\t+',
              '9testfile.txt.gz\t/testfile.txt.gz\tHOSTNAME\t64777\t+',
              '9ziptorture\t/ziptorture.zip\tHOSTNAME\t64777\t+']
        expectedarr = [re.sub('HOSTNAME', self.server.server_name, x) for \
                       x in expectedarr]
        self.assertEqual(len(actualarr), len(expectedarr))
        for i in range(len(actualarr)):
            self.assertEqual(actualarr[i], expectedarr[i])
Ejemplo n.º 29
0
class DISABLED_TestVFS_Zip_huge:
    def setUp(self):
        from pygopherd import testutil
        from pygopherd.protocols.rfc1436 import GopherProtocol
        self.config = testutil.getconfig()
        self.rfile = StringIO("/testfile.txt\n")
        self.wfile = StringIO()
        self.logfile = testutil.getstringlogger()
        self.handler = testutil.gettestinghandler(self.rfile, self.wfile,
                                                  self.config)
        self.server = self.handler.server
        self.proto = GopherProtocol("/testfile.txt\n", self.server,
                                    self.handler, self.rfile, self.wfile,
                                    self.config)
        self.config.set("handlers.ZIP.ZIPHandler", "enabled", 'true')
        from pygopherd.handlers import HandlerMultiplexer
        HandlerMultiplexer.handlers = None
        handlerlist = self.config.get("handlers.HandlerMultiplexer",
                                      "handlers")
        handlerlist = handlerlist.strip()
        handlerlist = handlerlist[0] + 'ZIP.ZIPHandler, ' + handlerlist[1:]
        self.config.set("handlers.HandlerMultiplexer", "handlers", handlerlist)

    def testlistdir1(self):
        from pygopherd.protocols.rfc1436 import GopherProtocol
        self.proto = GopherProtocol("/foo.zip\n", self.server, self.handler,
                                    self.rfile, self.wfile, self.config)
        self.proto.handle()

    def testlistdir2(self):
        from pygopherd.protocols.rfc1436 import GopherProtocol
        self.proto = GopherProtocol("/foo.zip/lib\n", self.server,
                                    self.handler, self.rfile, self.wfile,
                                    self.config)
        self.proto.handle()

    def testlistdir3(self):
        from pygopherd.protocols.rfc1436 import GopherProtocol
        self.proto = GopherProtocol("/foo.zip/lib/dpkg/info\n", self.server,
                                    self.handler, self.rfile, self.wfile,
                                    self.config)
        self.proto.handle()

    def testopen1(self):
        from pygopherd.protocols.rfc1436 import GopherProtocol
        self.proto = GopherProtocol("/foo.zip/lib/dpkg/info/dpkg.list\n",
                                    self.server, self.handler, self.rfile,
                                    self.wfile, self.config)
        self.proto.handle()

    def testopen2(self):
        from pygopherd.protocols.rfc1436 import GopherProtocol
        self.proto = GopherProtocol("/foo.zip/games/bsdgames/snake.log\n",
                                    self.server, self.handler, self.rfile,
                                    self.wfile, self.config)
        self.proto.handle()

    def testopen3(self):
        from pygopherd.protocols.rfc1436 import GopherProtocol
        self.proto = GopherProtocol(
            "/foo.zip/www/apache2-default/manual/platforms/index.html\n",
            self.server, self.handler, self.rfile, self.wfile, self.config)
        self.proto.handle()
Ejemplo n.º 30
0
 def getinfoblock(self, entry):
     return "+INFO: " + GopherProtocol.renderobjinfo(self, entry)
Ejemplo n.º 31
0
 def testopen3(self):
     from pygopherd.protocols.rfc1436 import GopherProtocol
     self.proto = GopherProtocol(
         "/foo.zip/www/apache2-default/manual/platforms/index.html\n",
         self.server, self.handler, self.rfile, self.wfile, self.config)
     self.proto.handle()
Ejemplo n.º 32
0
 def testopen2(self):
     from pygopherd.protocols.rfc1436 import GopherProtocol
     self.proto = GopherProtocol("/foo.zip/games/bsdgames/snake.log\n",
                                 self.server, self.handler, self.rfile,
                                 self.wfile, self.config)
     self.proto.handle()
Ejemplo n.º 33
0
 def testopen1(self):
     from pygopherd.protocols.rfc1436 import GopherProtocol
     self.proto = GopherProtocol("/foo.zip/lib/dpkg/info/dpkg.list\n",
                                 self.server, self.handler, self.rfile,
                                 self.wfile, self.config)
     self.proto.handle()