Skip to content

Commit

Permalink
Update Trivy IT to use OS component and properties
Browse files Browse the repository at this point in the history
Relates to DependencyTrack#3369

Signed-off-by: nscuro <[email protected]>
  • Loading branch information
nscuro committed Apr 14, 2024
1 parent 0cd4332 commit 5164bb8
Showing 1 changed file with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.dependencytrack.tasks.scanners;

import alpine.model.IConfigProperty;
import alpine.security.crypto.DataEncryption;
import org.dependencytrack.PersistenceCapableTest;
import org.dependencytrack.event.TrivyAnalysisEvent;
Expand Down Expand Up @@ -177,19 +178,30 @@ public void testWithUnrecognizedPackageName() {
final var project = new Project();
project.setName("acme-app");
qm.persist(project);

final var componentA = new Component();
componentA.setProject(project);
componentA.setName("libc6");
componentA.setVersion("2.35-0ubuntu3.4");
componentA.setClassifier(Classifier.LIBRARY);
componentA.setPurl("pkg:deb/ubuntu/[email protected]?arch=amd64&distro=ubuntu-22.04");
qm.persist(componentA);

final var analysisEvent = new TrivyAnalysisEvent(List.of(componentA));

final var osComponent = new Component();
osComponent.setProject(project);
osComponent.setName("ubuntu");
osComponent.setVersion("22.04");
osComponent.setClassifier(Classifier.OPERATING_SYSTEM);
qm.persist(osComponent);

final var component = new Component();
component.setProject(project);
component.setName("libc6");
component.setVersion("2.35-0ubuntu3.4");
component.setClassifier(Classifier.LIBRARY);
component.setPurl("pkg:deb/ubuntu/[email protected]?arch=amd64&distro=ubuntu-22.04");
qm.persist(component);

qm.createComponentProperty(component, "aquasecurity:trivy", "SrcName", "glibc", IConfigProperty.PropertyType.STRING, null);
qm.createComponentProperty(component, "aquasecurity:trivy", "SrcVersion", "2.35", IConfigProperty.PropertyType.STRING, null);
qm.createComponentProperty(component, "aquasecurity:trivy", "SrcRelease", "0ubuntu3.4", IConfigProperty.PropertyType.STRING, null);

final var analysisEvent = new TrivyAnalysisEvent(List.of(osComponent, component));
new TrivyAnalysisTask().inform(analysisEvent);

assertThat(qm.getAllVulnerabilities(componentA)).isEmpty();
assertThat(qm.getAllVulnerabilities(component)).isEmpty();
}

}

0 comments on commit 5164bb8

Please sign in to comment.