forked from DependencyTrack/dependency-track
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Detect and avoid infinite recursion during second upload of SBOM…
… with nested duplicate See DependencyTrack#1905 for details Signed-off-by: syalioune <[email protected]>
- Loading branch information
Showing
3 changed files
with
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ | |
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.time.Duration; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
|
||
|
@@ -209,4 +210,27 @@ public void informWithInvalidCycloneDxBomTest() throws Exception { | |
assertThat(project.getLastBomImport()).isNull(); | ||
} | ||
|
||
@Test | ||
public void informTestWithInvalidCycloneDxBomRecursiveDuplicateTest() throws Exception { | ||
// Test case for issue #1905 : https://github.com/DependencyTrack/dependency-track/issues/1905 | ||
Project project = qm.createProject("Acme Example", null, "1.0", null, null, null, true, false); | ||
|
||
final byte[] bomBytes = Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("bom-2.json").toURI())); | ||
|
||
new BomUploadProcessingTask().inform(new BomUploadEvent(project.getUuid(), bomBytes)); | ||
assertConditionWithTimeout(() -> qm.getAllComponents(project).size() == 1, Duration.ofSeconds(5)); | ||
assertConditionWithTimeout(() -> NOTIFICATIONS.size() >= 3, Duration.ofSeconds(5)); | ||
List<Component> components = qm.getAllComponents(project); | ||
final Component component = components.get(0); | ||
assertThat(component.getName()).isEqualTo("Pillow"); | ||
assertThat(component.getVersion()).isEqualTo("9.3.0"); | ||
assertThat(component.getCpe()).isEqualTo("cpe:2.3:a:alex_clark_\\(pil_fork_author\\):python-Pillow:9.3.0:*:*:*:*:*:*:*"); | ||
assertThat(component.getPurl().canonicalize()).isEqualTo("pkg:pypi/[email protected]"); | ||
assertThat(NOTIFICATIONS).satisfiesExactly( | ||
n -> assertThat(n.getGroup()).isEqualTo(NotificationGroup.PROJECT_CREATED.name()), | ||
n -> assertThat(n.getGroup()).isEqualTo(NotificationGroup.BOM_CONSUMED.name()), | ||
n -> assertThat(n.getGroup()).isEqualTo(NotificationGroup.BOM_PROCESSED.name()) | ||
); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"bomFormat": "CycloneDX", | ||
"specVersion": "1.4", | ||
"version": 1, | ||
"metadata": { | ||
"timestamp": "2023-01-01T11:01:51Z", | ||
"tools": [ | ||
{ | ||
"vendor": "changeme", | ||
"name": "changeme", | ||
"version": "0.62.3" | ||
} | ||
] | ||
}, | ||
"components": [ | ||
{ | ||
"bom-ref": "pkg:pypi/[email protected]", | ||
"type": "library", | ||
"name": "Pillow", | ||
"version": "9.3.0", | ||
"cpe": "cpe:2.3:a:alex_clark_\\(pil_fork_author\\):python-Pillow:9.3.0:*:*:*:*:*:*:*", | ||
"purl": "pkg:pypi/[email protected]", | ||
"components": [ | ||
{ | ||
"bom-ref": "pkg:pypi/[email protected]?package-id=212c649613e17901", | ||
"type": "library", | ||
"name": "Pillow", | ||
"version": "9.3.0", | ||
"cpe": "cpe:2.3:a:alex_clark_\\(pil_fork_author\\):python-Pillow:9.3.0:*:*:*:*:*:*:*", | ||
"purl": "pkg:pypi/[email protected]" | ||
} | ||
] | ||
} | ||
] | ||
} |