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

Commit

Permalink
Add tests to ensure requests are monitored (#544)
Browse files Browse the repository at this point in the history
Co-authored-by: Christian Kirschnick <[email protected]>
  • Loading branch information
pcvolkmer and christian-kirschnick authored Jun 11, 2020
1 parent 8597264 commit 39cf982
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
Expand All @@ -46,6 +47,7 @@
import app.coronawarn.server.common.persistence.service.DiagnosisKeyService;
import app.coronawarn.server.common.protocols.external.exposurenotification.TemporaryExposureKey;
import app.coronawarn.server.services.submission.config.SubmissionServiceConfig;
import app.coronawarn.server.services.submission.monitoring.SubmissionControllerMonitor;
import app.coronawarn.server.services.submission.verification.TanVerifier;
import com.google.protobuf.ByteString;
import java.net.URI;
Expand Down Expand Up @@ -83,6 +85,9 @@ class SubmissionControllerTest {
@MockBean
private TanVerifier tanVerifier;

@MockBean
private SubmissionControllerMonitor submissionControllerMonitor;

@Autowired
private TestRestTemplate testRestTemplate;

Expand Down Expand Up @@ -205,6 +210,41 @@ void fakeRequestHandling() {
assertThat(actResponse.getStatusCode()).isEqualTo(OK);
}

@Test
void checkRealRequestHandlingIsMonitored() {
ResponseEntity<Void> actResponse = executor.executeRequest(buildPayloadWithOneKey(), buildOkHeaders());

verify(submissionControllerMonitor, times(1)).incrementRequestCounter();
verify(submissionControllerMonitor, times(1)).incrementRealRequestCounter();
verify(submissionControllerMonitor, never()).incrementFakeRequestCounter();
verify(submissionControllerMonitor, never()).incrementInvalidTanRequestCounter();
}

@Test
void checkFakeRequestHandlingIsMonitored() {
HttpHeaders headers = buildOkHeaders();
setCwaFakeHeader(headers, "1");

ResponseEntity<Void> actResponse = executor.executeRequest(buildPayloadWithOneKey(), headers);

verify(submissionControllerMonitor, times(1)).incrementRequestCounter();
verify(submissionControllerMonitor, never()).incrementRealRequestCounter();
verify(submissionControllerMonitor, times(1)).incrementFakeRequestCounter();
verify(submissionControllerMonitor, never()).incrementInvalidTanRequestCounter();
}

@Test
void checkInvalidTanHandlingIsMonitored() {
when(tanVerifier.verifyTan(anyString())).thenReturn(false);

ResponseEntity<Void> actResponse = executor.executeRequest(buildPayloadWithOneKey(), buildOkHeaders());

verify(submissionControllerMonitor, times(1)).incrementRequestCounter();
verify(submissionControllerMonitor, times(1)).incrementRealRequestCounter();
verify(submissionControllerMonitor, never()).incrementFakeRequestCounter();
verify(submissionControllerMonitor, times(1)).incrementInvalidTanRequestCounter();
}

private static Collection<TemporaryExposureKey> buildPayloadWithOneKey() {
return Collections.singleton(buildTemporaryExposureKey(VALID_KEY_DATA_1, 1, 3));
}
Expand Down

0 comments on commit 39cf982

Please sign in to comment.