diff --git a/.github/workflows/ci-dockerfile.yml b/.github/workflows/ci-dockerfile.yml index cdf701e3..33147efb 100644 --- a/.github/workflows/ci-dockerfile.yml +++ b/.github/workflows/ci-dockerfile.yml @@ -1,5 +1,6 @@ name: ci-dockerfile on: + workflow_dispatch: push: branches: - master diff --git a/src/main/java/app/coronawarn/verification/controller/ExternalTestStateController.java b/src/main/java/app/coronawarn/verification/controller/ExternalTestStateController.java index 154a4c7d..ee9f8cea 100644 --- a/src/main/java/app/coronawarn/verification/controller/ExternalTestStateController.java +++ b/src/main/java/app/coronawarn/verification/controller/ExternalTestStateController.java @@ -16,6 +16,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; +import java.time.ZoneOffset; import java.util.Optional; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -75,7 +76,9 @@ public class ExternalTestStateController { * * @param registrationToken generated by a hashed guid {@link RegistrationToken} * @param fake flag for fake request - * @return result of the test, which can be POSITIVE, NEGATIVE, INVALID, PENDING or FAILED will POSITIVE for TeleTan + * @return result of the test, which can be POSITIVE, NEGATIVE, INVALID, PENDING, FAILED, + * quick-test-POSITIVE, quick-test-NEGATIVE, quick-test-INVALID, quick-test-PENDING or quick-test-FAILED + * will be POSITIVE for TeleTan */ @Operation( summary = "COVID-19 test result for given RegistrationToken", @@ -111,14 +114,16 @@ public DeferredResult> getTestState( log.info("The result for registration token based on hashed Guid will be returned."); stopWatch.stop(); fakeDelayService.updateFakeTestRequestDelay(stopWatch.getTotalTimeMillis()); - deferredResult.setResult(ResponseEntity.ok(generateReturnTestResult(testResult.getTestResult(),fake))); + deferredResult.setResult(ResponseEntity.ok(generateReturnTestResult(testResult.getTestResult(),fake, + testResult.getCs()))); return deferredResult; case TELETAN: log.info("The result for registration token based on teleTAN will be returned."); stopWatch.stop(); fakeDelayService.updateFakeTestRequestDelay(stopWatch.getTotalTimeMillis()); scheduledExecutor.schedule(() -> deferredResult.setResult(ResponseEntity.ok( - generateReturnTestResult(LabTestResult.POSITIVE.getTestResult(), fake))), + generateReturnTestResult(LabTestResult.POSITIVE.getTestResult(), fake, + appSession.get().getCreatedAt().toEpochSecond(ZoneOffset.UTC)))), fakeDelayService.realDelayTest(), MILLISECONDS); return deferredResult; default: @@ -132,11 +137,12 @@ public DeferredResult> getTestState( "Returning the test result for the registration token failed"); } - private TestResult generateReturnTestResult(Integer testResult, String fake) { + private TestResult generateReturnTestResult(Integer testResult, String fake, Long cs) { if (fake == null) { - return new TestResult(testResult); + return new TestResult(testResult,cs, RandomStringUtils.randomAlphanumeric(RESPONSE_PADDING_LENGTH)); } - return new TestResult(testResult, RandomStringUtils.randomAlphanumeric(RESPONSE_PADDING_LENGTH)); + return new TestResult(testResult, System.currentTimeMillis(), + RandomStringUtils.randomAlphanumeric(RESPONSE_PADDING_LENGTH)); } } diff --git a/src/main/java/app/coronawarn/verification/model/TestResult.java b/src/main/java/app/coronawarn/verification/model/TestResult.java index 1d4d6bb5..f0ce71b1 100644 --- a/src/main/java/app/coronawarn/verification/model/TestResult.java +++ b/src/main/java/app/coronawarn/verification/model/TestResult.java @@ -23,6 +23,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.media.Schema; +import java.time.LocalDateTime; import javax.persistence.Transient; import lombok.AllArgsConstructor; import lombok.Data; @@ -47,6 +48,9 @@ public class TestResult { @NonNull private int testResult; + @NonNull + private long cs; + @JsonInclude(JsonInclude.Include.NON_NULL) @Transient private String responsePadding; diff --git a/src/main/java/app/coronawarn/verification/service/FakeRequestService.java b/src/main/java/app/coronawarn/verification/service/FakeRequestService.java index 9a7ac61a..6f86a0fb 100644 --- a/src/main/java/app/coronawarn/verification/service/FakeRequestService.java +++ b/src/main/java/app/coronawarn/verification/service/FakeRequestService.java @@ -108,7 +108,7 @@ public DeferredResult> getTestState( long delay = fakeDelayService.getLongestJitter(); DeferredResult> deferredResult = new DeferredResult<>(); scheduledExecutor.schedule(() -> deferredResult.setResult(ResponseEntity - .ok(new TestResult(LabTestResult.POSITIVE.getTestResult(), + .ok(new TestResult(LabTestResult.POSITIVE.getTestResult(), System.currentTimeMillis(), RandomStringUtils.randomAlphanumeric(TEST_RESPONSE_PADDING_LENGTH)))), delay, MILLISECONDS); return deferredResult; } diff --git a/src/test/java/app/coronawarn/verification/TestUtils.java b/src/test/java/app/coronawarn/verification/TestUtils.java index d5b33c5e..c99f6c52 100644 --- a/src/test/java/app/coronawarn/verification/TestUtils.java +++ b/src/test/java/app/coronawarn/verification/TestUtils.java @@ -35,9 +35,9 @@ public class TestUtils { static final String TEST_INVALID_REG_TOK = "1234567890"; static final String TEST_REG_TOK = "1ea6ce8a-9740-41ea-bb37-0242ac130002"; static final String TEST_REG_TOK_HASH = "0199effab87800689c15c08e234db54f088cc365132ffc230e882b82cd3ecf95"; - static final TestResult TEST_LAB_POSITIVE_RESULT = new TestResult(2); - static final TestResult QUICK_TEST_POSITIVE_RESULT = new TestResult(7); - static final TestResult TEST_LAB_NEGATIVE_RESULT = new TestResult(1); + static final TestResult TEST_LAB_POSITIVE_RESULT = new TestResult(2,0); + static final TestResult QUICK_TEST_POSITIVE_RESULT = new TestResult(7,0); + static final TestResult TEST_LAB_NEGATIVE_RESULT = new TestResult(1,0); static final String TEST_TAN = "1819d933-45f6-4e3c-80c7-eeffd2d44ee6"; static final String TEST_INVALID_TAN = "1ea6ce8a-9740-11ea-is-invalid"; static final TanSourceOfTrust TEST_SOT = TanSourceOfTrust.CONNECTED_LAB; diff --git a/src/test/java/app/coronawarn/verification/VerificationApplicationExternalTest.java b/src/test/java/app/coronawarn/verification/VerificationApplicationExternalTest.java index 9293499f..4b865fd9 100644 --- a/src/test/java/app/coronawarn/verification/VerificationApplicationExternalTest.java +++ b/src/test/java/app/coronawarn/verification/VerificationApplicationExternalTest.java @@ -556,7 +556,11 @@ public void callGetTestState() throws Exception { mockMvc.perform(post(TestUtils.PREFIX_API_VERSION + "/testresult").contentType(MediaType.APPLICATION_JSON) .secure( true ) .content(TestUtils.getAsJsonFormat(new RegistrationToken(TestUtils.TEST_REG_TOK,TOKEN_PADDING)))) - .andExpect(status().isOk()); + .andExpect(status().isOk()) + .andReturn() + .getResponse() + .getContentAsString() + .contains("cs"); } /** @@ -576,7 +580,11 @@ public void callGetTestStateWithFake() throws Exception { .secure( true ) .header("cwa-fake", "1") .content(TestUtils.getAsJsonFormat(new RegistrationToken(TestUtils.TEST_REG_TOK,TOKEN_PADDING)))) - .andExpect(status().isOk()); + .andExpect(status().isOk()) + .andReturn() + .getResponse() + .getContentAsString() + .contains("cs"); } /** diff --git a/src/test/java/app/coronawarn/verification/service/TestResultServerServiceTest.java b/src/test/java/app/coronawarn/verification/service/TestResultServerServiceTest.java index 2ac35380..0635c1c4 100644 --- a/src/test/java/app/coronawarn/verification/service/TestResultServerServiceTest.java +++ b/src/test/java/app/coronawarn/verification/service/TestResultServerServiceTest.java @@ -34,8 +34,8 @@ public class TestResultServerServiceTest { public static final String TEST_GUI_HASH_1 = "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b"; public static final String TEST_GUI_HASH_2 = "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13c"; private static final String TEST_RESULT_PADDING = ""; - public static final TestResult TEST_LAB_POSITIVE_RESULT = new TestResult(2); - public static final TestResult TEST_LAB_REDEEMED_RESULT = new TestResult(4); + public static final TestResult TEST_LAB_POSITIVE_RESULT = new TestResult(2,0); + public static final TestResult TEST_LAB_REDEEMED_RESULT = new TestResult(4,0); private TestResultServerService testResultServerService; @BeforeEach @@ -65,9 +65,9 @@ public static class TestResultServerClientMock implements TestResultServerClient @Override public TestResult result(HashedGuid guid) { if (guid.getId().equals(TEST_GUI_HASH_1)) { - return new TestResult(2); + return new TestResult(2,0); } - return new TestResult(4); + return new TestResult(4,0); } } }