def testVFSVirtualRoot(self):

    # Let's open a file in the virtual root.
    os_root = "os:%s" % self.base_path
    with test_lib.ConfigOverrider({"Client.vfs_virtualroots": [os_root]}):
      # We need to reset the vfs._VFS_VIRTUALROOTS too.
      vfs.Init()

      fd = vfs.VFSOpen(
          rdf_paths.PathSpec(
              path="/morenumbers.txt", pathtype=rdf_paths.PathSpec.PathType.OS))
      data = fd.read(10)
      self.assertEqual(data, b"1\n2\n3\n4\n5\n")

    # This should also work with TSK.
    tsk_root = "tsk:%s" % os.path.join(self.base_path, "test_img.dd")
    with test_lib.ConfigOverrider({"Client.vfs_virtualroots": [tsk_root]}):
      vfs.Init()

      image_file_ps = rdf_paths.PathSpec(
          path=u"איןד ןד ש אקדא/איןד.txt",
          pathtype=rdf_paths.PathSpec.PathType.TSK)

      fd = vfs.VFSOpen(image_file_ps)

      data = fd.read(10)
      self.assertEqual(data, b"1\n2\n3\n4\n5\n")

      # This should not influence vfs handlers other than OS and TSK.
      reg_type = rdf_paths.PathSpec.PathType.REGISTRY
      os_handler = vfs.VFS_HANDLERS[rdf_paths.PathSpec.PathType.OS]
      with vfs_test_lib.VFSOverrider(reg_type, os_handler):
        with self.assertRaises(IOError):
          image_file_ps.pathtype = reg_type
          vfs.VFSOpen(image_file_ps)
示例#2
0
 def Start(self):
     if not vfs.VFS_HANDLERS:
         # Initialize VFS if not yet done, otherwise VFS will not initialize
         # correctly when it is used for the first time in testing code.
         vfs.Init()
     self._old_handler = vfs.VFS_HANDLERS.get(self._vfs_type)
     vfs.VFS_HANDLERS[self._vfs_type] = self._temp_handler
示例#3
0
 def setUp(self):
   super().setUp()
   self.client_mock = action_mocks.FileFinderClientMockWithTimestamps()
   self.fixture_path = os.path.join(self.base_path, "searching")
   self.path = os.path.join(self.fixture_path, "*.log")
   self.client_id = self.SetupClient(0)
   vfs.Init()
示例#4
0
def setUpModule():
  # client_vfs needs a config to be loaded to work.
  flags.FLAGS.config = package.ResourcePath(
      "grr-response-test", "grr_response_test/test_data/dummyconfig.yaml")
  config_lib.ParseConfigCommandLine()

  client_vfs.Init()
示例#5
0
    def testGrepRegex(self):
        # Use the real file system.
        vfs.Init()

        request = rdf_client_fs.GrepSpec(
            regex=b"1[0]",
            xor_out_key=self.XOR_OUT_KEY,
            start_offset=0,
            target=rdf_paths.PathSpec(path=os.path.join(
                self.base_path, "numbers.txt"),
                                      pathtype=rdf_paths.PathSpec.PathType.OS))

        result = self.RunAction(searching.Grep, request)
        hits = [x.offset for x in result]
        self.assertEqual(hits, [
            18, 288, 292, 296, 300, 304, 308, 312, 316, 320, 324, 329, 729,
            1129, 1529, 1929, 2329, 2729, 3129, 3529, 3888
        ])
        for x in result:
            self.assertIn(b"10", utils.Xor(x.data, self.XOR_OUT_KEY))
示例#6
0
def setUpModule():
    test_lib.SetUpDummyConfig()
    client_vfs.Init()