Skip to content

Commit 572ff04

Browse files
committed
fix: count unique transitive, direct and total independently
Signed-off-by: Ruben Romero Montes <[email protected]>
1 parent f9a51f0 commit 572ff04

File tree

2 files changed

+304
-263
lines changed

2 files changed

+304
-263
lines changed

src/main/java/com/redhat/exhort/integration/providers/ProviderResponseHandler.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.List;
2727
import java.util.Map;
2828
import java.util.Optional;
29+
import java.util.Set;
2930
import java.util.concurrent.atomic.AtomicInteger;
3031
import java.util.stream.Collectors;
3132

@@ -53,6 +54,7 @@
5354
import com.redhat.exhort.model.CvssScoreComparable.DependencyScoreComparator;
5455
import com.redhat.exhort.model.CvssScoreComparable.TransitiveScoreComparator;
5556
import com.redhat.exhort.model.DependencyTree;
57+
import com.redhat.exhort.model.DirectDependency;
5658
import com.redhat.exhort.model.ProviderResponse;
5759
import com.redhat.exhort.model.trustedcontent.IndexedRecommendation;
5860
import com.redhat.exhort.model.trustedcontent.TrustedContentResponse;
@@ -425,9 +427,21 @@ private SourceSummary buildSummary(
425427
var counter = new VulnerabilityCounter();
426428
var directRefs =
427429
tree.dependencies().keySet().stream().map(PackageRef::ref).collect(Collectors.toSet());
430+
var transitiveRefs =
431+
tree.dependencies().values().stream()
432+
.map(DirectDependency::transitive)
433+
.flatMap(Set::stream)
434+
.map(PackageRef::ref)
435+
.toList();
428436
issuesData
429437
.entrySet()
430-
.forEach(e -> incrementCounter(e.getValue(), counter, directRefs.contains(e.getKey())));
438+
.forEach(
439+
e ->
440+
incrementCounter(
441+
e.getValue(),
442+
counter,
443+
directRefs.contains(e.getKey()),
444+
transitiveRefs.contains(e.getKey())));
431445
Long recommendationsCount =
432446
sourceReport.stream().filter(s -> s.getRecommendation() != null).count();
433447
counter.recommendations.set(recommendationsCount.intValue());
@@ -436,7 +450,7 @@ private SourceSummary buildSummary(
436450
}
437451

438452
private void incrementCounter(
439-
List<Issue> issues, VulnerabilityCounter counter, boolean isDirect) {
453+
List<Issue> issues, VulnerabilityCounter counter, boolean isDirect, boolean isTransitive) {
440454
if (!issues.isEmpty()) {
441455
counter.dependencies.incrementAndGet();
442456
}
@@ -453,6 +467,9 @@ private void incrementCounter(
453467
if (isDirect) {
454468
counter.direct.addAndGet(vulnerabilities);
455469
}
470+
if (isTransitive) {
471+
counter.transitive.addAndGet(vulnerabilities);
472+
}
456473
if (i.getRemediation() != null
457474
&& i.getRemediation().getTrustedContent() != null
458475
&& i.getRemediation().getTrustedContent().getRef() != null) {
@@ -475,6 +492,7 @@ private int countVulnerabilities(Issue i) {
475492

476493
private static final record VulnerabilityCounter(
477494
AtomicInteger total,
495+
AtomicInteger transitive,
478496
AtomicInteger critical,
479497
AtomicInteger high,
480498
AtomicInteger medium,
@@ -496,6 +514,7 @@ private static final record VulnerabilityCounter(
496514
new AtomicInteger(),
497515
new AtomicInteger(),
498516
new AtomicInteger(),
517+
new AtomicInteger(),
499518
new AtomicInteger());
500519
}
501520

@@ -507,10 +526,9 @@ SourceSummary getSummary() {
507526
.medium(medium.get())
508527
.low(low.get())
509528
.direct(direct.get())
510-
.transitive(total.get() - direct.get())
529+
.transitive(transitive.get())
511530
.dependencies(dependencies.get())
512531
.remediations(remediations.get())
513-
// Will be calculated later when TC recommendations will be added.
514532
.recommendations(recommendations.get())
515533
.unscanned(unscanned.get());
516534
}

0 commit comments

Comments
 (0)