Skip to content
This repository was archived by the owner on May 16, 2023. It is now read-only.

Commit 25294e1

Browse files
authored
Merge/latst changes from main into release (#1536)
* fix: use correct length attributes for encrypted check in validation (#1535) * fix: remove spinning up unnecessary web server (#1529)
1 parent 80eb017 commit 25294e1

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

services/callback/src/test/java/app/coronawarn/server/services/callback/registration/CallbackRegistrationRunnerIntegrationTest.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
11
package app.coronawarn.server.services.callback.registration;
22

3-
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
4-
import static com.github.tomakehurst.wiremock.client.WireMock.get;
5-
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
6-
import static com.github.tomakehurst.wiremock.client.WireMock.put;
7-
import static com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor;
8-
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
9-
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
10-
import static org.mockito.Mockito.verify;
11-
import static org.mockito.internal.verification.VerificationModeFactory.times;
12-
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
13-
143
import app.coronawarn.server.common.federation.client.callback.RegistrationResponse;
154
import app.coronawarn.server.common.shared.util.HashUtils;
165
import app.coronawarn.server.services.callback.config.CallbackServiceConfig;
176
import com.fasterxml.jackson.databind.ObjectMapper;
187
import com.github.tomakehurst.wiremock.WireMockServer;
198
import com.github.tomakehurst.wiremock.http.HttpHeader;
209
import com.github.tomakehurst.wiremock.http.HttpHeaders;
21-
import java.util.List;
2210
import org.junit.jupiter.api.AfterAll;
2311
import org.junit.jupiter.api.BeforeAll;
2412
import org.junit.jupiter.api.Test;
2513
import org.springframework.boot.test.context.SpringBootTest;
26-
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
14+
import org.springframework.boot.test.mock.mockito.MockBean;
2715
import org.springframework.boot.test.mock.mockito.SpyBean;
16+
import org.springframework.boot.test.web.client.TestRestTemplate;
2817
import org.springframework.http.HttpStatus;
2918
import org.springframework.test.annotation.DirtiesContext;
3019
import org.springframework.test.context.ActiveProfiles;
20+
import java.util.List;
3121

32-
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
22+
import static com.github.tomakehurst.wiremock.client.WireMock.*;
23+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
24+
import static org.mockito.Mockito.verify;
25+
import static org.mockito.internal.verification.VerificationModeFactory.times;
26+
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
27+
28+
@SpringBootTest
3329
@ActiveProfiles({"callback-registration"})
3430
@DirtiesContext
3531
class CallbackRegistrationRunnerIntegrationTest {
3632

37-
private static WireMockServer server;
33+
private static WireMockServer server = new WireMockServer(options().port(1234));
3834

35+
@MockBean
36+
TestRestTemplate testRestTemplate;
3937
@SpyBean
4038
private CallbackServiceConfig callbackServiceConfig;
4139

@@ -44,7 +42,7 @@ static void setupWireMock() {
4442
RegistrationResponse registrationResponse1 = new RegistrationResponse(HashUtils.md5DigestAsHex("url1"), "url1");
4543
List<RegistrationResponse> responses = List.of(registrationResponse1);
4644

47-
server = new WireMockServer(options().port(1234));
45+
4846
server.start();
4947
server.stubFor(
5048
get(urlEqualTo("/diagnosiskeys/callback"))

services/submission/src/main/java/app/coronawarn/server/services/submission/checkins/EventCheckInProtectedReportsValidator.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
@Component
1111
public class EventCheckInProtectedReportsValidator {
1212

13+
public static final int INIT_VECTOR_LENGTH = 16;
14+
public static final int LOCATION_ID_HASH_LENGTH = 32;
15+
public static final int ENCRYPTED_CHECK_IN_RECORD_LENGTH = 16;
16+
1317
/**
1418
* Given the submission payload, it verifies whether user event checkInProtectedReports data is aligned with the
1519
* application constraints. For each checkInProtectedReports:
@@ -29,7 +33,7 @@ && verifyEncryptedCheckInRecordLength(checkInProtectedReport, validatorContext))
2933
boolean verifyLocationIdHashLength(CheckInProtectedReport checkInProtectedReport,
3034
ConstraintValidatorContext validatorContext) {
3135
if (ObjectUtils.isEmpty(checkInProtectedReport.getLocationIdHash())
32-
|| checkInProtectedReport.getLocationIdHash().size() != 32) {
36+
|| checkInProtectedReport.getLocationIdHash().size() != LOCATION_ID_HASH_LENGTH) {
3337
addViolation(validatorContext, "CheckInProtectedReports locationIdHash must have 32 bytes not "
3438
+ (checkInProtectedReport.getLocationIdHash() == null ? 0
3539
: checkInProtectedReport.getLocationIdHash().size()));
@@ -41,7 +45,7 @@ boolean verifyLocationIdHashLength(CheckInProtectedReport checkInProtectedReport
4145
boolean verifyIvLength(CheckInProtectedReport checkInProtectedReport,
4246
ConstraintValidatorContext validatorContext) {
4347
if (ObjectUtils.isEmpty(checkInProtectedReport.getIv())
44-
|| checkInProtectedReport.getIv().size() != 32) {
48+
|| checkInProtectedReport.getIv().size() != INIT_VECTOR_LENGTH) {
4549
addViolation(validatorContext, "CheckInProtectedReports iv must have 32 bytes not "
4650
+ (checkInProtectedReport.getIv() == null ? 0 : checkInProtectedReport.getIv().size()));
4751
return false;
@@ -52,7 +56,7 @@ boolean verifyIvLength(CheckInProtectedReport checkInProtectedReport,
5256
boolean verifyEncryptedCheckInRecordLength(CheckInProtectedReport checkInProtectedReport,
5357
ConstraintValidatorContext validatorContext) {
5458
if (ObjectUtils.isEmpty(checkInProtectedReport.getEncryptedCheckInRecord())
55-
|| checkInProtectedReport.getEncryptedCheckInRecord().size() != 16) {
59+
|| checkInProtectedReport.getEncryptedCheckInRecord().size() != ENCRYPTED_CHECK_IN_RECORD_LENGTH) {
5660
addViolation(validatorContext, "CheckInProtectedReports encryptedCheckInRecord must have 16 bytes not "
5761
+ (checkInProtectedReport.getEncryptedCheckInRecord() == null ? 0
5862
: checkInProtectedReport.getEncryptedCheckInRecord().size()));

services/submission/src/test/java/app/coronawarn/server/services/submission/checkins/EventCheckInProtectedReportsValidatorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void verifyNonEmptyCheckInProtectedReport() {
4848
.setEncryptedCheckInRecord(ByteString
4949
.copyFrom(generateSecureRandomByteArrayData(16)))
5050
.setIv(ByteString
51-
.copyFrom(generateSecureRandomByteArrayData(32)))
51+
.copyFrom(generateSecureRandomByteArrayData(16)))
5252
.setLocationIdHash(ByteString
5353
.copyFrom(generateSecureRandomByteArrayData(32)))
5454
.build()))
@@ -85,7 +85,7 @@ void verifyEncryptedCheckInRecordLengthIsFalse(ByteString e) {
8585
@Test
8686
void verifyIvLengthIsTrue() {
8787
CheckInProtectedReport checkInProtectedReport = CheckInProtectedReport.newBuilder().setIv(
88-
ByteString.copyFrom(generateSecureRandomByteArrayData(32))).build();
88+
ByteString.copyFrom(generateSecureRandomByteArrayData(16))).build();
8989

9090
boolean result = underTest.verifyIvLength(checkInProtectedReport, mockValidatorContext);
9191
assertThat(result).isTrue();
@@ -127,7 +127,7 @@ void verifyLocationIdHashLengthIsFalse(ByteString e) {
127127
private static Stream<Arguments> generateWrongLengthByteStrings() {
128128
return Stream.of(
129129
Arguments.of(ByteString.copyFrom(generateSecureRandomByteArrayData(100))),
130-
Arguments.of(ByteString.copyFrom(generateSecureRandomByteArrayData(0))),
130+
Arguments.of(ByteString.copyFrom(generateSecureRandomByteArrayData(33))),
131131
Arguments.of(ByteString.EMPTY));
132132
}
133133

services/submission/src/test/java/app/coronawarn/server/services/submission/integration/DataHelpers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static CheckInProtectedReport buildEncryptedCheckIn(ByteString checkInRec
5757

5858
public static CheckInProtectedReport buildDefaultEncryptedCheckIn() {
5959
return buildEncryptedCheckIn(ByteString.copyFrom(generateSecureRandomByteArrayData(16)),
60-
ByteString.copyFrom(generateSecureRandomByteArrayData(32)),
60+
ByteString.copyFrom(generateSecureRandomByteArrayData(16)),
6161
ByteString.copyFrom(generateSecureRandomByteArrayData(32)));
6262
}
6363

0 commit comments

Comments
 (0)