Example #1
0
    def _RunTestForApprovalForHuntCopiedFromAnotherHunt(self):
        with test_lib.FakeTime(42):
            self.CreateAdminUser("approver")

            with self.CreateHunt(description="original hunt") as hunt_obj:
                hunt1_urn = hunt_obj.urn
                hunt1_id = hunt1_urn.Basename()

            ref = rdf_hunts.FlowLikeObjectReference.FromHuntId(hunt1_id)
            with self.CreateHunt(description="copied hunt",
                                 original_object=ref) as hunt_obj:
                hunt2_urn = hunt_obj.urn
                hunt2_id = hunt2_urn.Basename()

        with test_lib.FakeTime(44):
            approval_id = self.RequestHuntApproval(hunt2_id,
                                                   reason="foo",
                                                   approver="approver")

        with test_lib.FakeTime(126):
            self.Check("GetHuntApproval",
                       args=user_plugin.ApiGetHuntApprovalArgs(
                           username=self.token.username,
                           hunt_id=hunt2_id,
                           approval_id=approval_id),
                       replace={
                           hunt1_id: "H:556677",
                           hunt2_id: "H:DDEEFF",
                           approval_id: "approval:333333"
                       })
Example #2
0
    def _RunTestForApprovalForHuntCopiedFromFlow(self):
        with test_lib.FakeTime(42):
            self.CreateAdminUser("approver")

            client_urn = self.SetupClient(0)
            flow_urn = flow.GRRFlow.StartFlow(
                flow_name=discovery.Interrogate.__name__,
                client_id=client_urn,
                token=self.token)

            ref = rdf_hunts.FlowLikeObjectReference.FromFlowIdAndClientId(
                flow_urn.Basename(), client_urn.Basename())
            with self.CreateHunt(description="hunt started from flow",
                                 original_object=ref) as hunt_obj:
                hunt_urn = hunt_obj.urn
                hunt_id = hunt_urn.Basename()

        with test_lib.FakeTime(44):
            approval_id = self.RequestHuntApproval(hunt_id,
                                                   reason="foo",
                                                   approver="approver")

        with test_lib.FakeTime(126):
            self.Check("GetHuntApproval",
                       args=user_plugin.ApiGetHuntApprovalArgs(
                           username=self.token.username,
                           hunt_id=hunt_id,
                           approval_id=approval_id),
                       replace={
                           flow_urn.Basename(): "F:112233",
                           hunt_id: "H:667788",
                           approval_id: "approval:444444"
                       })
Example #3
0
    def _RunTestForNormalApprovals(self):
        with test_lib.FakeTime(42):
            self.CreateAdminUser("approver")

            with self.CreateHunt(description="hunt1") as hunt_obj:
                hunt1_id = hunt_obj.urn.Basename()

            with self.CreateHunt(description="hunt2") as hunt_obj:
                hunt2_id = hunt_obj.urn.Basename()

        with test_lib.FakeTime(44):
            approval1_id = self.RequestHuntApproval(hunt1_id,
                                                    approver="approver",
                                                    reason="foo")

        with test_lib.FakeTime(45):
            approval2_id = self.RequestHuntApproval(hunt2_id,
                                                    approver="approver",
                                                    reason="bar")

        with test_lib.FakeTime(84):
            self.GrantHuntApproval(hunt2_id,
                                   approver="approver",
                                   approval_id=approval2_id)

        with test_lib.FakeTime(126):
            self.Check("GetHuntApproval",
                       args=user_plugin.ApiGetHuntApprovalArgs(
                           username=self.token.username,
                           hunt_id=hunt1_id,
                           approval_id=approval1_id),
                       replace={
                           hunt1_id: "H:123456",
                           approval1_id: "approval:111111"
                       })
            self.Check("GetHuntApproval",
                       args=user_plugin.ApiGetHuntApprovalArgs(
                           username=self.token.username,
                           hunt_id=hunt2_id,
                           approval_id=approval2_id),
                       replace={
                           hunt2_id: "H:567890",
                           approval2_id: "approval:222222"
                       })