Пример #1
0
    def __init__(self, client, verifier, hasher, db, cert_db, log_key,
                 state_keeper):
        self.__client = client
        self.__verifier = verifier
        self.__hasher = hasher
        self.__db = db
        self.__state_keeper = state_keeper

        # TODO(ekasper): once consistency checks are in place, also load/store
        # Merkle tree info.
        # Depends on: Merkle trees implemented in Python.
        self.__state = client_pb2.MonitorState()
        self.__report = aggregated_reporter.AggregatedCertificateReport(
            (text_reporter.TextCertificateReport(),
             db_reporter.CertDBCertificateReport(cert_db, log_key)))
        try:
            self.__state = self.__state_keeper.read(client_pb2.MonitorState)
        except state.FileNotFoundError:
            # TODO(ekasper): initialize state file with a setup script, so we
            # can raise with certainty when it's not found.
            logging.warning("Monitor state file not found, assuming first "
                            "run.")
        else:
            if not self.__state.HasField("verified_sth"):
                logging.warning(
                    "No verified monitor state, assuming first run.")

        # load compact merkle tree state from the monitor state
        self._verified_tree = merkle.CompactMerkleTree(hasher)
        self._unverified_tree = merkle.CompactMerkleTree(hasher)
        self._verified_tree.load(self.__state.verified_tree)
        self._unverified_tree.load(self.__state.unverified_tree)
 def test_report(self):
     db = mock.MagicMock()
     reporter = db_reporter.CertDBCertificateReport(db, 1, checks=[])
     for j in range(1, 6):
         for i in range(0, 10):
             reporter._batch_scanned_callback([(None, None, None)])
         reporter.report()
         self.assertEqual(db.store_certs_desc.call_count, 10 * j)
    def test_db_raising_does_not_stall_reporter(self):
        db = mock.Mock()
        db.store_certs_desc.side_effect = [ValueError("Boom!"), None]

        reporter = db_reporter.CertDBCertificateReport(db, 1, checks=[])
        reporter._batch_scanned_callback([(None, None, None)])
        reporter._batch_scanned_callback([(None, None, None)])
        reporter.report()
        self.assertEqual(db.store_certs_desc.call_count, 2)