grr/server/grr_response_server/flows/general/transfer_test.py
def testGetFile(self):
    """Test that the GetFile flow works."""

    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"))

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

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

    if data_store.RelationalDBReadEnabled(category="filestore"):
      cp = db.ClientPath.FromPathSpec(self.client_id.Basename(), 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 = pathspec.AFF4Path(self.client_id)
      fd1 = aff4.FACTORY.Open(urn, token=self.token)
      fd2.seek(0, 2)
      self.assertEqual(fd2.tell(), int(fd1.Get(fd1.Schema.SIZE)))
      self.CompareFDs(fd1, fd2)
Test that the GetFile flow works.
Test that the GetFile flow works.
Test that the GetFile flow works .
def testGetFile(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"))
    flow_test_lib.TestFlowHelper(
        transfer.GetFile.__name__,
        client_mock,
        token=self.token,
        client_id=self.client_id,
        pathspec=pathspec)
    pathspec.path = pathspec.path.replace("\\", "/")
    fd2 = open(pathspec.path, "rb")
    if data_store.RelationalDBReadEnabled(category="filestore"):
      cp = db.ClientPath.FromPathSpec(self.client_id.Basename(), 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 = pathspec.AFF4Path(self.client_id)
      fd1 = aff4.FACTORY.Open(urn, token=self.token)
      fd2.seek(0, 2)
      self.assertEqual(fd2.tell(), int(fd1.Get(fd1.Schema.SIZE)))
      self.CompareFDs(fd1, fd2)
def testGetFile ( 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" ) ) flow_test_lib . TestFlowHelper ( transfer . GetFile . __name__ , client_mock , token = self . token , client_id = self . client_id , pathspec = pathspec ) pathspec . path = pathspec . path . replace ( "\\" , "/" ) fd2 = open ( pathspec . path , "rb" ) if data_store . RelationalDBReadEnabled ( category = "filestore" ) : cp = db . ClientPath . FromPathSpec ( self . client_id . Basename ( ) , 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 = pathspec . AFF4Path ( self . client_id ) fd1 = aff4 . FACTORY . Open ( urn , token = self . token ) fd2 . seek ( 0 , 2 ) self . assertEqual ( fd2 . tell ( ) , int ( fd1 . Get ( fd1 . Schema . SIZE ) ) ) self . CompareFDs ( fd1 , fd2 )
Test that the GetFile flow works.
Test that the GetFile flow works .
"""Test that the GetFile flow works.""" # 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