예제 #1
0
    def Run(self):
        with test_lib.FakeTime(42):
            self.CreateUser("approver")

            with self.CreateHunt(description="foo") as hunt_obj:
                hunt_id = hunt_obj.urn.Basename()

        def ReplaceHuntAndApprovalIds():
            approvals = list(
                aff4.FACTORY.ListChildren(
                    aff4.ROOT_URN.Add("ACL").Add("hunts").Add(hunt_id).Add(
                        self.token.username)))

            return {
                approvals[0].Basename(): "approval:112233",
                hunt_id: "H:123456"
            }

        with test_lib.FakeTime(126):
            self.Check("CreateHuntApproval",
                       args=user_plugin.ApiCreateHuntApprovalArgs(
                           hunt_id=hunt_id,
                           approval=user_plugin.ApiHuntApproval(
                               reason="really important reason!",
                               notified_users=["approver1", "approver2"],
                               email_cc_addresses=["*****@*****.**"])),
                       replace=ReplaceHuntAndApprovalIds)
예제 #2
0
    def RequestHuntApproval(self,
                            hunt_id,
                            requestor=None,
                            reason=None,
                            email_cc_address=None,
                            approver="approver"):
        """Request hunt approval for a given hunt."""

        if not requestor:
            requestor = self.token.username

        if not reason:
            reason = self.token.reason

        self.CreateUser(requestor)
        self.CreateUser(approver)

        args = api_user.ApiCreateHuntApprovalArgs(
            hunt_id=hunt_id,
            approval=api_user.ApiHuntApproval(
                reason=reason,
                notified_users=[approver],
                email_cc_addresses=([email_cc_address]
                                    if email_cc_address else [])))
        handler = api_user.ApiCreateHuntApprovalHandler()
        result = handler.Handle(
            args, token=access_control.ACLToken(username=requestor))

        return result.id
예제 #3
0
    def setUp(self):
        super(ApiCreateHuntApprovalHandlerTest, self).setUp()

        self.SetUpApprovalTest()

        with self.CreateHunt(description="foo") as hunt_obj:
            hunt_id = hunt_obj.urn.Basename()

        self.handler = user_plugin.ApiCreateHuntApprovalHandler()

        self.args = user_plugin.ApiCreateHuntApprovalArgs(hunt_id=hunt_id)
        self.args.approval.reason = self.token.reason
        self.args.approval.notified_users = ["approver"]
        self.args.approval.email_cc_addresses = ["*****@*****.**"]