-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update generate_sbom to process cachi2 results. SBOM must be combined from cachi2 SBOM stored in build_dir in this case. Signed-off-by: Martin Basti <[email protected]>
- Loading branch information
1 parent
7b2ce79
commit c1e1ce5
Showing
2 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ | |
REPO_FETCH_ARTIFACTS_KOJI, | ||
REPO_FETCH_ARTIFACTS_URL, | ||
PLUGIN_CHECK_AND_SET_PLATFORMS_KEY, | ||
PLUGIN_CACHI2_POSTPROCESS, | ||
CACHI2_BUILD_DIR, | ||
) | ||
from atomic_reactor.plugin import PluginFailedException | ||
from atomic_reactor.plugins.generate_sbom import GenerateSbomPlugin | ||
|
@@ -1065,7 +1067,7 @@ def teardown_function(*args): | |
sys.modules.pop(GenerateSbomPlugin.key, None) | ||
|
||
|
||
def mock_env(workflow, df_images): | ||
def mock_env(workflow, df_images, cachi2=False): | ||
tmp_dir = tempfile.mkdtemp() | ||
dockerconfig_contents = {"auths": {LOCALHOST_REGISTRY: {"username": "user", | ||
"email": "[email protected]", | ||
|
@@ -1099,12 +1101,20 @@ def mock_env(workflow, df_images): | |
.for_plugin(GenerateSbomPlugin.key) | ||
.set_reactor_config(r_c_m) | ||
.set_dockerfile_images(df_images) | ||
.set_plugin_result(PLUGIN_RESOLVE_REMOTE_SOURCE, deepcopy(REMOTE_SOURCES)) | ||
.set_plugin_result(PLUGIN_FETCH_MAVEN_KEY, | ||
{'sbom_components': deepcopy(PNC_SBOM_COMPONENTS)}) | ||
.set_plugin_result(PLUGIN_RPMQA, deepcopy(RPM_SBOM_COMPONENTS)) | ||
) | ||
|
||
if cachi2: | ||
# Note: using CACHITO_SBOM_JSON here, as the fields are almost the same as | ||
# for Cachi2; I don't want to die from mocking everything again, just to | ||
# make test pass for extra property "found_by: cachi2" added by cachi2 | ||
# this provides good tests | ||
mock_cachi2_sbom(workflow, deepcopy(CACHITO_SBOM_JSON)) | ||
else: | ||
env.set_plugin_result(PLUGIN_RESOLVE_REMOTE_SOURCE, deepcopy(REMOTE_SOURCES)) | ||
|
||
all_inspects = [(EMPTY_SBOM_IMAGE_LABELS, EMPTY_SBOM_IMAGE_NAME), | ||
(MISSING_LABEL_IMAGE_LABELS, MISSING_LABEL_IMAGE_NAME), | ||
(BUILDING_IMAGE_LABELS, BUILDING_IMAGE_NAME), | ||
|
@@ -1131,6 +1141,19 @@ def mock_get_sbom_cachito(requests_mock): | |
requests_mock.register_uri('GET', CACHITO_SBOM_URL, json=CACHITO_SBOM_JSON) | ||
|
||
|
||
def mock_cachi2_sbom(workflow, cachi2_sbom: dict): | ||
workflow.data.plugins_results[PLUGIN_CACHI2_POSTPROCESS] = { | ||
"plugin": "did run, real value doesn't matter" | ||
} | ||
|
||
# save cachi2 SBOM which is source for ICM | ||
path = workflow.build_dir.path/CACHI2_BUILD_DIR/"bom.json" | ||
path.parent.mkdir() | ||
with open(path, "w") as f: | ||
json.dump(cachi2_sbom, f) | ||
f.flush() | ||
|
||
|
||
def mock_build_icm_urls(requests_mock): | ||
all_sboms = [(EMPTY_SBOM_KOJI_BUILD, EMPTY_SBOM_BUILD_SBOM_JSON), | ||
(BASE_WITH_SBOM_KOJI_BUILD, BASE_WITH_SBOM_BUILD_SBOM_JSON), | ||
|
@@ -1311,12 +1334,16 @@ def koji_session(): | |
INCOMPLETE_CACHE_URL_KOJI, | ||
), | ||
]) | ||
@pytest.mark.parametrize('cachi2', [True, False]) | ||
def test_sbom(workflow, requests_mock, koji_session, df_images, use_cache, use_fetch_url, | ||
use_fetch_koji, expected_components, expected_incomplete): | ||
mock_get_sbom_cachito(requests_mock) | ||
use_fetch_koji, expected_components, expected_incomplete, cachi2): | ||
|
||
if not cachi2: | ||
mock_get_sbom_cachito(requests_mock) | ||
|
||
mock_build_icm_urls(requests_mock) | ||
|
||
runner = mock_env(workflow, df_images) | ||
runner = mock_env(workflow, df_images, cachi2=cachi2) | ||
workflow.data.tag_conf.add_unique_image(UNIQUE_IMAGE) | ||
|
||
def check_cosign_run(args): | ||
|