Beispiel #1
0
    def test_try_filetype_with_coverage_via_afl_fail(
            self, subprocess_check_output: unittest.mock.MagicMock):
        binary_path = "tshark"
        repo_path = ""
        max_timeout = 2500
        memory_limit = "none"

        h = HeuristicConfigCreator(binary_path=binary_path,
                                   repo_path=repo_path,
                                   dummyfiles_path=os.getcwd())
        h.MAX_TIMEOUT = max_timeout
        h.memory_limit = memory_limit
        h.FAILED_INVOCATIONS_THRESHOLD = 2
        h.afl_cmin_path = "afl-cmin"
        mocked_return_value = "cmin-output"
        subprocess_check_output.return_value = bytes(mocked_return_value,
                                                     encoding="utf-8")
        subprocess_check_output.side_effect = subprocess.CalledProcessError(
            returncode=-1, cmd="alja")
        h.try_filetype_with_coverage_via_afl("-f",
                                             os.getcwd(),
                                             file_type=".test")
        with self.assertRaises(helpers.exceptions.NoCoverageInformation):
            h.try_filetype_with_coverage_via_afl("-g",
                                                 os.getcwd(),
                                                 file_type=".test")
Beispiel #2
0
    def test_ingestFails_raisesError(
        self, mock_ingest: unittest.mock.MagicMock
    ) -> None:
        # Arrange
        mock_ingest.side_effect = ValueError("Malformed manifest")

        # Act
        request_args = {"manifest_path": "gs://fake-bucket/foo/manifest.yaml"}
        headers = {"X-Appengine-Cron": "test-cron"}
        with self.assertRaisesRegex(ValueError, "Malformed manifest"):
            self.client.get("/ingest", query_string=request_args, headers=headers)

        # Assert
        mock_ingest.assert_called_with(
            ANY, GcsfsFilePath(bucket_name="fake-bucket", blob_name="foo/manifest.yaml")
        )
    def test_get_info_gaierror(self,
                               addrinfo_path: unittest.mock.MagicMock) -> None:
        """
        Tests the method which let us get the information to work with for the
        case that we get an gaierror exception.
        """
        def fake_hostbyaddr(*args, **kwargs):
            raise socket.gaierror("This is a test :-)")

        addrinfo_path.side_effect = fake_hostbyaddr

        given = "example.org"

        expected = dict()  # pylint: disable=use-dict-literal
        actual = HostByAddrInfo(given).get_info()

        self.assertEqual(expected, actual)
Beispiel #4
0
    def test_get_info_gaierror(self,
                               addrinfo_path: unittest.mock.MagicMock) -> None:
        """
        Tests the method which let us get the information to work with for the
        case that we get an gaierror exception.
        """
        def fake_getattrinfo(*args, **kwargs):
            raise socket.gaierror("This is a test :-)")

        addrinfo_path.side_effect = fake_getattrinfo

        given = "example.org"

        expected = []
        actual = AddressInfo(given).get_info()

        self.assertEqual(expected, actual)
Beispiel #5
0
    def test_get_info(self, addrinfo_path: unittest.mock.MagicMock) -> None:
        """
        Tests the method which let us get the information to work with.
        """
        def fake_getattrinfo(*args, **kwargs):
            _ = args
            _ = kwargs
            return [("192.169.1.1", "10.20.30.40", ["10.55.0.32"])]

        addrinfo_path.side_effect = fake_getattrinfo

        given = "example.org"

        expected = ["10.55.0.32"]
        actual = AddressInfo(given).get_info()

        self.assertEqual(expected, actual)
Beispiel #6
0
    def test_ingestFails_raisesError(
            self, mock_ingest: unittest.mock.MagicMock) -> None:
        # Arrange
        mock_ingest.side_effect = ValueError("Malformed manifest")

        # Act
        request_args = {"manifest_path": "gs://fake-bucket/foo/manifest.yaml"}
        headers = {"X-Appengine-Cron": "test-cron"}
        response = self.client.get("/ingest",
                                   query_string=request_args,
                                   headers=headers)

        # Assert
        self.assertEqual(500, response.status_code)
        self.assertEqual("Error ingesting data: 'Malformed manifest'",
                         response.get_data().decode())
        mock_ingest.assert_called_with(
            ANY,
            GcsfsFilePath(bucket_name="fake-bucket",
                          blob_name="foo/manifest.yaml"))
    def test_get_info(self, addrinfo_path: unittest.mock.MagicMock) -> None:
        """
        Tests the method which let us get the information to work with.
        """
        def fake_hostbyaddr(*args, **kwargs):
            _ = args
            _ = kwargs
            return [
                "www.example.org", ["example.org", "example.net"],
                ["10.55.39.20"]
            ]

        addrinfo_path.side_effect = fake_hostbyaddr

        given = "example.org"

        expected = {
            "hostname": "www.example.org",
            "aliases": ["example.org", "example.net"],
            "ips": ["10.55.39.20"],
        }
        actual = HostByAddrInfo(given).get_info()

        self.assertEqual(expected, actual)