diff --git a/services/submission/src/main/java/app/coronawarn/server/services/submission/controller/SubmissionController.java b/services/submission/src/main/java/app/coronawarn/server/services/submission/controller/SubmissionController.java index ef67ffaa36..5b3db2d673 100644 --- a/services/submission/src/main/java/app/coronawarn/server/services/submission/controller/SubmissionController.java +++ b/services/submission/src/main/java/app/coronawarn/server/services/submission/controller/SubmissionController.java @@ -142,18 +142,20 @@ private List padDiagnosisKeys(List diagnosisKeys) { diagnosisKeys.forEach(diagnosisKey -> { paddedDiagnosisKeys.add(diagnosisKey); IntStream.range(1, randomKeyPaddingMultiplier) - .mapToObj(index -> { - byte[] randomKeyData = new byte[16]; - new SecureRandom().nextBytes(randomKeyData); - return DiagnosisKey.builder() - .withKeyData(randomKeyData) - .withRollingStartIntervalNumber(diagnosisKey.getRollingStartIntervalNumber()) - .withTransmissionRiskLevel(diagnosisKey.getTransmissionRiskLevel()) - .withRollingPeriod(diagnosisKey.getRollingPeriod()) - .build(); - }) + .mapToObj(index -> DiagnosisKey.builder() + .withKeyData(generateRandomKeyData()) + .withRollingStartIntervalNumber(diagnosisKey.getRollingStartIntervalNumber()) + .withTransmissionRiskLevel(diagnosisKey.getTransmissionRiskLevel()) + .withRollingPeriod(diagnosisKey.getRollingPeriod()) + .build()) .forEach(paddedDiagnosisKeys::add); }); return paddedDiagnosisKeys; } + + private static byte[] generateRandomKeyData() { + byte[] randomKeyData = new byte[16]; + new SecureRandom().nextBytes(randomKeyData); + return randomKeyData; + } } diff --git a/services/submission/src/test/java/app/coronawarn/server/services/submission/controller/SubmissionControllerTest.java b/services/submission/src/test/java/app/coronawarn/server/services/submission/controller/SubmissionControllerTest.java index dffb71ca8b..f7f5916d3f 100644 --- a/services/submission/src/test/java/app/coronawarn/server/services/submission/controller/SubmissionControllerTest.java +++ b/services/submission/src/test/java/app/coronawarn/server/services/submission/controller/SubmissionControllerTest.java @@ -259,7 +259,7 @@ private void assertElementsCorrespondToEachOther(Collection DiagnosisKey.builder().fromProtoBuf(submittedDiagnosisKey).build()) .collect(Collectors.toSet()); - assertThat(savedDiagnosisKeys).hasSize(submittedDiagnosisKeys.size() * 10); + assertThat(savedDiagnosisKeys).hasSize(submittedDiagnosisKeys.size() * config.getRandomKeyPaddingMultiplier()); assertThat(savedDiagnosisKeys).containsAll(submittedDiagnosisKeys); submittedDiagnosisKeys.forEach(submittedDiagnosisKey -> { @@ -272,7 +272,7 @@ private void assertElementsCorrespondToEachOther(Collection Arrays.equals(savedKey.getKeyData(), submittedDiagnosisKey.getKeyData()))).hasSize(1); assertThat(savedKeysForSingleSubmittedKey).allMatch(