Example #1
0
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])
Example #4
0
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
Example #5
0
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
Example #6
0
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
Example #8
0
 def test_config_file_not_exists(self, hash_1):
     with pytest.raises(FileNotFoundError):
         ioc = Hash(hash_1, config_path="idontexist.in")
Example #9
0
 def test_config_file_3(self, hash_1, config_file):
     ioc = Hash(hash_1, config_path=config_file)
Example #10
0
 def test_invalid_hash_exception(self, file_hash, hash_type,
                                 config_file):
     with pytest.raises(InvalidHashException):
         Hash(file_hash, hash_type, config_path=config_file)
Example #11
0
 def test_md5_guess_3(self, hash_1, config_file):
     with pytest.raises(InvalidHashException):
         assert Hash(hash_1, hash_type=MD5, config_path=config_file)
Example #12
0
 def test_md5_guess_2(self, hash_2, config_file):
     assert Hash(hash_2, hash_type=MD5,
                 config_path=config_file).hash_type == MD5
Example #13
0
 def test_sha256_guess_3(self, hash_2, config_file):
     with pytest.raises(InvalidHashException):
         assert Hash(hash_2, hash_type=SHA256, config_path=config_file)
Example #14
0
 def test_sha256_guess_2(self, hash_1, config_file):
     assert (Hash(hash_1, hash_type=SHA256,
                  config_path=config_file).hash_type == SHA256)