Exemple #1
0
        with open(path, "wb") as fd:
            fd.write("")

    def _make_temp_directory(self):
        self._touch(os.path.join(self.temp_directory, "boo.txt"))
        os.makedirs(os.path.join(self.temp_directory, "foo"))
        self._touch(os.path.join(self.temp_directory, "foo/boo2.txt"))

        # Drop a symlink to / - if we follow links this will crash.
        os.symlink("/", os.path.join(self.temp_directory, "link"))

    def testGlob(self):
        self._make_temp_directory()
        glob_plugin = files.IRGlob(session=self.session,
                                   globs=[self.temp_directory + "/*.txt"])
        result = list(glob_plugin.collect())
        self.assertTrue(
            "boo.txt" in
            [os.path.basename(unicode(x["path"].filename)) for x in result])
        self.assertEqual(len(result), 1)

        glob_plugin = files.IRGlob(session=self.session,
                                   globs=[self.temp_directory + "/**/*.txt"])
        result = list(glob_plugin.collect())
        paths = [os.path.basename(unicode(x["path"].filename)) for x in result]
        self.assertEqual(["boo.txt", "boo2.txt"], paths)


if __name__ == "__main__":
    testlib.main()
Exemple #2
0
        # It does not matter if the path has a / at the end or not. It
        # still refers to the same object.
        test_obj = common.FileSpec("/usr/bin/")
        self.assertEqual(test_obj.basename, "bin")
        self.assertEqual(unicode(test_obj.dirname), "/usr")

        test_obj = common.FileSpec("/")
        self.assertEqual(test_obj.basename, "")
        self.assertEqual(unicode(test_obj.dirname), "/")
        self.assertEqual(test_obj.components(), [])

    @mock.patch("os.path.sep", "\\")
    def testFileSpecWindows(self):
        """Test windows paths."""
        test_obj = common.FileSpec("c:\\Windows\System32\\notepad.exe", path_sep="\\")
        self.assertEqual(test_obj.basename, "notepad.exe")
        self.assertEqual(unicode(test_obj.dirname), "c:\\Windows\\System32")
        self.assertEqual(test_obj.components(), ["c:", "Windows", "System32",
                                                 "notepad.exe"])

        self.assertEqual(test_obj.os_path(), "c:\\Windows\System32\\notepad.exe")


class TestFileInformation(testlib.RekallBaseUnitTestCase):
    def testUnixFiles(self):
        pass


if __name__ == "__main__":
    testlib.main()
Exemple #3
0
        # Clean up.
        location_obj.delete()

    def test_read_modify_write_file(self):
        def modify(filename):
            with open(filename, "wb") as fd:
                fd.write("hello world")

        a = cloud.GCSOAuth2BasedLocation(session=self.session)
        a.bucket = self.config.server.bucket
        a.path = "test.txt"
        a.read_modify_write_local_file(modify)


if __name__ == "__main__":
    args, unknown_args = parser.parse_known_args()
    if args.verbose:
        VERBOSITY = 10

    if args.config:
        CONFIG_FILE = args.config

    else:
        print """
This test requires a valid GCS configuration.

You can make one with the agent_server_initialize_gcs plugin.
"""

    testlib.main(argv=["test"] + unknown_args)
Exemple #4
0
def main():
    testlib.main()
Exemple #5
0
            self.config.server.service_account.create_oauth_location(
                path=u"signed_policy/%s" % self.filename))

        self.assertEqual(location_obj.read_file(), "Hello world")

        # Clean up.
        location_obj.delete()

    def test_read_modify_write_file(self):
        def modify(filename):
            with open(filename, "wb") as fd:
                fd.write("hello world")

        a = cloud.GCSOAuth2BasedLocation(session=self.session)
        a.bucket = "rekall-temp"
        a.path = "test.txt"
        a.read_modify_write_local_file(modify)


if __name__ == "__main__":
    args, unknown_args = parser.parse_known_args()
    if not args.config:
        print """
This test requires a valid GCS configuration.

You can make one with the agent_server_initialize_gcs plugin.
"""

    else:
        testlib.main(argv=["test"] + unknown_args)
Exemple #6
0
def main():
    testlib.main()