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

Commit 5c146ab

Browse files
committed
Preparation for additional Request Header send to UBirch with labId
1 parent 4c19e6e commit 5c146ab

File tree

6 files changed

+23
-22
lines changed

6 files changed

+23
-22
lines changed

src/main/java/app/coronawarn/dcc/client/SigningApiClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.http.MediaType;
2525
import org.springframework.web.bind.annotation.PostMapping;
2626
import org.springframework.web.bind.annotation.RequestBody;
27+
import org.springframework.web.bind.annotation.RequestHeader;
2728

2829
/**
2930
* This class represents the Verification Server Feign client.
@@ -44,5 +45,5 @@ public interface SigningApiClient {
4445
consumes = MediaType.TEXT_PLAIN_VALUE,
4546
produces = MediaType.APPLICATION_CBOR_VALUE
4647
)
47-
byte[] sign(@RequestBody String hash);
48+
byte[] sign(@RequestBody String hash, @RequestHeader("<<LAB ID REQUEST HEADER>>") String labId);
4849
}

src/main/java/app/coronawarn/dcc/client/SigningApiClientConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public Client signingApiClient() {
7474

7575
List<BasicHeader> headers = new ArrayList<>();
7676

77-
if (config.getSigningApiServer().getApiKey() != null) {
77+
if (!config.getSigningApiServer().getApiKey().isEmpty()) {
7878
headers.add(
7979
new BasicHeader(HttpHeaders.AUTHORIZATION, "Bearer " + config.getSigningApiServer().getApiKey()));
8080
}

src/main/java/app/coronawarn/dcc/service/DccService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public DccRegistration sign(DccRegistration registration) throws DccGenerateExce
5858
byte[] hashBytes = Hex.decode(registration.getDccHash());
5959
String hashBase64 = Base64.getEncoder().encodeToString(hashBytes);
6060

61-
coseBytes = callSigningApiWithRetry(hashBase64);
61+
coseBytes = callSigningApiWithRetry(hashBase64, registration.getLabId());
6262
} catch (FeignException e) {
6363
log.error("Failed to sign DCC. Http Status Code: {}, Message: {}", e.status(), e.getMessage());
6464

@@ -81,12 +81,12 @@ public DccRegistration sign(DccRegistration registration) throws DccGenerateExce
8181
return registration;
8282
}
8383

84-
private byte[] callSigningApiWithRetry(String hashBase64) {
84+
private byte[] callSigningApiWithRetry(String hashBase64, String labId) {
8585
try {
86-
return signingApiClient.sign(hashBase64);
86+
return signingApiClient.sign(hashBase64, labId);
8787
} catch (FeignException e) {
8888
log.info("First try of calling Signing API failed. Status Code: {}, Message: {}", e.status(), e.getMessage());
89-
return signingApiClient.sign(hashBase64);
89+
return signingApiClient.sign(hashBase64, labId);
9090
}
9191
}
9292

src/main/resources/application-cloud.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ cwa:
4343
key-store-password: ${CWA_DCC_SIGNINGAPISERVER_KEYSTOREPASSWORD}
4444
trust-store-password: ${CWA_DCC_SIGNINGAPISERVER_TRUSTSTOREPASSWORD}
4545
trust-store-path: ${CWA_DCC_SIGNINGAPISERVER_TRUSTSTOREPATH}
46-
api-key: ${CWA_DCC_SIGNINGAPISERVER_APIKEY}
46+
api-key: ${CWA_DCC_SIGNINGAPISERVER_APIKEY:}
4747
verify-hostnames: true
48-
connection-close-workaround: ${CWA_DCC_SIGNINGAPISERVER_CONNECTIONCLOSEWORKAROUND}
48+
connection-close-workaround: ${CWA_DCC_SIGNINGAPISERVER_CONNECTIONCLOSEWORKAROUND:false}
4949
request:
5050
sizelimit: 10000
5151
entities:

src/test/java/app/coronawarn/dcc/controller/InternalDccControllerTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void setup() {
103103
when(verificationServerClientMock.result(eq(registrationToken)))
104104
.thenReturn(new InternalTestResult(6, labId, testId, 0));
105105

106-
when(signingApiClientMock.sign(eq(dccHashBase64)))
106+
when(signingApiClientMock.sign(eq(dccHashBase64), eq(labId)))
107107
.thenReturn(partialDcc);
108108
}
109109

@@ -123,7 +123,7 @@ void testUploadDcc() throws Exception {
123123
.andExpect(status().isOk())
124124
.andExpect(jsonPath("$.partialDcc").value(equalTo(partialDccBase64)));
125125

126-
verify(signingApiClientMock).sign(eq(dccHashBase64));
126+
verify(signingApiClientMock).sign(eq(dccHashBase64), eq(labId));
127127

128128
Optional<DccRegistration> dccRegistration = dccRegistrationRepository.findByRegistrationToken(registrationTokenValue);
129129

@@ -147,7 +147,7 @@ void testUploadDccFailedUnknownTestId() throws Exception {
147147
)
148148
.andExpect(status().isNotFound());
149149

150-
verify(signingApiClientMock, never()).sign(eq(dccHashBase64));
150+
verify(signingApiClientMock, never()).sign(eq(dccHashBase64), eq(labId));
151151
}
152152

153153
@Test
@@ -166,7 +166,7 @@ void testUploadDccFailedLabIdNotAssignedToPartner() throws Exception {
166166
)
167167
.andExpect(status().isForbidden());
168168

169-
verify(signingApiClientMock, never()).sign(eq(dccHashBase64));
169+
verify(signingApiClientMock, never()).sign(eq(dccHashBase64), eq(labId));
170170
}
171171

172172
@Test
@@ -186,7 +186,7 @@ void testUploadDccFailedAlreadyExists() throws Exception {
186186
)
187187
.andExpect(status().isConflict());
188188

189-
verify(signingApiClientMock, never()).sign(eq(dccHashBase64));
189+
verify(signingApiClientMock, never()).sign(eq(dccHashBase64), eq(labId));
190190
}
191191

192192
@Test
@@ -202,7 +202,7 @@ void testUploadDccFailedInvalidDCC() throws Exception {
202202
)
203203
.andExpect(status().isBadRequest());
204204

205-
verify(signingApiClientMock, never()).sign(eq(dccHashBase64));
205+
verify(signingApiClientMock, never()).sign(eq(dccHashBase64), eq(labId));
206206
}
207207

208208
@Test
@@ -218,7 +218,7 @@ void testUploadDccFailedInvalidDek() throws Exception {
218218
)
219219
.andExpect(status().isBadRequest());
220220

221-
verify(signingApiClientMock, never()).sign(eq(dccHashBase64));
221+
verify(signingApiClientMock, never()).sign(eq(dccHashBase64), eq(labId));
222222
}
223223

224224
@Test
@@ -228,7 +228,7 @@ void testUploadDccFailedBadResponseFromSignignAPI4xx() throws Exception {
228228
DccUploadRequest dccUploadRequest = new DccUploadRequest(dccHash, encryptedDccBase64, encryptedDekBase64);
229229

230230
doThrow(new FeignException.BadRequest("", dummyRequest, null))
231-
.when(signingApiClientMock).sign(eq(dccHashBase64));
231+
.when(signingApiClientMock).sign(eq(dccHashBase64), eq(labId));
232232

233233
mockMvc.perform(post("/version/v1/test/" + testId + "/dcc")
234234
.contentType(MediaType.APPLICATION_JSON_VALUE)
@@ -254,7 +254,7 @@ void testUploadDccFailedBadResponseFromSignignAPI5xx() throws Exception {
254254
DccUploadRequest dccUploadRequest = new DccUploadRequest(dccHash, encryptedDccBase64, encryptedDekBase64);
255255

256256
doThrow(new FeignException.InternalServerError("", dummyRequest, null))
257-
.when(signingApiClientMock).sign(eq(dccHashBase64));
257+
.when(signingApiClientMock).sign(eq(dccHashBase64), eq(labId));
258258

259259
mockMvc.perform(post("/version/v1/test/" + testId + "/dcc")
260260
.contentType(MediaType.APPLICATION_JSON_VALUE)

src/test/java/app/coronawarn/dcc/service/DccServiceTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void setup() {
8080
void testSigning() throws NoSuchAlgorithmException, DccRegistrationService.DccRegistrationException {
8181

8282
when(verificationServerClientMock.result(eq(registrationToken))).thenReturn(new InternalTestResult(6, labId, testId, 0));
83-
when(signingApiClient.sign(eq(Base64.getEncoder().encodeToString(Hex.decode(dccHash))))).thenReturn(partialDcc);
83+
when(signingApiClient.sign(eq(Base64.getEncoder().encodeToString(Hex.decode(dccHash))), eq(labId))).thenReturn(partialDcc);
8484

8585
PublicKey publicKey = TestUtils.generateKeyPair().getPublic();
8686
DccRegistration registration = dccRegistrationService.createDccRegistration(registrationTokenValue, publicKey);
@@ -105,7 +105,7 @@ void testSigningFailedBySigningApi4xx() throws NoSuchAlgorithmException, DccRegi
105105
when(verificationServerClientMock.result(eq(registrationToken))).thenReturn(new InternalTestResult(6, labId, testId, 0));
106106

107107
doThrow(new FeignException.BadRequest("", dummyRequest, null))
108-
.when(signingApiClient).sign(eq(Base64.getEncoder().encodeToString(Hex.decode(dccHash))));
108+
.when(signingApiClient).sign(eq(Base64.getEncoder().encodeToString(Hex.decode(dccHash))), eq(labId));
109109

110110
PublicKey publicKey = TestUtils.generateKeyPair().getPublic();
111111
DccRegistration registration = dccRegistrationService.createDccRegistration(registrationTokenValue, publicKey);
@@ -131,7 +131,7 @@ void testSigningFailedBySigningApi5xx() throws NoSuchAlgorithmException, DccRegi
131131
when(verificationServerClientMock.result(eq(registrationToken))).thenReturn(new InternalTestResult(6, labId, testId, 0));
132132

133133
doThrow(new FeignException.InternalServerError("", dummyRequest, null))
134-
.when(signingApiClient).sign(eq(Base64.getEncoder().encodeToString(Hex.decode(dccHash))));
134+
.when(signingApiClient).sign(eq(Base64.getEncoder().encodeToString(Hex.decode(dccHash))), eq(labId));
135135

136136
PublicKey publicKey = TestUtils.generateKeyPair().getPublic();
137137
DccRegistration registration = dccRegistrationService.createDccRegistration(registrationTokenValue, publicKey);
@@ -158,7 +158,7 @@ void testSigningRetry() throws NoSuchAlgorithmException, DccRegistrationService.
158158

159159
doThrow(new FeignException.InternalServerError("", dummyRequest, null))
160160
.doReturn(partialDcc)
161-
.when(signingApiClient).sign(eq(Base64.getEncoder().encodeToString(Hex.decode(dccHash))));
161+
.when(signingApiClient).sign(eq(Base64.getEncoder().encodeToString(Hex.decode(dccHash))), eq(labId));
162162

163163
PublicKey publicKey = TestUtils.generateKeyPair().getPublic();
164164
DccRegistration registration = dccRegistrationService.createDccRegistration(registrationTokenValue, publicKey);
@@ -185,7 +185,7 @@ void testSigningFailedOnFirstRequestButSuccessOnSecond() throws NoSuchAlgorithmE
185185
doThrow(new FeignException.InternalServerError("", dummyRequest, null))
186186
.doThrow(new FeignException.InternalServerError("", dummyRequest, null))
187187
.doReturn(partialDcc)
188-
.when(signingApiClient).sign(eq(Base64.getEncoder().encodeToString(Hex.decode(dccHash))));
188+
.when(signingApiClient).sign(eq(Base64.getEncoder().encodeToString(Hex.decode(dccHash))), eq(labId));
189189

190190
PublicKey publicKey = TestUtils.generateKeyPair().getPublic();
191191
DccRegistration registration = dccRegistrationService.createDccRegistration(registrationTokenValue, publicKey);

0 commit comments

Comments
 (0)