def test_bulk_inputs(response, config_file): fake_hash = "73bef2ac39be261ae9a06076302c1d0af982e0560e88ac168980fab6ea5dd9c4" with patch.object(VirusTotal, "_get_api_response", return_value=response): sample = Hash(fake_hash, config_path=config_file) sample.check(services=[VirusTotal]) propnames = [name for (name, value) in inspect.getmembers(sample, isprop)] for prop in propnames: getattr(sample, prop) propnames = [ name for (name, value) in inspect.getmembers(sample.reports, isprop) ] for prop in propnames: getattr(sample, prop) propnames = [ name for (name, value) in inspect.getmembers( sample.reports.malwarebazaar, isprop ) ] for prop in propnames: getattr(sample, prop)
def test_no_credential_error(self, hash_1, config_file): with patch("ioccheck.services.service.Credentials") as MockCredentials: instance = MockCredentials.return_value instance.api_key = None with pytest.raises(InvalidCredentialsError): sample = Hash(hash_1, config_path=config_file) sample.check(services=[VirusTotal])
def test_error_chaining(self, hash_1, config_file): """vt.Client errors should be caught and chained as our own APIError""" with patch("vt.Client") as MockClass: MockClass.side_effect = vt.error.APIError("foo", "bar") sample = Hash(hash_1, config_path=config_file) with pytest.raises(APIError): sample.check(services=[VirusTotal])
def virustotal_bad_response_1(virustotal_mocked_response_1, hash_1, config_file): with patch.object( VirusTotal, "_get_api_response", return_value=None ) as mock_method: mock_api_response = virustotal_mocked_response_1 sample = Hash(hash_1, config_path=config_file) sample.check(services=[VirusTotal]) return sample
def virustotal_report_1(virustotal_mocked_response_1, hash_1, config_file): """ VirusTotal report generated from virustotal_mocked_response_1 """ with patch.object( VirusTotal, "_get_api_response", return_value=virustotal_mocked_response_1 ) as mock_method: mock_api_response = virustotal_mocked_response_1 sample = Hash(hash_1, config_path=config_file) sample.check(services=[VirusTotal]) return sample
def malwarebazaar_report_1(malwarebazaar_mocked_response_1, hash_1, config_file): """ MalwareBazaar report generated from malware_mocked_response_1 """ with patch.object( MalwareBazaar, "_get_api_response", return_value=malwarebazaar_mocked_response_1 ) as mock_method: mock_api_response = malwarebazaar_mocked_response_1 sample = Hash(hash_1, config_path=config_file) sample.check(services=[MalwareBazaar]) return sample
def test_empty_detections_attribute_error(self, hash_1, config_file): def side_effect(*args): raise AttributeError with patch.object(VirusTotal, "_get_api_response", side_effect=side_effect): sample = Hash(hash_1, config_path=config_file) with pytest.raises(AttributeError): sample.check(services=[VirusTotal]) assert sample.detections is None