grr/server/grr_response_server/flows/general/transfer_test.py
def testGetFilePathCorrection(self):
    """Tests that the pathspec returned is used for the aff4path."""
    client_mock = action_mocks.GetFileClientMock()
    # Deliberately using the wrong casing.
    pathspec = rdf_paths.PathSpec(
        pathtype=rdf_paths.PathSpec.PathType.OS,
        path=os.path.join(self.base_path, "TEST_IMG.dd"))

    session_id = flow_test_lib.TestFlowHelper(
        transfer.GetFile.__name__,
        client_mock,
        token=self.token,
        client_id=self.client_id,
        pathspec=pathspec)

    results = flow_test_lib.GetFlowResults(self.client_id.Basename(),
                                           session_id)
    self.assertLen(results, 1)
    res_pathspec = results[0].pathspec

    # Fix path for Windows testing.
    pathspec.path = pathspec.path.replace("\\", "/")
    fd2 = open(res_pathspec.path, "rb")
    fd2.seek(0, 2)

    if data_store.RelationalDBReadEnabled(category="filestore"):
      cp = db.ClientPath.FromPathSpec(self.client_id.Basename(), res_pathspec)

      fd_rel_db = file_store.OpenFile(cp)
      self.CompareFDs(fd2, fd_rel_db)

      # Only the sha256 hash of the contents should have been calculated:
      # in order to put file contents into the file store.
      history = data_store.REL_DB.ReadPathInfoHistory(
          cp.client_id, cp.path_type, cp.components)
      self.assertEqual(history[-1].hash_entry.sha256,
                       fd_rel_db.hash_id.AsBytes())
      self.assertIsNone(history[-1].hash_entry.sha1)
      self.assertIsNone(history[-1].hash_entry.md5)
    else:
      # Test the AFF4 file that was created.
      urn = res_pathspec.AFF4Path(self.client_id)
      fd1 = aff4.FACTORY.Open(urn, token=self.token)

      self.assertEqual(fd2.tell(), int(fd1.Get(fd1.Schema.SIZE)))
      self.CompareFDs(fd1, fd2)
Tests that the pathspec returned is used for the aff4path.
Tests that the pathspec returned is used for the aff4path.
Tests that the pathspec returned is used for the aff4path .
def testGetFilePathCorrection(self):
    client_mock = action_mocks.GetFileClientMock()
    pathspec = rdf_paths.PathSpec(
        pathtype=rdf_paths.PathSpec.PathType.OS,
        path=os.path.join(self.base_path, "TEST_IMG.dd"))
    session_id = flow_test_lib.TestFlowHelper(
        transfer.GetFile.__name__,
        client_mock,
        token=self.token,
        client_id=self.client_id,
        pathspec=pathspec)
    results = flow_test_lib.GetFlowResults(self.client_id.Basename(),
                                           session_id)
    self.assertLen(results, 1)
    res_pathspec = results[0].pathspec
    pathspec.path = pathspec.path.replace("\\", "/")
    fd2 = open(res_pathspec.path, "rb")
    fd2.seek(0, 2)
    if data_store.RelationalDBReadEnabled(category="filestore"):
      cp = db.ClientPath.FromPathSpec(self.client_id.Basename(), res_pathspec)
      fd_rel_db = file_store.OpenFile(cp)
      self.CompareFDs(fd2, fd_rel_db)
      history = data_store.REL_DB.ReadPathInfoHistory(
          cp.client_id, cp.path_type, cp.components)
      self.assertEqual(history[-1].hash_entry.sha256,
                       fd_rel_db.hash_id.AsBytes())
      self.assertIsNone(history[-1].hash_entry.sha1)
      self.assertIsNone(history[-1].hash_entry.md5)
    else:
      urn = res_pathspec.AFF4Path(self.client_id)
      fd1 = aff4.FACTORY.Open(urn, token=self.token)
      self.assertEqual(fd2.tell(), int(fd1.Get(fd1.Schema.SIZE)))
      self.CompareFDs(fd1, fd2)
def testGetFilePathCorrection ( self ) : client_mock = action_mocks . GetFileClientMock ( ) pathspec = rdf_paths . PathSpec ( pathtype = rdf_paths . PathSpec . PathType . OS , path = os . path . join ( self . base_path , "TEST_IMG.dd" ) ) session_id = flow_test_lib . TestFlowHelper ( transfer . GetFile . __name__ , client_mock , token = self . token , client_id = self . client_id , pathspec = pathspec ) results = flow_test_lib . GetFlowResults ( self . client_id . Basename ( ) , session_id ) self . assertLen ( results , 1 ) res_pathspec = results [ 0 ] . pathspec pathspec . path = pathspec . path . replace ( "\\" , "/" ) fd2 = open ( res_pathspec . path , "rb" ) fd2 . seek ( 0 , 2 ) if data_store . RelationalDBReadEnabled ( category = "filestore" ) : cp = db . ClientPath . FromPathSpec ( self . client_id . Basename ( ) , res_pathspec ) fd_rel_db = file_store . OpenFile ( cp ) self . CompareFDs ( fd2 , fd_rel_db ) history = data_store . REL_DB . ReadPathInfoHistory ( cp . client_id , cp . path_type , cp . components ) self . assertEqual ( history [ - 1 ] . hash_entry . sha256 , fd_rel_db . hash_id . AsBytes ( ) ) self . assertIsNone ( history [ - 1 ] . hash_entry . sha1 ) self . assertIsNone ( history [ - 1 ] . hash_entry . md5 ) else : urn = res_pathspec . AFF4Path ( self . client_id ) fd1 = aff4 . FACTORY . Open ( urn , token = self . token ) self . assertEqual ( fd2 . tell ( ) , int ( fd1 . Get ( fd1 . Schema . SIZE ) ) ) self . CompareFDs ( fd1 , fd2 )
Tests that the pathspec returned is used for the aff4path.
Tests that the pathspec returned is used for the aff4path .
"""Tests that the pathspec returned is used for the aff4path.""" # Deliberately using the wrong casing. # Fix path for Windows testing. # Only the sha256 hash of the contents should have been calculated: # in order to put file contents into the file store. # Test the AFF4 file that was created.
self