def testArtifactCollectorWorksWhenEnabledAndArgumentsAreCorrect(self): router = None def Check(artifacts): router.CreateFlow(api_flow.ApiCreateFlowArgs( flow=api_flow.ApiFlow( name=collectors.ArtifactCollectorFlow.__name__, args=artifact_utils.ArtifactCollectorFlowArgs( artifact_list=artifacts)), client_id=self.client_id), token=self.token) router = self._CreateRouter( artifact_collector_flow=rr.RobotRouterArtifactCollectorFlowParams( enabled=True)) Check([]) router = self._CreateRouter( artifact_collector_flow=rr.RobotRouterArtifactCollectorFlowParams( enabled=True, artifacts_whitelist=["foo"])) Check(["foo"]) router = self._CreateRouter( artifact_collector_flow=rr.RobotRouterArtifactCollectorFlowParams( enabled=True, artifacts_whitelist=["foo", "bar", "blah"])) Check(["foo", "blah"])
def testGetFlowFilesArchiveReturnsNonLimitedHandlerForArtifactsWhenNeeded( self): router = self._CreateRouter( artifact_collector_flow=rr.RobotRouterArtifactCollectorFlowParams( artifact_collector_flow_name=AnotherArtifactCollector.__name__ ), get_flow_files_archive=rr.RobotRouterGetFlowFilesArchiveParams( enabled=True, skip_glob_checks_for_artifact_collector=True, path_globs_blacklist=["**/*.txt"], path_globs_whitelist=["foo/*", "bar/*"])) flow_id = self._CreateFlowWithRobotId() handler = router.GetFlowFilesArchive( api_flow.ApiGetFlowFilesArchiveArgs(client_id=self.client_id, flow_id=flow_id), token=self.token) self.assertEqual(handler.path_globs_blacklist, ["**/*.txt"]) self.assertEqual(handler.path_globs_whitelist, ["foo/*", "bar/*"]) flow_id = self._CreateFlowWithRobotId( flow_name=AnotherArtifactCollector.__name__, flow_args=artifact_utils.ArtifactCollectorFlowArgs( artifact_list=["Foo"])) handler = router.GetFlowFilesArchive( api_flow.ApiGetFlowFilesArchiveArgs(client_id=self.client_id, flow_id=flow_id), token=self.token) self.assertTrue(handler.path_globs_blacklist is None) self.assertTrue(handler.path_globs_whitelist is None)
def testOnlyFileFinderAndArtifactCollectorFlowsAreAllowed(self): router = self._CreateRouter( file_finder_flow=rr.RobotRouterFileFinderFlowParams(enabled=True), artifact_collector_flow=rr.RobotRouterArtifactCollectorFlowParams( enabled=True)) with self.assertRaises(access_control.UnauthorizedAccess): router.CreateFlow(api_flow.ApiCreateFlowArgs( flow=api_flow.ApiFlow(name=flow_test_lib.BrokenFlow.__name__), client_id=self.client_id), token=self.token)
def testArtifactCollectorRaisesWhenEnabledButArgumentsNotCorrect(self): router = None def Check(artifacts): with self.assertRaises(access_control.UnauthorizedAccess): router.CreateFlow(api_flow.ApiCreateFlowArgs( flow=api_flow.ApiFlow( name=collectors.ArtifactCollectorFlow.__name__, args=artifact_utils.ArtifactCollectorFlowArgs( artifact_list=artifacts)), client_id=self.client_id), token=self.token) router = self._CreateRouter( artifact_collector_flow=rr.RobotRouterArtifactCollectorFlowParams( enabled=True)) Check(["foo"]) router = self._CreateRouter( artifact_collector_flow=rr.RobotRouterArtifactCollectorFlowParams( enabled=True, artifacts_whitelist=["bar", "blah"])) Check(["foo", "bar"])
def testArtifactCollectorFlowNameCanBeOverriden(self): router = self._CreateRouter( artifact_collector_flow=rr.RobotRouterArtifactCollectorFlowParams( enabled=True, artifact_collector_flow_name=AnotherArtifactCollector.__name__) ) with self.assertRaises(access_control.UnauthorizedAccess): router.CreateFlow(api_flow.ApiCreateFlowArgs( flow=api_flow.ApiFlow( name=collectors.ArtifactCollectorFlow.__name__), client_id=self.client_id), token=self.token) router.CreateFlow(api_flow.ApiCreateFlowArgs( flow=api_flow.ApiFlow(name=AnotherArtifactCollector.__name__), client_id=self.client_id), token=self.token)