Skip to content

Commit

Permalink
Fix CPE not being imported from CycloneDX metadata.component
Browse files Browse the repository at this point in the history
Co-Authored-By: Niklas <[email protected]>
  • Loading branch information
sahibamittal and nscuro committed Nov 22, 2024
1 parent a86d5d6 commit 590845a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public static Project convertToProject(final org.cyclonedx.model.Component cdxCo
project.setName(trimToNull(cdxComponent.getName()));
project.setVersion(trimToNull(cdxComponent.getVersion()));
project.setDescription(trimToNull(cdxComponent.getDescription()));
project.setCpe(trimToNull(cdxComponent.getCpe()));
project.setExternalReferences(convertExternalReferences(cdxComponent.getExternalReferences()));

List<OrganizationalContact> contacts = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ private static Project processProject(
// hasChanged |= applyIfChanged(persistentProject, project, Project::getVersion, persistentProject::setVersion);
// hasChanged |= applyIfChanged(persistentProject, project, Project::getDescription, persistentProject::setDescription);
hasChanged |= applyIfChanged(persistentProject, project, Project::getExternalReferences, persistentProject::setExternalReferences);
hasChanged |= applyIfChanged(persistentProject, project, Project::getCpe, persistentProject::setCpe);
hasChanged |= applyIfChanged(persistentProject, project, Project::getPurl, persistentProject::setPurl);
hasChanged |= applyIfChanged(persistentProject, project, Project::getSwidTagId, persistentProject::setSwidTagId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ public void informTest() throws Exception {
qm.getPersistenceManager().refresh(project);
qm.getPersistenceManager().refreshAll(qm.getAllWorkflowStatesForAToken(bomUploadEvent.getChainIdentifier()));
assertThat(project.getClassifier()).isEqualTo(Classifier.APPLICATION);
assertThat(project.getCpe()).isEqualTo("cpe:2.3:a:acme:example:1.0.0:*:*:*:*:*:*:*");
assertThat(project.getPurl()).asString().isEqualTo("pkg:maven/com.acme/[email protected]");
assertThat(project.getSwidTagId()).isEqualTo("swidgen-242eb18a-503e-ca37-393b-cf156ef09691_9.1.1");
assertThat(project.getLastBomImport()).isNotNull();
assertThat(project.getLastBomImportFormat()).isEqualTo("CycloneDX 1.5");
assertThat(project.getExternalReferences()).isNotNull();
Expand Down
5 changes: 5 additions & 0 deletions src/test/resources/unit/bom-1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
</supplier>
<publisher>DependencyTrack</publisher>
<name>Acme example</name>
<cpe>cpe:2.3:a:acme:example:1.0.0:*:*:*:*:*:*:*</cpe>
<purl>pkg:maven/com.acme/[email protected]</purl>
<swid tagId="swidgen-242eb18a-503e-ca37-393b-cf156ef09691_9.1.1" name="Acme Application" version="9.1.1">
<text content-type="text/xml" encoding="base64">PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiID8+CjxTb2Z0d2FyZUlkZW50aXR5IHhtbDpsYW5nPSJFTiIgbmFtZT0iQWNtZSBBcHBsaWNhdGlvbiIgdmVyc2lvbj0iOS4xLjEiIAogdmVyc2lvblNjaGVtZT0ibXVsdGlwYXJ0bnVtZXJpYyIgCiB0YWdJZD0ic3dpZGdlbi1iNTk1MWFjOS00MmMwLWYzODItM2YxZS1iYzdhMmE0NDk3Y2JfOS4xLjEiIAogeG1sbnM9Imh0dHA6Ly9zdGFuZGFyZHMuaXNvLm9yZy9pc28vMTk3NzAvLTIvMjAxNS9zY2hlbWEueHNkIj4gCiB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIiAKIHhzaTpzY2hlbWFMb2NhdGlvbj0iaHR0cDovL3N0YW5kYXJkcy5pc28ub3JnL2lzby8xOTc3MC8tMi8yMDE1LWN1cnJlbnQvc2NoZW1hLnhzZCBzY2hlbWEueHNkIiA+CiAgPE1ldGEgZ2VuZXJhdG9yPSJTV0lEIFRhZyBPbmxpbmUgR2VuZXJhdG9yIHYwLjEiIC8+IAogIDxFbnRpdHkgbmFtZT0iQWNtZSwgSW5jLiIgcmVnaWQ9ImV4YW1wbGUuY29tIiByb2xlPSJ0YWdDcmVhdG9yIiAvPiAKPC9Tb2Z0d2FyZUlkZW50aXR5Pg==</text>
</swid>
<externalReferences>
<reference type="build-system">
<url>https://acme.example</url>
Expand Down

0 comments on commit 590845a

Please sign in to comment.