2727import static app .coronawarn .dcc .utils .TestValues .registrationTokenValue ;
2828import static app .coronawarn .dcc .utils .TestValues .testId ;
2929import static org .mockito .ArgumentMatchers .eq ;
30- import static org .mockito .Mockito .doReturn ;
3130import static org .mockito .Mockito .doThrow ;
3231import static org .mockito .Mockito .reset ;
3332import static org .mockito .Mockito .when ;
@@ -100,9 +99,9 @@ void testUploadPublicKey() throws Exception {
10099 registrationTokenValue , publicKeyBase64 , "" );
101100
102101 mockMvc .perform (post ("/version/v1/publicKey" )
103- .contentType (MediaType .APPLICATION_JSON_VALUE )
104- .content (new ObjectMapper ().writeValueAsString (uploadPublicKeyRequest ))
105- )
102+ .contentType (MediaType .APPLICATION_JSON_VALUE )
103+ .content (new ObjectMapper ().writeValueAsString (uploadPublicKeyRequest ))
104+ )
106105 .andExpect (status ().isCreated ());
107106
108107
@@ -120,9 +119,9 @@ void testUploadPublicKeyFailedInvalidPublicKey() throws Exception {
120119 registrationTokenValue , publicKeyBase64 , "" );
121120
122121 mockMvc .perform (post ("/version/v1/publicKey" )
123- .contentType (MediaType .APPLICATION_JSON_VALUE )
124- .content (new ObjectMapper ().writeValueAsString (uploadPublicKeyRequest ))
125- )
122+ .contentType (MediaType .APPLICATION_JSON_VALUE )
123+ .content (new ObjectMapper ().writeValueAsString (uploadPublicKeyRequest ))
124+ )
126125 .andExpect (status ().isBadRequest ());
127126 }
128127
@@ -140,12 +139,31 @@ void testUploadPublicKeyInvalidRegistrationTokenForbidden() throws Exception {
140139 .when (verificationServerClientMock ).result (eq (registrationToken ));
141140
142141 mockMvc .perform (post ("/version/v1/publicKey" )
143- .contentType (MediaType .APPLICATION_JSON_VALUE )
144- .content (new ObjectMapper ().writeValueAsString (uploadPublicKeyRequest ))
145- )
142+ .contentType (MediaType .APPLICATION_JSON_VALUE )
143+ .content (new ObjectMapper ().writeValueAsString (uploadPublicKeyRequest ))
144+ )
146145 .andExpect (status ().isForbidden ());
147146 }
148147
148+ @ Test
149+ void testUploadPublicKeyInvalidRegistrationTokenNoLabId () throws Exception {
150+ KeyPair keyPair = TestUtils .generateKeyPair ();
151+ String publicKeyBase64 = Base64 .getEncoder ().encodeToString (keyPair .getPublic ().getEncoded ());
152+
153+ UploadPublicKeyRequest uploadPublicKeyRequest = new UploadPublicKeyRequest (
154+ registrationTokenValue , publicKeyBase64 , "" );
155+
156+ reset (verificationServerClientMock );
157+
158+ when (verificationServerClientMock .result (eq (registrationToken )))
159+ .thenReturn (new InternalTestResult (6 , null , testId , 0 ));
160+
161+ mockMvc .perform (post ("/version/v1/publicKey" )
162+ .contentType (MediaType .APPLICATION_JSON_VALUE )
163+ .content (new ObjectMapper ().writeValueAsString (uploadPublicKeyRequest ))
164+ )
165+ .andExpect (status ().isForbidden ());
166+ }
149167
150168 @ Test
151169 void testUploadPublicKeyInvalidRegistrationTokenNotFound () throws Exception {
@@ -161,9 +179,9 @@ void testUploadPublicKeyInvalidRegistrationTokenNotFound() throws Exception {
161179 .when (verificationServerClientMock ).result (eq (registrationToken ));
162180
163181 mockMvc .perform (post ("/version/v1/publicKey" )
164- .contentType (MediaType .APPLICATION_JSON_VALUE )
165- .content (new ObjectMapper ().writeValueAsString (uploadPublicKeyRequest ))
166- )
182+ .contentType (MediaType .APPLICATION_JSON_VALUE )
183+ .content (new ObjectMapper ().writeValueAsString (uploadPublicKeyRequest ))
184+ )
167185 .andExpect (status ().isNotFound ());
168186 }
169187
@@ -182,9 +200,9 @@ void testUploadPublicKeyInvalidRegistrationTokenInternalServerError() throws Exc
182200 .when (verificationServerClientMock ).result (eq (registrationToken ));
183201
184202 mockMvc .perform (post ("/version/v1/publicKey" )
185- .contentType (MediaType .APPLICATION_JSON_VALUE )
186- .content (new ObjectMapper ().writeValueAsString (uploadPublicKeyRequest ))
187- )
203+ .contentType (MediaType .APPLICATION_JSON_VALUE )
204+ .content (new ObjectMapper ().writeValueAsString (uploadPublicKeyRequest ))
205+ )
188206 .andExpect (status ().isInternalServerError ());
189207 }
190208
@@ -199,9 +217,9 @@ void testUploadPublicKeyFailedAlreadyExists() throws Exception {
199217 registrationTokenValue , publicKeyBase64 , "" );
200218
201219 mockMvc .perform (post ("/version/v1/publicKey" )
202- .contentType (MediaType .APPLICATION_JSON_VALUE )
203- .content (new ObjectMapper ().writeValueAsString (uploadPublicKeyRequest ))
204- )
220+ .contentType (MediaType .APPLICATION_JSON_VALUE )
221+ .content (new ObjectMapper ().writeValueAsString (uploadPublicKeyRequest ))
222+ )
205223 .andExpect (status ().isConflict ());
206224 }
207225
@@ -219,9 +237,9 @@ void testUploadPublicKeyFailedTestResultPending() throws Exception {
219237 .thenReturn (new InternalTestResult (0 , labId , testId , 0 ));
220238
221239 mockMvc .perform (post ("/version/v1/publicKey" )
222- .contentType (MediaType .APPLICATION_JSON_VALUE )
223- .content (new ObjectMapper ().writeValueAsString (uploadPublicKeyRequest ))
224- )
240+ .contentType (MediaType .APPLICATION_JSON_VALUE )
241+ .content (new ObjectMapper ().writeValueAsString (uploadPublicKeyRequest ))
242+ )
225243 .andExpect (status ().isForbidden ());
226244 }
227245
0 commit comments