def testListDirectoryBasePath(self):
        fileServer = FileServer(self.directory,
                                allowDirectoryListing=True,
                                basePath='/webpath/')
        with open(join(self.directory, "dummy.txt"), "w") as f:
            f.write("Dummy")
        mkdir(self.directory, "subdir")

        response = generatorToString(
            fileServer.handleRequest(port=80,
                                     Client=('localhost', 9000),
                                     path="/"))
        self.assertTrue(response.startswith("HTTP/1.0 200 OK"), response)
        self.assertTrue("<title>Index of /webpath</title>" in response,
                        response)

        links = [
            line for line in response.split("\n") if line.startswith("<a href")
        ]
        self.assertEqual(2, len(links))

        self.assertTrue(
            links[0].startswith('<a href="dummy.txt">dummy.txt</a>'), links[0])
        self.assertTrue(links[0].endswith(' 5'), links[0])
        self.assertTrue(links[1].startswith('<a href="subdir/">subdir/</a>'),
                        links[1])
Exemple #2
0
    def testMkdir(self):
        self.assertFalse(isdir(join(self.tempdir, "mkdir")))
        self.assertEquals(join(self.tempdir, "mkdir"), mkdir(self.tempdir, "mkdir"))
        self.assertTrue(isdir(join(self.tempdir, "mkdir")))

        self.assertFalse(isdir(join(self.tempdir, "1", "2", "3", "4")))
        mkdir(self.tempdir, "1", "2", "3", "4")
        self.assertTrue(isdir(join(self.tempdir, "1", "2", "3", "4")))
Exemple #3
0
    def testMkdir(self):
        self.assertFalse(isdir(join(self.tempdir, "mkdir")))
        self.assertEqual(join(self.tempdir, "mkdir"), mkdir(self.tempdir, "mkdir"))
        self.assertTrue(isdir(join(self.tempdir, "mkdir")))

        self.assertFalse(isdir(join(self.tempdir, "1", "2", "3", "4")))
        mkdir(self.tempdir, "1", "2", "3", "4")
        self.assertTrue(isdir(join(self.tempdir, "1", "2", "3", "4")))
Exemple #4
0
    def testListDirectory(self):
        fileServer = FileServer(self.directory)
        response = asString(fileServer.handleRequest(port=80, Client=('localhost', 9000), path="/"))
        self.assertTrue(response.startswith("HTTP/1.0 404 Not Found"), response)

        fileServer = FileServer(self.directory, allowDirectoryListing=True)
        with open(join(self.directory, "dummy.txt"), "w") as f:
            f.write("Dummy")

        subdir = mkdir(self.directory, "subdir")
        with open(join(self.directory, subdir, 'The "real" <deal>.txt'), "w") as f:
            f.write("to test escaping")

        response = asString(fileServer.handleRequest(port=80, Client=('localhost', 9000), path="/"))
        self.assertTrue(response.startswith("HTTP/1.0 200 OK"), response)
        self.assertTrue("<title>Index of /</title>" in response, response)

        links = [line for line in response.split("\n") if line.startswith("<a href")]
        self.assertEqual(3, len(links))

        self.assertEquals('<a href="../">../</a>', links[0])
        self.assertTrue(links[1].startswith('<a href="dummy.txt">dummy.txt</a>'), links[1])
        self.assertTrue(links[1].endswith(' 5'), links[1])
        self.assertTrue(links[2].startswith('<a href="subdir/">subdir/</a>'), links[2])

        response = asString(fileServer.handleRequest(port=80, Client=('localhost', 9000), path="/subdir"))
        self.assertTrue(response.startswith("HTTP/1.0 301 Moved Permanently"), response)

        response = asString(fileServer.handleRequest(port=80, Client=('localhost', 9000), path="/subdir/"))
        self.assertTrue("<title>Index of /subdir/</title>" in response, response)
        links = [line for line in response.split("\n") if line.startswith("<a href")]
        self.assertEquals('<a href="../">../</a>', links[0])
        self.assertTrue(links[1].startswith('''<a href='The "real" &lt;deal&gt;.txt'>The "real" &lt;deal&gt;.txt</a>'''), links[1])
        self.assertTrue(links[1].endswith(' 16'), links[1])

        subdir = mkdir(self.directory, "subdir2")
        response = asString(fileServer.handleRequest(port=80, Client=('localhost', 9000), path="/subdir2/"))
        self.assertTrue("<title>Index of /subdir2/</title>" in response, response)
        links = [line for line in response.split("\n") if line.startswith("<a href")]
        self.assertTrue(1, len(links))
        hrs = [line for line in response.split("\n") if line.strip() == "<hr>"]
        self.assertEquals(2, len(hrs))

        response = asString(fileServer.handleRequest(port=80, Client=('localhost', 9000), path="/does_not_exist/"))
        self.assertTrue(response.startswith("HTTP/1.0 404 Not Found"), response)
Exemple #5
0
    def testLoadTestFromPathSubDirs(self):
        with open(join(self.tempdir, "sometest.py"), "w") as fp:
            fp.write(TEST_TEMPLATE)
        
        with open(join(mkdir(self.tempdir, "sub"), "sometest.py"), "w") as fp:
            fp.write(TEST_TEMPLATE)

        g = {}
        loadTestsFromPath(self.tempdir, _globals=g)
        self.assertEqual(2, len(g))
        self.assertEqual({'sub.SomeTest', 'SomeTest'}, set(g.keys()))
Exemple #6
0
    def testLoadTestFromPathSubDirs(self):
        with open(join(self.tempdir, "sometest.py"), "w") as fp:
            fp.write(TEST_TEMPLATE)

        with open(join(mkdir(self.tempdir, "sub"), "sometest.py"), "w") as fp:
            fp.write(TEST_TEMPLATE)

        g = {}
        loadTestsFromPath(self.tempdir, _globals=g)
        self.assertEqual(2, len(g))
        self.assertEqual({'sub.SomeTest', 'SomeTest'}, set(g.keys()))
    def setUp(self):
        SeecrTestCase.setUp(self)
        self.domainId = "adomain"
        self.stateDir = mkdir(self.tempdir, "state")
        mkdir(self.stateDir, self.domainId)
        self.logDir = mkdir(self.tempdir, "log")
        repoId1LogDir = mkdir(self.logDir, self.domainId, "invalid", "repoId1")
        repoId2LogDir = mkdir(self.logDir, self.domainId, "invalid",
                              escapeFilename("repoId/2"))
        _writeFile(repoId1LogDir,
                   "invalidId1",
                   data="<diagnostic>ERROR1</diagnostic>")
        _writeFile(repoId1LogDir,
                   "invalidId&2",
                   data="<diagnostic>ERROR2</diagnostic>")
        _writeFile(repoId2LogDir,
                   escapeFilename("invalidId/3"),
                   data="<diagnostic>ERROR3</diagnostic>")
        _writeFile(self.stateDir,
                   self.domainId,
                   "repoId1_invalid.ids",
                   data="invalidId1\ninvalidId&2")
        _writeFile(self.stateDir,
                   self.domainId,
                   escapeFilename("repoId/2_invalid.ids"),
                   data="invalidId/3")
        _writeFile(self.stateDir,
                   self.domainId,
                   "repoId3_invalid.ids",
                   data="")
        self.status = RepositoryStatus(self.logDir, self.stateDir)
        observer = CallTrace("HarvesterData")
        observer.returnValues["getRepositoryGroupIds"] = [
            "repoGroupId1", "repoGroupId2"
        ]

        def getRepositoryIds(domainId, repositoryGroupId):
            if repositoryGroupId == "repoGroupId1":
                return ["repoId1", "repoId/2"]
            return ["repoId3", "anotherRepoId"]

        observer.methods["getRepositoryIds"] = getRepositoryIds

        def getRepositoryGroupId(domainId, repositoryId):
            return 'repoGroupId1' if repositoryId in ['repoId1', 'repoId/2'
                                                      ] else 'repoGroupId2'

        observer.methods["getRepositoryGroupId"] = getRepositoryGroupId
        self.status.addObserver(observer)
 def setUp(self):
     SeecrTestCase.setUp(self)
     self.directory = mkdir(self.tempdir, "directory1")
     self.directory2 = mkdir(self.tempdir, "directory2")
    def testListDirectory(self):
        fileServer = FileServer(self.directory)
        response = generatorToString(
            fileServer.handleRequest(port=80,
                                     Client=('localhost', 9000),
                                     path="/"))
        self.assertTrue(response.startswith("HTTP/1.0 404 Not Found"),
                        response)

        fileServer = FileServer(self.directory, allowDirectoryListing=True)
        with open(join(self.directory, "dummy.txt"), "w") as f:
            f.write("Dummy")

        subdir = mkdir(self.directory, "subdir")
        with open(join(self.directory, subdir, 'The "real" <deal>.txt'),
                  "w") as f:
            f.write("to test escaping")

        response = generatorToString(
            fileServer.handleRequest(port=80,
                                     Client=('localhost', 9000),
                                     path="/"))
        self.assertTrue(response.startswith("HTTP/1.0 200 OK"), response)
        self.assertTrue("<title>Index of /</title>" in response, response)

        links = [
            line for line in response.split("\n") if line.startswith("<a href")
        ]
        self.assertEqual(2, len(links))

        self.assertTrue(
            links[0].startswith('<a href="dummy.txt">dummy.txt</a>'), links[0])
        self.assertTrue(links[0].endswith(' 5'), links[0])
        self.assertTrue(links[1].startswith('<a href="subdir/">subdir/</a>'),
                        links[1])

        response = generatorToString(
            fileServer.handleRequest(port=80,
                                     Client=('localhost', 9000),
                                     path="/subdir"))
        self.assertTrue(response.startswith("HTTP/1.0 301 Moved Permanently"),
                        response)

        response = generatorToString(
            fileServer.handleRequest(port=80,
                                     Client=('localhost', 9000),
                                     path="/subdir/"))
        self.assertTrue("<title>Index of /subdir</title>" in response,
                        response)
        links = [
            line for line in response.split("\n") if line.startswith("<a href")
        ]
        self.assertEqual('<a href="../">../</a>', links[0])
        self.assertTrue(
            links[1].startswith(
                '''<a href='The "real" &lt;deal&gt;.txt'>The "real" &lt;deal&gt;.txt</a>'''
            ), links[1])
        self.assertTrue(links[1].endswith(' 16'), links[1])

        subdir = mkdir(self.directory, "subdir2")
        response = generatorToString(
            fileServer.handleRequest(port=80,
                                     Client=('localhost', 9000),
                                     path="/subdir2/"))
        self.assertTrue("<title>Index of /subdir2</title>" in response,
                        response)
        links = [
            line for line in response.split("\n") if line.startswith("<a href")
        ]
        self.assertTrue(1, len(links))
        hrs = [line for line in response.split("\n") if line.strip() == "<hr>"]
        self.assertEqual(2, len(hrs))

        response = generatorToString(
            fileServer.handleRequest(port=80,
                                     Client=('localhost', 9000),
                                     path="/does_not_exist/"))
        self.assertTrue(response.startswith("HTTP/1.0 404 Not Found"),
                        response)
Exemple #10
0
 def setUp(self):
     SeecrTestCase.setUp(self)
     self.directory = mkdir(self.tempdir, "directory1")
     self.directory2 = mkdir(self.tempdir, "directory2")