Skip to content

Commit a2c4c6d

Browse files
authored
[backend] fix(securitycoverage): convert coverage score in fractions to percentage points (#4390)
Signed-off-by: Antoine MAZEAS <[email protected]>
1 parent 82bb808 commit a2c4c6d

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

openaev-api/src/main/java/io/openaev/service/stix/SecurityCoverageService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ private BaseType<?> computeCoverage(
463463
List<InjectExpectationResultUtils.ExpectationResultsByType> coverageResults) {
464464
List<Complex<?>> coverageValues = new ArrayList<>();
465465
for (InjectExpectationResultUtils.ExpectationResultsByType result : coverageResults) {
466-
CoverageResult cov = new CoverageResult(result.type().name(), result.getSuccessRate());
466+
CoverageResult cov =
467+
new CoverageResult(
468+
result.type().name(), result.getSuccessRate() * 100); // force percentage points
467469
coverageValues.add(new Complex<>(cov));
468470
}
469471
return new io.openaev.stix.types.List<>(coverageValues);

openaev-api/src/test/java/io/openaev/service/stix/SecurityCoverageServiceTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private io.openaev.stix.types.List<Complex<CoverageResult>> predictCoverageFromI
170170
injects.stream().map(Inject::getId).collect(Collectors.toSet()));
171171
return toList(
172172
results.stream()
173-
.map(r -> new Complex<>(new CoverageResult(r.type().name(), r.getSuccessRate())))
173+
.map(r -> new Complex<>(new CoverageResult(r.type().name(), r.getSuccessRate() * 100)))
174174
.toList());
175175
}
176176

@@ -315,7 +315,7 @@ public void whenAllAttackPatternsAreCoveredAndAllExpectationsAreSuccessful_bundl
315315
.getId()
316316
.getValue()
317317
.contains(securityPlatformWrapper.get().getId())
318-
? 1.0
318+
? 100.0
319319
: 0.0)),
320320
new Complex<>(
321321
new CoverageResult(
@@ -324,7 +324,7 @@ public void whenAllAttackPatternsAreCoveredAndAllExpectationsAreSuccessful_bundl
324324
.getId()
325325
.getValue()
326326
.contains(securityPlatformWrapper.get().getId())
327-
? 1.0
327+
? 100.0
328328
: 0.0))))));
329329
assertThatJson(actualSro.toStix(mapper))
330330
.whenIgnoringPaths(CommonProperties.ID.toString())
@@ -357,8 +357,8 @@ public void whenAllAttackPatternsAreCoveredAndAllExpectationsAreSuccessful_bundl
357357
ExtendedProperties.COVERAGE.toString(),
358358
toList(
359359
List.of(
360-
new Complex<>(new CoverageResult("PREVENTION", 1.0)),
361-
new Complex<>(new CoverageResult("DETECTION", 1.0))))));
360+
new Complex<>(new CoverageResult("PREVENTION", 100.0)),
361+
new Complex<>(new CoverageResult("DETECTION", 100.0))))));
362362
assertThatJson(actualSro.toStix(mapper))
363363
.whenIgnoringPaths(CommonProperties.ID.toString())
364364
.isEqualTo(expectedSro.toStix(mapper));
@@ -429,7 +429,7 @@ public void whenAllVulnerabilitiesAreCoveredAndAllExpectationsAreSuccessful_bund
429429
ExtendedProperties.COVERED.toString(),
430430
new io.openaev.stix.types.Boolean(true),
431431
ExtendedProperties.COVERAGE.toString(),
432-
toList(List.of(new Complex<>(new CoverageResult("VULNERABILITY", 1.0))))));
432+
toList(List.of(new Complex<>(new CoverageResult("VULNERABILITY", 100.0))))));
433433
assertThatJson(actualSro.toStix(mapper))
434434
.whenIgnoringPaths(CommonProperties.ID.toString())
435435
.isEqualTo(expectedSro.toStix(mapper));
@@ -624,7 +624,7 @@ public void whenAllAttackPatternsAreCoveredAndHalfOfAllExpectationsAreSuccessful
624624
.getId()
625625
.getValue()
626626
.contains(securityPlatformWrapper.get().getId())
627-
? 0.5
627+
? 50.0
628628
: 0.0)),
629629
new Complex<>(
630630
new CoverageResult(
@@ -633,7 +633,7 @@ public void whenAllAttackPatternsAreCoveredAndHalfOfAllExpectationsAreSuccessful
633633
.getId()
634634
.getValue()
635635
.contains(securityPlatformWrapper.get().getId())
636-
? 0.5
636+
? 50.0
637637
: 0.0))))));
638638
assertThatJson(actualSro.toStix(mapper))
639639
.whenIgnoringPaths(CommonProperties.ID.toString())
@@ -668,11 +668,11 @@ public void whenAllAttackPatternsAreCoveredAndHalfOfAllExpectationsAreSuccessful
668668
new Complex<>(
669669
new CoverageResult(
670670
"PREVENTION",
671-
stixRef.getExternalRef().equals("T1234") ? 1.0 : 0.0)),
671+
stixRef.getExternalRef().equals("T1234") ? 100.0 : 0.0)),
672672
new Complex<>(
673673
new CoverageResult(
674674
"DETECTION",
675-
stixRef.getExternalRef().equals("T1234") ? 1.0 : 0.0))))));
675+
stixRef.getExternalRef().equals("T1234") ? 100.0 : 0.0))))));
676676
assertThatJson(actualSro.toStix(mapper))
677677
.whenIgnoringPaths(CommonProperties.ID.toString())
678678
.isEqualTo(expectedSro.toStix(mapper));

0 commit comments

Comments
 (0)