-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SBOMER-200): Enhance RPM components found in the container image…
… manifests
- Loading branch information
Showing
3 changed files
with
131 additions
and
2 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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package org.jboss.sbomer.cli.test.unit.feature.sbom; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.when; | ||
|
||
|
@@ -83,6 +84,53 @@ void testAddBrewInfo() throws IOException, KojiClientException { | |
|
||
} | ||
|
||
@Test | ||
void testAddBrewInfoForRpm() throws IOException, KojiClientException { | ||
PncService pncServiceMock = Mockito.mock(PncService.class); | ||
KojiService kojiServiceMock = Mockito.mock(KojiService.class); | ||
|
||
KojiBuildInfo kojiBuildInfo = new KojiBuildInfo(); | ||
kojiBuildInfo.setId(12345); | ||
kojiBuildInfo.setSource("https://git.com/repo#hash"); | ||
|
||
BuildConfig buildConfig = new BuildConfig(); | ||
buildConfig.setKojiWebURL(new URL("https://koji.web")); | ||
|
||
when(kojiServiceMock.getConfig()).thenReturn(buildConfig); | ||
when(kojiServiceMock.findBuildByRPM(eq("audit-libs-3.0.7-103.el9.x86_64"))) | ||
.thenReturn(kojiBuildInfo); | ||
|
||
DefaultProcessor defaultProcessor = new DefaultProcessor(pncServiceMock, kojiServiceMock); | ||
|
||
Bom bom = SbomUtils.fromString(TestResources.asString("boms/image-after-adjustments.json")); | ||
Bom processed = defaultProcessor.process(bom); | ||
|
||
assertEquals(192, processed.getComponents().size()); | ||
|
||
Component rpmComponent = processed.getComponents().stream() | ||
.filter(c -> "pkg:rpm/redhat/[email protected]?arch=x86_64".equals(c.getPurl())) | ||
.findFirst().orElseThrow(); | ||
|
||
assertNotNull(rpmComponent.getSupplier()); | ||
assertEquals("Red Hat", rpmComponent.getSupplier().getName()); | ||
assertEquals("Red Hat", rpmComponent.getPublisher()); | ||
|
||
ExternalReference buildSystem = SbomUtils.getExternalReferences(rpmComponent, Type.BUILD_SYSTEM).get(0); | ||
|
||
assertEquals("https://koji.web/buildinfo?buildID=12345", buildSystem.getUrl()); | ||
assertEquals("brew-build-id", buildSystem.getComment()); | ||
|
||
assertEquals( | ||
"https://git.com/repo#hash", | ||
SbomUtils.getExternalReferences(rpmComponent, Type.VCS).get(0).getUrl()); | ||
|
||
Commit commit = rpmComponent.getPedigree().getCommits().get(0); | ||
|
||
assertEquals("hash", commit.getUid()); | ||
assertEquals("https://git.com/repo#hash", commit.getUrl()); | ||
|
||
} | ||
|
||
@Test | ||
void baseTest() throws IOException { | ||
Bom bom = SbomUtils.fromString(TestResources.asString("boms/adjusted.json")); | ||
|