Esempio n. 1
0
    def testFileFinderWorksWhenEnabledAndArgumentsAreCorrect(self):
        router = None

        def Check(path):
            router.CreateFlow(api_flow.ApiCreateFlowArgs(
                flow=api_flow.ApiFlow(
                    name=file_finder.FileFinder.__name__,
                    args=rdf_file_finder.FileFinderArgs(paths=[path])),
                client_id=self.client_id),
                              token=self.token)

        router = self._CreateRouter(
            file_finder_flow=rr.RobotRouterFileFinderFlowParams(enabled=True))
        Check("/foo/bar")

        router = self._CreateRouter(
            file_finder_flow=rr.RobotRouterFileFinderFlowParams(
                enabled=True, globs_allowed=True))
        Check("/foo/bar/**/*")

        router = self._CreateRouter(
            file_finder_flow=rr.RobotRouterFileFinderFlowParams(
                enabled=True, interpolations_allowed=True))
        Check("%%users.homedir%%/foo")

        router = self._CreateRouter(
            file_finder_flow=rr.RobotRouterFileFinderFlowParams(
                enabled=True, globs_allowed=True, interpolations_allowed=True))
        Check("%%users.homedir%%/foo/**/*")
Esempio n. 2
0
    def testFileFinderRaisesWhenEnabledButArgumentsNotCorrect(self):
        router = None

        def Check(path):
            with self.assertRaises(access_control.UnauthorizedAccess):
                router.CreateFlow(api_flow.ApiCreateFlowArgs(
                    flow=api_flow.ApiFlow(
                        name=file_finder.FileFinder.__name__,
                        args=rdf_file_finder.FileFinderArgs(paths=[path])),
                    client_id=self.client_id),
                                  token=self.token)

        router = self._CreateRouter(
            file_finder_flow=rr.RobotRouterFileFinderFlowParams(enabled=True))
        Check("/foo/bar/**/*")

        router = self._CreateRouter(
            file_finder_flow=rr.RobotRouterFileFinderFlowParams(enabled=True))
        Check("%%users.homedir%%/foo")
Esempio n. 3
0
    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=test_lib.BrokenFlow.__name__),
                client_id=self.client_id),
                              token=self.token)
Esempio n. 4
0
    def testFileFinderFlowNameCanBeOverriden(self):
        router = self._CreateRouter(
            file_finder_flow=rr.RobotRouterFileFinderFlowParams(
                enabled=True,
                file_finder_flow_name=AnotherFileFinder.__name__))

        with self.assertRaises(access_control.UnauthorizedAccess):
            router.CreateFlow(api_flow.ApiCreateFlowArgs(
                flow=api_flow.ApiFlow(name=file_finder.FileFinder.__name__),
                client_id=self.client_id),
                              token=self.token)

        router.CreateFlow(api_flow.ApiCreateFlowArgs(
            flow=api_flow.ApiFlow(name=AnotherFileFinder.__name__),
            client_id=self.client_id),
                          token=self.token)
    def testFileFinderHashMaxFileSizeCanBeOverriden(self):
        router = self._CreateRouter(
            file_finder_flow=rr.RobotRouterFileFinderFlowParams(
                enabled=True, max_file_size=42))

        ha = rdf_file_finder.FileFinderHashActionOptions()
        ha.max_size = 80
        ha.oversized_file_policy = ha.OversizedFilePolicy.HASH_TRUNCATED

        path = "/foo/bar"
        handler = router.CreateFlow(api_flow.ApiCreateFlowArgs(
            flow=api_flow.ApiFlow(name=file_finder.FileFinder.__name__,
                                  args=rdf_file_finder.FileFinderArgs(
                                      paths=[path],
                                      action=rdf_file_finder.FileFinderAction(
                                          action_type="HASH", hash=ha))),
            client_id=self.client_id),
                                    token=self.token)

        ha = handler.override_flow_args.action.hash
        self.assertEqual(ha.oversized_file_policy, ha.OversizedFilePolicy.SKIP)
        self.assertEqual(ha.max_size, 42)
    def testFileFinderDownloadMaxFileSizeCanBeOverriden(self):
        router = self._CreateRouter(
            file_finder_flow=rr.RobotRouterFileFinderFlowParams(
                enabled=True, max_file_size=42))

        da = rdf_file_finder.FileFinderDownloadActionOptions()
        da.max_size = 80
        da.oversized_file_policy = da.OversizedFilePolicy.DOWNLOAD_TRUNCATED

        path = "/foo/bar"
        handler = router.CreateFlow(api_flow.ApiCreateFlowArgs(
            flow=api_flow.ApiFlow(name=file_finder.FileFinder.__name__,
                                  args=rdf_file_finder.FileFinderArgs(
                                      paths=[path],
                                      action=rdf_file_finder.FileFinderAction(
                                          action_type="DOWNLOAD",
                                          download=da))),
            client_id=self.client_id),
                                    token=self.token)

        da = handler.override_flow_args.action.download
        self.assertEqual(da.oversized_file_policy, da.OversizedFilePolicy.SKIP)
        self.assertEqual(da.max_size, 42)