Ejemplo n.º 1
0
    def Run(self):
        with test_lib.FakeTime(42):
            self.CreateAdminUser("requestor")

            cron_manager = aff4_cronjobs.CronManager()
            cron_args = aff4_cronjobs.CreateCronJobFlowArgs(
                periodicity="1d", allow_overruns=False)
            cron_urn = cron_manager.ScheduleFlow(cron_args=cron_args,
                                                 token=self.token)

        with test_lib.FakeTime(44):
            approval_id = self.RequestCronJobApproval(
                cron_urn.Basename(),
                approver=self.token.username,
                requestor="requestor",
                reason="foo")

        with test_lib.FakeTime(126):
            self.Check("GrantCronJobApproval",
                       args=user_plugin.ApiGrantCronJobApprovalArgs(
                           cron_job_id=cron_urn.Basename(),
                           approval_id=approval_id,
                           username="******"),
                       replace={
                           cron_urn.Basename(): "CronJob_123456",
                           approval_id: "approval:111111"
                       })
Ejemplo n.º 2
0
    def GrantCronJobApproval(self,
                             cron_job_id,
                             requestor=None,
                             approval_id=None,
                             approver="approver",
                             admin=True):
        """Grants an approval for a given cron job."""
        if not requestor:
            requestor = self.token.username

        if not approval_id:
            raise ValueError("approval_id can't be empty.")

        self.CreateUser(requestor)
        if admin:
            self.CreateAdminUser(approver)
        else:
            self.CreateUser(approver)

        args = api_user.ApiGrantCronJobApprovalArgs(cron_job_id=cron_job_id,
                                                    username=requestor,
                                                    approval_id=approval_id)
        handler = api_user.ApiGrantCronJobApprovalHandler()
        handler.Handle(args, token=access_control.ACLToken(username=approver))