示例#1
0
    def test_successful_contract_audit_request_dockerhub_fail_multiple_analyzers(self):
        """
        Tests that a report is generated when the dockerhub fails
        """
        # Replace analyzers with a single dockerhub fail analyzer
        faulty_wrapper = Wrapper(
            wrappers_dir="{0}/tests/resources/wrappers".format(project_root()),
            analyzer_name="dockerhub_fail",
            args="",
            storage_dir="/tmp/{}{}".format(time(), random()),
            timeout_sec=60,
            prefetch=False
        )
        analyzer = Analyzer(faulty_wrapper)
        original_analyzers = self.__audit_node.config._Config__analyzers
        original_analyzers_config = self.__audit_node.config._Config__analyzers_config
        self.__audit_node.config._Config__analyzers[1] = analyzer
        self.__audit_node.config._Config__analyzers_config[1] = {"dockerhub_fail": analyzer}

        # since we're mocking the smart contract, we should explicitly call its internals
        buggy_contract = resource_uri("DAOBug.sol")
        self.__request_audit(buggy_contract, self.__PRICE)

        self.__evt_wait_loop(self.__submitReport_filter)

        # NOTE: if the audit node later requires the stubbed fields, this will have to change a bit
        self.__send_done_message(self.__REQUEST_ID)
        self.__assert_audit_request_report(self.__REQUEST_ID,
                                           report_file_path="reports/DockerhubFailAllAnalyzers.json")
        self.__assert_all_analyzers(self.__REQUEST_ID)

        # set the values back
        self.__audit_node.config._Config__analyzers = original_analyzers
        self.__audit_node.config._Config__analyzers_config = original_analyzers_config

        compressed_report = self.__compress_report("reports/DockerhubFailAllAnalyzers.json")

        # asserting the database content
        expected_row = {"request_id": 1,
                        "requestor": self.__config.account,
                        "contract_uri": buggy_contract,
                        "evt_name": "LogAuditAssigned",
                        'assigned_block_nbr': "IGNORE",
                        "submission_block_nbr": "IGNORE",
                        "fk_status": "DN",
                        "fk_type": "AU",
                        "price": str(self.__PRICE),
                        "status_info": "Report successfully submitted",
                        "tx_hash": "IGNORE",
                        "submission_attempts": 1,
                        "is_persisted": 1,
                        "audit_uri": "IGNORE",
                        "audit_hash": "IGNORE",
                        "audit_state": 5,
                        "full_report": "IGNORE",
                        "compressed_report": compressed_report
                        }
        self.assert_event_table_contains(self.__config, [expected_row],
                                          ignore_keys=[key for key in expected_row if expected_row[key] == "IGNORE"])
示例#2
0
 def __new_analyzer(timeout_sec=60, prefetch=False):
     faulty_wrapper = Wrapper(
         wrappers_dir="{0}/tests/resources/wrappers".format(project_root()),
         analyzer_name="dockerhub_fail",
         args="",
         storage_dir="/tmp/./dockerhub_fail/{}{}".format(time(), random()),
         timeout_sec=timeout_sec,
         prefetch=prefetch)
     return Analyzer(faulty_wrapper)
 def __new_analyzer(timeout_sec=600):
     securify_wrapper = Wrapper(
         wrappers_dir="{0}/plugins/analyzers/wrappers".format(
             project_root()),
         analyzer_name="securify",
         args="",
         storage_dir="/tmp/{}{}".format(time(), random()),
         timeout_sec=timeout_sec,
     )
     return Analyzer(securify_wrapper)
示例#4
0
    def create_analyzers(self, analyzers_config):
        """
        Creates an instance of the each target analyzer that should be verifying a given contract.
        """
        default_timeout_sec = 60
        default_storage = gettempdir()
        analyzers = []

        for i, analyzer_config_dict in enumerate(analyzers_config):
            # Each analyzer config is a dictionary of a single entry
            # <analyzer_name> -> {
            #     analyzer dictionary configuration
            # }

            # Gets ths single key in the dictionary (the name of the analyzer)
            analyzer_name = list(analyzer_config_dict.keys())[0]
            analyzer_config = analyzers_config[i][analyzer_name]
            script_path = os.path.realpath(__file__)
            wrappers_dir = '{0}/../../../plugins/analyzers/wrappers'.format(os.path.dirname(script_path))

            wrapper = Wrapper(
                wrappers_dir=wrappers_dir,
                analyzer_name=analyzer_name,
                args=analyzer_config.get('args', ""),
                storage_dir=analyzer_config.get('storage_dir', default_storage),
                timeout_sec=analyzer_config.get('timeout_sec', default_timeout_sec)
            )

            default_storage = "{0}/.{1}".format(
                str(Path.home()),
                analyzer_name,
            )

            analyzers.append(Analyzer(wrapper))

        return analyzers