def testCreatesHuntFor2FilesSingleClient(self): args = hunt_plugin.ApiCreatePerClientFileCollectionHuntArgs( description="Per-client file collection", per_client_args=[ hunt_plugin.PerClientFileCollectionArgs( client_id=self.client_id, paths=["/etc/hosts", "/foo/bar"], ), ]) result = self.handler.Handle(args, self.context) self.assertTrue(result.hunt_id)
def testFailsWhenMoreThan1000FilesScheduledForCollection(self): args = hunt_plugin.ApiCreatePerClientFileCollectionHuntArgs( description="Per-client file collection", per_client_args=[ hunt_plugin.PerClientFileCollectionArgs( client_id=self.client_id, paths=[f"/etc/hosts/{i}" for i in range(1001)], ), ]) with self.assertRaises(ValueError): self.handler.Handle(args, self.context)
def testFailsWhenMoreThan250ClientsScheduledForCollection(self): args = hunt_plugin.ApiCreatePerClientFileCollectionHuntArgs( description="Per-client file collection", per_client_args=[]) # Ensure that we get 251 unique client ids. client_ids = set() while len(client_ids) < 251: client_id = db_test_utils.InitializeClient(data_store.REL_DB) client_ids.add(client_id) args.per_client_args.append( hunt_plugin.PerClientFileCollectionArgs( client_id=client_id, paths=["/etc/hosts"], )) with self.assertRaises(ValueError): self.handler.Handle(args, self.context)
def Run(self): client_id = self.SetupClient(0) with test_lib.FakeTime(42): def ReplaceHuntId(): hunts = data_store.REL_DB.ListHuntObjects(0, 1) return {hunts[0].hunt_id: "H:123456"} self.Check( "CreatePerClientFileCollectionHunt", args=hunt_plugin.ApiCreatePerClientFileCollectionHuntArgs( description="Per-client file collection", per_client_args=[ hunt_plugin.PerClientFileCollectionArgs( client_id=client_id, paths=["/etc/hosts", "/foo/bar"], ), ]), replace=ReplaceHuntId)