示例#1
0
    def __init__(self, config):
        self.config = config
        self.workspace = docker.Workspace(config)
        self.clusterfuzz_deployment = (
            clusterfuzz_deployment.get_clusterfuzz_deployment(
                self.config, self.workspace))

        # Set by the initialize method.
        self.fuzz_target_paths = None
示例#2
0
 def setUp(self):
     self.setUpPyfakefs()
     config = test_helpers.create_run_config(project_name=EXAMPLE_PROJECT,
                                             build_integration_path='/',
                                             workspace=WORKSPACE,
                                             is_github=False)
     workspace = docker.Workspace(config)
     self.deployment = clusterfuzz_deployment.get_clusterfuzz_deployment(
         config, workspace)
示例#3
0
 def __init__(self, config, ci_system):
     self.config = config
     self.ci_system = ci_system
     self.workspace = docker.Workspace(config)
     self.workspace.initialize_dir(self.workspace.out)
     self.workspace.initialize_dir(self.workspace.work)
     self.image_repo_path = None
     self.host_repo_path = None
     self.repo_manager = None
示例#4
0
 def __init__(self, config, ci_system):
     self.config = config
     self.ci_system = ci_system
     self.workspace = docker.Workspace(config)
     self.workspace.initialize_dir(self.workspace.out)
     self.workspace.initialize_dir(self.workspace.work)
     self.clusterfuzz_deployment = (
         clusterfuzz_deployment.get_clusterfuzz_deployment(
             self.config, self.workspace))
     self.image_repo_path = None
     self.host_repo_path = None
     self.repo_manager = None
示例#5
0
    def test_get_clusterfuzz_deployment(self, platform,
                                        expected_deployment_cls):
        """Tests that get_clusterfuzz_deployment returns the correct value."""
        with mock.patch('config_utils.BaseConfig.platform',
                        return_value=platform,
                        new_callable=mock.PropertyMock):
            with mock.patch('filestore_utils.get_filestore',
                            return_value=None):
                config = _create_config()
                workspace = docker.Workspace(config)

                self.assertIsInstance(
                    clusterfuzz_deployment.get_clusterfuzz_deployment(
                        config, workspace), expected_deployment_cls)
示例#6
0
    def test_remove_unaffected_fuzz_targets(self, side_effect,
                                            expected_dir_len):
        """Tests that remove_unaffected_fuzzers has the intended effect."""
        config = test_helpers.create_run_config(is_github=True,
                                                project_name=EXAMPLE_PROJECT,
                                                workspace='/workspace')
        workspace = docker.Workspace(config)
        deployment = clusterfuzz_deployment.get_clusterfuzz_deployment(
            config, workspace)
        # We can't use fakefs in this test because this test executes
        # utils.is_fuzz_target_local. This function relies on the executable bit
        # being set, which doesn't work properly in fakefs.
        with tempfile.TemporaryDirectory() as tmp_dir, mock.patch(
                'get_coverage.OSSFuzzCoverage.get_files_covered_by_target'
        ) as mocked_get_files:
            with mock.patch('get_coverage._get_oss_fuzz_fuzzer_stats_dir_url',
                            return_value=1):
                mocked_get_files.side_effect = side_effect
                shutil.copy(self.TEST_FUZZER_1, tmp_dir)
                shutil.copy(self.TEST_FUZZER_2, tmp_dir)

                affected_fuzz_targets.remove_unaffected_fuzz_targets(
                    deployment, tmp_dir, [EXAMPLE_FILE_CHANGED], '')
                self.assertEqual(expected_dir_len, len(os.listdir(tmp_dir)))
示例#7
0
def _create_deployment(**kwargs):
  config = _create_config(**kwargs)
  workspace = docker.Workspace(config)
  return clusterfuzz_deployment.get_clusterfuzz_deployment(config, workspace)
示例#8
0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests the functionality of the docker module."""
import unittest
from unittest import mock

import config_utils
import docker

CONTAINER_NAME = 'example-container'
config = config_utils.RunFuzzersConfig()
config.workspace = '/workspace'
WORKSPACE = docker.Workspace(config)
SANITIZER = 'example-sanitizer'
LANGUAGE = 'example-language'


class GetProjectImageTest(unittest.TestCase):
    """Tests for get_project_image."""
    def test_get_project_image(self):
        """Tests that get_project_image_name works as intended."""
        project = 'my-project'
        self.assertEqual(docker.get_project_image_name(project),
                         'gcr.io/oss-fuzz/my-project')


class GetDeleteImagesTest(unittest.TestCase):
    """Tests for delete_images."""
示例#9
0
def create_workspace(workspace_path='/workspace'):
  """Returns a workspace located at |workspace_path| ('/workspace' by
  default)."""
  config = create_run_config(workspace=workspace_path)
  return docker.Workspace(config)