Example #1
0
    def test_get_results_200_success(self, mock_get):
        '''
        Tests Metadefender._parse_scan_result()'s handling of a complete
        analysis report
        '''
        print('Running test_get_results_200_success')
        report_resp = Metadefender._retrieve_scan_results(
            'results_url', SCAN_IDS[0])
        is_scan_complete, parsed_resp = Metadefender._parse_scan_result(
            report_resp)
        self.assertEquals(is_scan_complete, True)
        self.assertEquals(parsed_resp['overall_status'],
                          Metadefender.STATUS_SUCCESS)

        engine_results = parsed_resp['engine_results']
        for engine_result in engine_results:
            engine_name = engine_result['engine_name']
            scan_result = engine_result['scan_result']
            threat_found = engine_result['threat_found']
            if engine_name == 'ClamAV':
                self.assertEquals(scan_result, 'Infected/Known')
                self.assertEquals(threat_found,
                                  'Heuristics.PDF.ObfuscatedNameObject')
            elif engine_name == 'Ahnlab':
                self.assertEquals(scan_result, 'Infected/Known')
                self.assertEquals(threat_found, 'Trojan/Win32.Inject.C1515213')
            elif engine_name == 'ESET':
                self.assertEquals(scan_result, 'No threats Found')
                self.assertEquals(threat_found, '')
            elif engine_name == 'Avira':
                self.assertEquals(scan_result, 'No threats Found')
                self.assertEquals(threat_found, '')
            else:
                self.fail('Unexpected Engine: %s' % engine_name)
    def test_get_results_200_success(self, mock_get):
        '''
        Tests Metadefender._parse_scan_result()'s handling of a complete
        analysis report
        '''
        print('Running test_get_results_200_success')
        report_resp = Metadefender._retrieve_scan_results('results_url', SCAN_IDS[0])
        is_scan_complete, parsed_resp = Metadefender._parse_scan_result(report_resp)
        self.assertEquals(is_scan_complete, True)
        self.assertEquals(parsed_resp['overall_status'], Metadefender.STATUS_SUCCESS)

        engine_results = parsed_resp['engine_results']
        for engine_result in engine_results:
            engine_name = engine_result['engine_name']
            scan_result = engine_result['scan_result']
            threat_found = engine_result['threat_found']
            if engine_name == 'ClamAV':
                self.assertEquals(scan_result, 'Infected/Known')
                self.assertEquals(threat_found, 'Heuristics.PDF.ObfuscatedNameObject')
            elif engine_name == 'Ahnlab':
                self.assertEquals(scan_result, 'Infected/Known')
                self.assertEquals(threat_found, 'Trojan/Win32.Inject.C1515213')
            elif engine_name == 'ESET':
                self.assertEquals(scan_result, 'No threats Found')
                self.assertEquals(threat_found, '')
            elif engine_name == 'Avira':
                self.assertEquals(scan_result, 'No threats Found')
                self.assertEquals(threat_found, '')
            else:
                self.fail('Unexpected Engine: %s' % engine_name)
    def test_get_results_200_not_found(self, mock_get):
        '''
        Tests Metadefender._parse_scan_result()'s handling of a 200 response
        where the scan ID was not found. The module is supposed to interpret
        this to mean that the analysis is 'pending'
        '''
        print('Running test_get_results_200_not_found')
        report_resp = Metadefender._retrieve_scan_results('results_url', SCAN_IDS[0])
        is_scan_complete, parsed_resp = Metadefender._parse_scan_result(report_resp)
        self.assertEquals(is_scan_complete, False)
        self.assertEquals(parsed_resp['overall_status'], Metadefender.STATUS_PENDING)

        engine_results = parsed_resp['engine_results']
        if len(engine_results) != 0:
            self.fail('Engine result list should be empty')
 def test_get_results_200_succes_in_progress(self, mock_get):
     '''
     Tests Metadefender._parse_scan_result()'s handling of a 200 response
     where the scan ID was found but the scan is not complete
     '''
     print('Running test_get_results_200_succes_in_progress')
     report_resp = Metadefender._retrieve_scan_results('results_url', SCAN_IDS[0])
     is_scan_complete, parsed_resp = Metadefender._parse_scan_result(report_resp)
     self.assertEquals(is_scan_complete, False)
     self.assertEquals(parsed_resp['overall_status'], Metadefender.STATUS_PENDING)
     msg = parsed_resp['msg']
     if 'percent complete: 10' not in msg:
         self.fail('Progress percentage not present')
     engine_results = parsed_resp['engine_results']
     if len(engine_results) != 0:
         self.fail('Engine result list should be empty')
Example #5
0
    def test_get_results_200_not_found(self, mock_get):
        '''
        Tests Metadefender._parse_scan_result()'s handling of a 200 response
        where the scan ID was not found. The module is supposed to interpret
        this to mean that the analysis is 'pending'
        '''
        print('Running test_get_results_200_not_found')
        report_resp = Metadefender._retrieve_scan_results(
            'results_url', SCAN_IDS[0])
        is_scan_complete, parsed_resp = Metadefender._parse_scan_result(
            report_resp)
        self.assertEquals(is_scan_complete, False)
        self.assertEquals(parsed_resp['overall_status'],
                          Metadefender.STATUS_PENDING)

        engine_results = parsed_resp['engine_results']
        if len(engine_results) != 0:
            self.fail('Engine result list should be empty')
Example #6
0
 def test_get_results_200_succes_in_progress(self, mock_get):
     '''
     Tests Metadefender._parse_scan_result()'s handling of a 200 response
     where the scan ID was found but the scan is not complete
     '''
     print('Running test_get_results_200_succes_in_progress')
     report_resp = Metadefender._retrieve_scan_results(
         'results_url', SCAN_IDS[0])
     is_scan_complete, parsed_resp = Metadefender._parse_scan_result(
         report_resp)
     self.assertEquals(is_scan_complete, False)
     self.assertEquals(parsed_resp['overall_status'],
                       Metadefender.STATUS_PENDING)
     msg = parsed_resp['msg']
     if 'percent complete: 10' not in msg:
         self.fail('Progress percentage not present')
     engine_results = parsed_resp['engine_results']
     if len(engine_results) != 0:
         self.fail('Engine result list should be empty')
 def test_scan_timeout_scan_in_progress(self, mock_post, mock_get):
     '''
     Test for a scan where analysis time exceeds timeout period
     '''
     print('Running test_scan_timeout_scan_in_progress')
     resultlist, metadata = Metadefender.scan(RANDOM_INPUT_FILES,
                                              conf=self.create_conf_short_timeout())
     self.assertEquals(len(resultlist), len(RANDOM_INPUT_FILES))
     for scan_res in resultlist:
         self.assertEquals(scan_res[1]['overall_status'], Metadefender.STATUS_TIMEOUT)
 def test_scan_complete_success(self, mock_post, mock_get):
     '''
     Test for a perfect scan. No submission errors, no retrieval errors
     '''
     print('Running test_scan_complete_success')
     resultlist, metadata = Metadefender.scan(RANDOM_INPUT_FILES,
                                              conf=self.create_conf_short_timeout())
     self.assertEquals(len(resultlist), len(RANDOM_INPUT_FILES))
     for scan_res in resultlist:
         self.assertEquals(scan_res[1]['overall_status'], Metadefender.STATUS_SUCCESS)
 def test_submit_sample_fail_unavailable_no_msg(self, mock_get):
     '''
     Tests Metadefender._submit_sample()'s handling of a submission that fails due to
     a 500 error and where no message is returned
     '''
     print('Running test_submit_sample_fail_unavailable_no_msg')
     submit_resp = Metadefender._submit_sample(RANDOM_INPUT_FILES[1], 'scan_url', 'user_agent')
     self.assertEquals(submit_resp['status_code'], 500)
     self.assertEquals(submit_resp['error'], Metadefender.MD_HTTP_ERR_CODES[500])
     self.assertEquals(submit_resp['scan_id'], None)
 def test_submit_sample_fail_unavailable(self, mock_get):
     '''
     Tests Metadefender._submit_sample()'s handling of a submission that fails due to
     a 500 error
     '''
     print('Running test_submit_sample_fail_unavailable')
     submit_resp = Metadefender._submit_sample(RANDOM_INPUT_FILES[1], 'scan_url', 'user_agent')
     self.assertEquals(submit_resp['status_code'], 500)
     self.assertEquals(submit_resp['error'], MSG_SERVER_UNAVAILABLE)
     self.assertEquals(submit_resp['scan_id'], None)
 def test_submit_sample_success(self, mock_get):
     '''
     Tests Metadefender._submit_sample()'s handling of a successful response from
     the server
     '''
     print('Running test_submit_sample_success')
     submit_resp = Metadefender._submit_sample(RANDOM_INPUT_FILES[0], 'scan_url', 'user_agent')
     self.assertEquals(submit_resp['status_code'], 200)
     self.assertEquals(submit_resp['error'], None)
     self.assertEquals(submit_resp['scan_id'], generate_scan_id(RANDOM_INPUT_FILES[0]))
Example #12
0
 def test_scan_timeout_scan_in_progress(self, mock_post, mock_get):
     '''
     Test for a scan where analysis time exceeds timeout period
     '''
     print('Running test_scan_timeout_scan_in_progress')
     resultlist, metadata = Metadefender.scan(
         RANDOM_INPUT_FILES, conf=self.create_conf_short_timeout())
     self.assertEquals(len(resultlist), len(RANDOM_INPUT_FILES))
     for scan_res in resultlist:
         self.assertEquals(scan_res[1]['overall_status'],
                           Metadefender.STATUS_TIMEOUT)
Example #13
0
 def test_scan_complete_success(self, mock_post, mock_get):
     '''
     Test for a perfect scan. No submission errors, no retrieval errors
     '''
     print('Running test_scan_complete_success')
     resultlist, metadata = Metadefender.scan(
         RANDOM_INPUT_FILES, conf=self.create_conf_short_timeout())
     self.assertEquals(len(resultlist), len(RANDOM_INPUT_FILES))
     for scan_res in resultlist:
         self.assertEquals(scan_res[1]['overall_status'],
                           Metadefender.STATUS_SUCCESS)
Example #14
0
 def test_submit_sample_fail_unavailable(self, mock_get):
     '''
     Tests Metadefender._submit_sample()'s handling of a submission that fails due to
     a 500 error
     '''
     print('Running test_submit_sample_fail_unavailable')
     submit_resp = Metadefender._submit_sample(RANDOM_INPUT_FILES[1],
                                               'scan_url', 'user_agent')
     self.assertEquals(submit_resp['status_code'], 500)
     self.assertEquals(submit_resp['error'], MSG_SERVER_UNAVAILABLE)
     self.assertEquals(submit_resp['scan_id'], None)
Example #15
0
 def test_submit_sample_fail_unavailable_no_msg(self, mock_get):
     '''
     Tests Metadefender._submit_sample()'s handling of a submission that fails due to
     a 500 error and where no message is returned
     '''
     print('Running test_submit_sample_fail_unavailable_no_msg')
     submit_resp = Metadefender._submit_sample(RANDOM_INPUT_FILES[1],
                                               'scan_url', 'user_agent')
     self.assertEquals(submit_resp['status_code'], 500)
     self.assertEquals(submit_resp['error'],
                       Metadefender.MD_HTTP_ERR_CODES[500])
     self.assertEquals(submit_resp['scan_id'], None)
Example #16
0
 def test_submit_sample_success(self, mock_get):
     '''
     Tests Metadefender._submit_sample()'s handling of a successful response from
     the server
     '''
     print('Running test_submit_sample_success')
     submit_resp = Metadefender._submit_sample(RANDOM_INPUT_FILES[0],
                                               'scan_url', 'user_agent')
     self.assertEquals(submit_resp['status_code'], 200)
     self.assertEquals(submit_resp['error'], None)
     self.assertEquals(submit_resp['scan_id'],
                       generate_scan_id(RANDOM_INPUT_FILES[0]))