Example #1
0
    def _RunTestForApprovalForHuntCopiedFromAnotherHunt(self):
        with test_lib.FakeTime(42):
            self.CreateAdminUser(u"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=u"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(u"approver")

      client_urn = self.SetupClient(0)
      flow_urn = flow.StartAFF4Flow(
          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=u"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(u"approver")

            hunt1_id = self.StartHunt(description="hunt1",
                                      paused=True,
                                      creator=self.token.username)
            hunt2_id = self.StartHunt(description="hunt2",
                                      paused=True,
                                      creator=self.token.username)

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

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

        with test_lib.FakeTime(84):
            self.GrantHuntApproval(hunt2_id,
                                   approver=u"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"
                       })
Example #4
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"
                       })
Example #5
0
  def _RunTestForApprovalForHuntCopiedFromFlow(self):
    with test_lib.FakeTime(42):
      self.CreateAdminUser(u"approver")

      client_id = self.SetupClient(0)
      flow_id = flow_test_lib.StartFlow(
          discovery.Interrogate,
          client_id=client_id,
          creator=self.test_username,
          notify_to_user=True)

      ref = rdf_hunts.FlowLikeObjectReference.FromFlowIdAndClientId(
          flow_id, client_id)
      hunt_id = self.StartHunt(
          description="hunt started from flow",
          original_object=ref,
          paused=True,
          creator=self.test_username)

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

    with test_lib.FakeTime(126):
      self.Check(
          "GetHuntApproval",
          args=user_plugin.ApiGetHuntApprovalArgs(
              username=self.test_username,
              hunt_id=hunt_id,
              approval_id=approval_id),
          replace={
              # TODO(user): remove this replacement as soon as REL_DB
              # migration is done.
              "%s/%s" % (client_id, flow_id):
                  "%s/flows/F:112233" % (client_id),
              flow_id:
                  "F:112233",
              hunt_id:
                  "H:667788",
              approval_id:
                  "approval:444444"
          })