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

Add tests to ensure requests are monitored by SubmissionController #544

Merged
merged 4 commits into from
Jun 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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