Esempio n. 1
0
  def testInvalidStateChangeError(self):

    host_key = test_utils.CreateBit9Host().key
    exm_key = test_utils.CreateExemption(
        host_key.id(), initial_state=_STATE.APPROVED)

    with self.assertRaises(api.InvalidStateChangeError):
      api.Escalate(exm_key)
    self.assertEqual(_STATE.APPROVED, exm_key.get().state)
Esempio n. 2
0
  def testSuccess(self):
    host_key = test_utils.CreateBit9Host().key
    exm_key = test_utils.CreateExemption(
        host_key.id(), initial_state=_STATE.PENDING)

    api.Escalate(exm_key)
    exm = exm_key.get()

    self.assertEqual(_STATE.ESCALATED, exm.state)
    self.assertBigQueryInsertion(constants.BIGQUERY_TABLE.EXEMPTION)
Esempio n. 3
0
    def post(self, host_id):

        if not self.exm:
            self.abort(httplib.NOT_FOUND, explanation='Exemption not found')

        # Humans should never trigger the transition from PENDING to ESCALATED, only
        # api.Process() should.
        if self.exm.key.get().state == constants.EXEMPTION_STATE.PENDING:
            self.abort(httplib.FORBIDDEN,
                       explanation='Cannot escalate a pending request')

        try:
            exemption_api.Escalate(self.exm.key)
        except Exception:  # pylint: disable=broad-except
            logging.exception(
                'Error encountered while escalating Exemption for host %s',
                host_id)
            self.abort(httplib.INTERNAL_SERVER_ERROR,
                       explanation='Error while escalating exemption')