Esempio n. 1
0
def test_load_security_information_api_responses(secscan_api_response,
                                                 initialized_db):
    repository_ref = registry_model.lookup_repository("devtable", "simple")
    tag = registry_model.get_repo_tag(repository_ref, "latest")
    manifest = registry_model.get_manifest_for_tag(tag)

    registry_model.populate_legacy_images_for_testing(manifest, storage)

    legacy_image_row = shared.get_legacy_image_for_manifest(manifest._db_id)
    assert legacy_image_row is not None
    set_secscan_status(legacy_image_row, True, 3)

    secscan = V2SecurityScanner(app, instance_keys, storage)
    secscan._legacy_secscan_api = mock.Mock()
    secscan._legacy_secscan_api.get_layer_data.return_value = secscan_api_response

    security_information = secscan.load_security_information(
        manifest).security_information

    assert isinstance(security_information, SecurityInformation)
    assert security_information.Layer.Name == secscan_api_response[
        "Layer"].get("Name", "")
    assert security_information.Layer.ParentName == secscan_api_response[
        "Layer"].get("ParentName", "")
    assert security_information.Layer.IndexedByVersion == secscan_api_response[
        "Layer"].get("IndexedByVersion", None)
    assert len(security_information.Layer.Features) == len(
        secscan_api_response["Layer"].get("Features", []))
Esempio n. 2
0
def test_load_security_information_api_responses(secscan_api_response,
                                                 initialized_db):
    repository_ref = registry_model.lookup_repository("devtable", "simple")
    tag = registry_model.get_repo_tag(repository_ref,
                                      "latest",
                                      include_legacy_image=True)
    manifest = registry_model.get_manifest_for_tag(tag,
                                                   backfill_if_necessary=True,
                                                   include_legacy_image=True)
    set_secscan_status(Image.get(id=manifest.legacy_image._db_id), True, 3)

    secscan = V2SecurityScanner(app, instance_keys, storage)
    secscan._legacy_secscan_api = mock.Mock()
    secscan._legacy_secscan_api.get_layer_data.return_value = secscan_api_response

    security_information = secscan.load_security_information(
        manifest).security_information

    assert isinstance(security_information, SecurityInformation)
    assert security_information.Layer.Name == secscan_api_response[
        "Layer"].get("Name", "")
    assert security_information.Layer.ParentName == secscan_api_response[
        "Layer"].get("ParentName", "")
    assert security_information.Layer.IndexedByVersion == secscan_api_response[
        "Layer"].get("IndexedByVersion", None)
    assert len(security_information.Layer.Features) == len(
        secscan_api_response["Layer"].get("Features", []))
Esempio n. 3
0
def test_load_security_information_queued(initialized_db):
    repository_ref = registry_model.lookup_repository("devtable", "simple")
    tag = registry_model.get_repo_tag(repository_ref, "latest")
    manifest = registry_model.get_manifest_for_tag(tag)

    registry_model.populate_legacy_images_for_testing(manifest, storage)

    secscan = V2SecurityScanner(app, instance_keys, storage)
    assert secscan.load_security_information(
        manifest).status == ScanLookupStatus.NOT_YET_INDEXED
Esempio n. 4
0
def test_load_security_information_unknown_manifest(initialized_db):
    repository_ref = registry_model.lookup_repository("devtable", "simple")
    tag = registry_model.get_repo_tag(repository_ref, "latest")
    manifest = registry_model.get_manifest_for_tag(tag)

    registry_model.populate_legacy_images_for_testing(manifest, storage)

    # Delete the manifest.
    Manifest.get(id=manifest._db_id).delete_instance(recursive=True)

    secscan = V2SecurityScanner(app, instance_keys, storage)
    assert (secscan.load_security_information(manifest).status ==
            ScanLookupStatus.UNSUPPORTED_FOR_INDEXING)
Esempio n. 5
0
    def configure(self, app, instance_keys, storage):
        # TODO(alecmerdler): Just use `V4SecurityScanner` once Clair V2 is removed.
        self._model = V2SecurityScanner(app, instance_keys, storage)
        self._v4_model = V4SecurityScanner(app, instance_keys, storage)
        self._v4_namespace_whitelist = app.config.get(
            "SECURITY_SCANNER_V4_NAMESPACE_WHITELIST", [])

        logger.info("===============================")
        logger.info(
            "Using split secscan model: v4 whitelist `%s`",
            self._v4_namespace_whitelist,
        )
        logger.info("===============================")

        return self
Esempio n. 6
0
def test_load_security_information_failed_to_index(initialized_db):
    repository_ref = registry_model.lookup_repository("devtable", "simple")
    tag = registry_model.get_repo_tag(repository_ref, "latest")
    manifest = registry_model.get_manifest_for_tag(tag)

    registry_model.populate_legacy_images_for_testing(manifest, storage)

    # Set the index status.
    image = shared.get_legacy_image_for_manifest(manifest._db_id)
    image.security_indexed = False
    image.security_indexed_engine = 3
    image.save()

    secscan = V2SecurityScanner(app, instance_keys, storage)
    assert secscan.load_security_information(
        manifest).status == ScanLookupStatus.FAILED_TO_INDEX
Esempio n. 7
0
    def configure(self, app, instance_keys, storage):
        try:
            self._model = V4SecurityScanner(app, instance_keys, storage)
        except InvalidConfigurationException:
            self._model = NoopV4SecurityScanner()

        try:
            self._legacy_model = V2SecurityScanner(app, instance_keys, storage)
        except InvalidConfigurationException:
            self._legacy_model = NoopV2SecurityScanner()

        logger.info("===============================")
        logger.info("Using split secscan model: `%s`", [self._legacy_model, self._model])
        logger.info("===============================")

        return self
Esempio n. 8
0
def test_perform_indexing(initialized_db):
    secscan = V2SecurityScanner(app, instance_keys, storage)

    with pytest.raises(NotImplementedError):
        secscan.perform_indexing()
Esempio n. 9
0
 def configure(self, app, instance_keys, storage):
     self._model = V2SecurityScanner(app, instance_keys, storage)