grr/server/grr_response_server/flows/general/transfer_test.py
def testMultiGetFileMultiFiles(self):
    """Test MultiGetFile downloading many files at once."""
    client_mock = action_mocks.MultiGetFileClientMock()

    pathspecs = []
    # Make 30 files to download.
    for i in range(30):
      path = os.path.join(self.temp_dir, "test_%s.txt" % i)
      with open(path, "wb") as fd:
        fd.write("Hello")

      pathspecs.append(
          rdf_paths.PathSpec(
              pathtype=rdf_paths.PathSpec.PathType.OS, path=path))

    args = transfer.MultiGetFileArgs(
        pathspecs=pathspecs, maximum_pending_files=10)
    session_id = flow_test_lib.TestFlowHelper(
        transfer.MultiGetFile.__name__,
        client_mock,
        token=self.token,
        client_id=self.client_id,
        args=args)

    if data_store.RelationalDBReadEnabled(category="filestore"):
      # Now open each file and make sure the data is there.
      for pathspec in pathspecs:
        cp = db.ClientPath.FromPathSpec(self.client_id.Basename(), pathspec)
        fd_rel_db = file_store.OpenFile(cp)
        self.assertEqual("Hello", fd_rel_db.read())

        # Check that SHA256 hash of the file matches the contents
        # hash and that MD5 and SHA1 are set.
        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.assertIsNotNone(history[-1].hash_entry.sha1)
        self.assertIsNotNone(history[-1].hash_entry.md5)
    else:
      # Check up on the internal flow state.
      flow_state = flow_test_lib.GetFlowState(
          self.client_id, session_id, token=self.token)
      # All the pathspecs should be in this list.
      self.assertLen(flow_state.indexed_pathspecs, 30)

      # At any one time, there should not be more than 10 files or hashes
      # pending.
      self.assertLessEqual(len(flow_state.pending_files), 10)
      self.assertLessEqual(len(flow_state.pending_hashes), 10)

      # When we finish there should be no pathspecs stored in the flow state.
      for flow_pathspec in flow_state.indexed_pathspecs:
        self.assertIsNone(flow_pathspec)
      for flow_request_data in flow_state.request_data_list:
        self.assertIsNone(flow_request_data)

      for pathspec in pathspecs:
        urn = pathspec.AFF4Path(self.client_id)
        fd = aff4.FACTORY.Open(urn, token=self.token)
        self.assertEqual("Hello", fd.read())
Test MultiGetFile downloading many files at once.
Test MultiGetFile downloading many files at once.
Test MultiGetFile downloading many files at once .
def testMultiGetFileMultiFiles(self):
    client_mock = action_mocks.MultiGetFileClientMock()
    pathspecs = []
    for i in range(30):
      path = os.path.join(self.temp_dir, "test_%s.txt" % i)
      with open(path, "wb") as fd:
        fd.write("Hello")
      pathspecs.append(
          rdf_paths.PathSpec(
              pathtype=rdf_paths.PathSpec.PathType.OS, path=path))
    args = transfer.MultiGetFileArgs(
        pathspecs=pathspecs, maximum_pending_files=10)
    session_id = flow_test_lib.TestFlowHelper(
        transfer.MultiGetFile.__name__,
        client_mock,
        token=self.token,
        client_id=self.client_id,
        args=args)
    if data_store.RelationalDBReadEnabled(category="filestore"):
      for pathspec in pathspecs:
        cp = db.ClientPath.FromPathSpec(self.client_id.Basename(), pathspec)
        fd_rel_db = file_store.OpenFile(cp)
        self.assertEqual("Hello", fd_rel_db.read())
        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.assertIsNotNone(history[-1].hash_entry.sha1)
        self.assertIsNotNone(history[-1].hash_entry.md5)
    else:
      flow_state = flow_test_lib.GetFlowState(
          self.client_id, session_id, token=self.token)
      self.assertLen(flow_state.indexed_pathspecs, 30)
      self.assertLessEqual(len(flow_state.pending_files), 10)
      self.assertLessEqual(len(flow_state.pending_hashes), 10)
      for flow_pathspec in flow_state.indexed_pathspecs:
        self.assertIsNone(flow_pathspec)
      for flow_request_data in flow_state.request_data_list:
        self.assertIsNone(flow_request_data)
      for pathspec in pathspecs:
        urn = pathspec.AFF4Path(self.client_id)
        fd = aff4.FACTORY.Open(urn, token=self.token)
        self.assertEqual("Hello", fd.read())
def testMultiGetFileMultiFiles ( self ) : client_mock = action_mocks . MultiGetFileClientMock ( ) pathspecs = [ ] for i in range ( 30 ) : path = os . path . join ( self . temp_dir , "test_%s.txt" % i ) with open ( path , "wb" ) as fd : fd . write ( "Hello" ) pathspecs . append ( rdf_paths . PathSpec ( pathtype = rdf_paths . PathSpec . PathType . OS , path = path ) ) args = transfer . MultiGetFileArgs ( pathspecs = pathspecs , maximum_pending_files = 10 ) session_id = flow_test_lib . TestFlowHelper ( transfer . MultiGetFile . __name__ , client_mock , token = self . token , client_id = self . client_id , args = args ) if data_store . RelationalDBReadEnabled ( category = "filestore" ) : for pathspec in pathspecs : cp = db . ClientPath . FromPathSpec ( self . client_id . Basename ( ) , pathspec ) fd_rel_db = file_store . OpenFile ( cp ) self . assertEqual ( "Hello" , fd_rel_db . read ( ) ) 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 . assertIsNotNone ( history [ - 1 ] . hash_entry . sha1 ) self . assertIsNotNone ( history [ - 1 ] . hash_entry . md5 ) else : flow_state = flow_test_lib . GetFlowState ( self . client_id , session_id , token = self . token ) self . assertLen ( flow_state . indexed_pathspecs , 30 ) self . assertLessEqual ( len ( flow_state . pending_files ) , 10 ) self . assertLessEqual ( len ( flow_state . pending_hashes ) , 10 ) for flow_pathspec in flow_state . indexed_pathspecs : self . assertIsNone ( flow_pathspec ) for flow_request_data in flow_state . request_data_list : self . assertIsNone ( flow_request_data ) for pathspec in pathspecs : urn = pathspec . AFF4Path ( self . client_id ) fd = aff4 . FACTORY . Open ( urn , token = self . token ) self . assertEqual ( "Hello" , fd . read ( ) )
Test MultiGetFile downloading many files at once.
Test MultiGetFile downloading many files at once .
"""Test MultiGetFile downloading many files at once.""" # Make 30 files to download. # Now open each file and make sure the data is there. # Check that SHA256 hash of the file matches the contents # hash and that MD5 and SHA1 are set. # Check up on the internal flow state. # All the pathspecs should be in this list. # At any one time, there should not be more than 10 files or hashes # pending. # When we finish there should be no pathspecs stored in the flow state.
self