Example #1
0
  def testEventsExist(self):
    event_count = 5
    host_id = _CreateUnsyncedEvents(events_per_host=event_count)[0]

    # Patch out the various _Persist methods since they're tested below.
    methods = [
        '_PersistBit9Certificates', '_PersistBit9Binary', '_PersistBanNote',
        '_PersistBit9Host', '_PersistBit9Events'
    ]
    for method in methods:
      self.Patch(sync, method, return_value=model_utils.GetNoOpFuture())

    sync.Process(host_id)

    # Verify all usage of the DatastoreLock.
    self.assertTrue(self.mock_lock.__enter__.called)
    self.assertTrue(self.mock_lock.__exit__.called)

    # Verify everything was persisted.
    self.assertEqual(event_count, sync._PersistBit9Certificates.call_count)
    self.assertEqual(event_count, sync._PersistBit9Binary.call_count)
    self.assertEqual(event_count, sync._PersistBanNote.call_count)
    self.assertEqual(event_count, sync._PersistBit9Host.call_count)
    self.assertEqual(event_count, sync._PersistBit9Events.call_count)

    self.assertEqual(event_count,
                     self.mock_events_processed.Increment.call_count)
Example #2
0
  def testAcquireLockError(self):
    self.mock_lock.__enter__.side_effect = datastore_locks.AcquireLockError()

    sync.Process(12345)

    # Verify all usage of the DatastoreLock.
    self.assertTrue(self.mock_lock.__enter__.called)
    self.assertFalse(self.mock_lock.__exit__.called)

    # Verify no work was done.
    self.assertTaskCount(constants.TASK_QUEUE.BIT9_PROCESS, 0)
    self.assertFalse(self.mock_events_processed.Increment.called)
Example #3
0
  def testInsertsCertificateRow(self):
    event, cert = _CreateEventAndCert()
    sync._UnsyncedEvent.Generate(event, [cert]).put()

    # Patch out the all methods except _PersistBit9Certificates.
    methods = [
        '_PersistBit9Binary', '_PersistBanNote',
        '_PersistBit9Host', '_PersistBit9Events']
    for method in methods:
      self.Patch(sync, method, return_value=model_utils.GetNoOpFuture())

    sync.Process(event.computer_id)

    # Should be 1 Task for the CertificateRow caused by the event.
    self.assertBigQueryInsertions([constants.BIGQUERY_TABLE.CERTIFICATE])
Example #4
0
  def testInsertsExecutionRow(self):
    event_count = 3
    host_id = _CreateUnsyncedEvents(events_per_host=event_count)[0]

    # Patch out the all methods except _PersistBit9Events.
    methods = [
        '_PersistBit9Certificates', '_PersistBit9Binary',
        '_PersistBanNote', '_PersistBit9Host']
    for method in methods:
      self.Patch(sync, method, return_value=model_utils.GetNoOpFuture())

    sync.Process(host_id)

    # Should be 3 ExecutionRows since 3 Unsynced Events were created.
    self.assertBigQueryInsertions(
        [constants.BIGQUERY_TABLE.EXECUTION] * event_count)
Example #5
0
  def testPersistsExecutionRow(self):
    event_count = 3
    host_id = self._CreateUnsyncedEvents(events_per_host=event_count)[0]

    # Patch out the all methods except _PersistBit9Events.
    methods = [
        '_PersistBit9Certificates', '_PersistBit9Binary',
        '_PersistBanNote', '_PersistBit9Host']
    for method in methods:
      self.Patch(sync, method, return_value=model_utils.GetNoOpFuture())

    sync.Process(host_id)

    # Should be 3 ExecutionRows since 3 Unsynced Events were created.
    self.assertTaskCount(constants.TASK_QUEUE.BQ_PERSISTENCE, event_count)
    self.RunDeferredTasks(constants.TASK_QUEUE.BQ_PERSISTENCE)
    self.assertEntityCount(bigquery_db.ExecutionRow, event_count)
Example #6
0
  def testPersistsCertificateRow(self):
    event, signing_chain = _CreateEventTuple()
    sync._UnsyncedEvent.Generate(event, signing_chain).put()

    # Patch out the all methods except _PersistBit9Certificates.
    methods = [
        '_PersistBit9Binary', '_PersistBanNote',
        '_PersistBit9Host', '_PersistBit9Events']
    for method in methods:
      self.Patch(sync, method, return_value=model_utils.GetNoOpFuture())

    sync.Process(event.computer_id)

    # Should be 1 Task for the CertificateRow caused by the event.
    self.assertTaskCount(constants.TASK_QUEUE.BQ_PERSISTENCE, 1)
    self.RunDeferredTasks(constants.TASK_QUEUE.BQ_PERSISTENCE)
    self.assertEntityCount(bigquery_db.CertificateRow, 1)