Search in sources :

Example 6 with Status

use of fi.thl.covid19.exposurenotification.diagnosiskey.v1.Status in project yakc by manusa.

the class ConfigMapIT method deleteNamespacedConfigMap.

@Test
@DisplayName("deleteNamespacedConfigMap, should delete existing ConfigMap")
void deleteNamespacedConfigMap() throws IOException {
    // When
    final Status result = KC.create(CoreV1Api.class).deleteNamespacedConfigMap(configMapName, NAMESPACE).get();
    // Then
    assertAll("Deleted configMap", () -> assertThat(result).isNotNull(), () -> assertThat(result.getStatus()).isEqualTo("Success"));
}
Also used : Status(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.Status) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 7 with Status

use of fi.thl.covid19.exposurenotification.diagnosiskey.v1.Status in project koronavilkku-backend by THLfi.

the class DiagnosisKeyControllerIT method reusingTokenForDifferentRequestIs403.

@Test
public void reusingTokenForDifferentRequestIs403() throws Exception {
    PublishTokenVerification verification = new PublishTokenVerification(1, LocalDate.now().minus(7, DAYS), Optional.empty());
    given(tokenVerificationService.getVerification("123654032165")).willReturn(verification);
    DiagnosisPublishRequest request1 = new DiagnosisPublishRequest(keyGenerator.someRequestKeys(14), Optional.empty(), Optional.empty());
    DiagnosisPublishRequest request2 = new DiagnosisPublishRequest(keyGenerator.someRequestKeys(14), Optional.empty(), Optional.empty());
    verifiedPost("123654032165", request1);
    mockMvc.perform(post(BASE_URL).contentType(MediaType.APPLICATION_JSON).header(PUBLISH_TOKEN_HEADER, "123654032165").header(FAKE_REQUEST_HEADER, 0).content(mapper.writeValueAsString(request2))).andExpect(status().isForbidden()).andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(content().string(containsString("Publish token not accepted")));
    verify(tokenVerificationService, times(2)).getVerification("123654032165");
}
Also used : PublishTokenVerification(fi.thl.covid19.exposurenotification.tokenverification.PublishTokenVerification) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with Status

use of fi.thl.covid19.exposurenotification.diagnosiskey.v1.Status in project koronavilkku-backend by THLfi.

the class DiagnosisKeyController method getCurrentStatus.

@GetMapping("/status")
public ResponseEntity<Status> getCurrentStatus(@RequestParam(value = "batch") Optional<BatchId> batchId, @RequestParam(value = "app-config") Optional<Integer> appConfigVersion, @RequestParam(value = "exposure-config") Optional<Integer> exposureConfigVersion, @RequestParam(value = "exposure-config-v2") Optional<Integer> exposureConfigVersionV2, @RequestParam(value = "en-api-version") Optional<Integer> enApiVersionOptional) {
    int enApiVersion = enApiVersionOptional.orElse(1);
    LOG.info("Fetching full status info: {} {} {} {} {}", keyValue("clientBatchId", batchId), keyValue("clientAppConfigVersion", appConfigVersion), keyValue("enApiVersion", enApiVersion), keyValue("clientExposureConfigVersion", exposureConfigVersion), keyValue("clientExposureConfigVersionV2", exposureConfigVersionV2));
    BatchIntervals intervals = enApiVersion == 2 ? getExportIntervalsV2() : getExportIntervals();
    ExposureConfiguration exposureConfig = configurationService.getLatestExposureConfig();
    ExposureConfigurationV2 exposureConfigV2 = configurationService.getLatestV2ExposureConfig();
    AppConfiguration appConfig = configurationService.getLatestAppConfig();
    Status result = new Status(batchId.map(id -> enApiVersion == 2 ? batchFileService.listBatchIdsSinceV2(id, intervals) : batchFileService.listBatchIdsSince(id, intervals)).orElse(List.of()), toLatest(appConfig, appConfig.version, appConfigVersion), toLatest(exposureConfig, exposureConfig.version, exposureConfigVersion), toLatest(exposureConfigV2, exposureConfigV2.version, exposureConfigVersionV2));
    boolean cacheableBatchId = batchId.isEmpty() || intervals.isDistributed(batchId.get().intervalNumber);
    boolean cacheableAppConfig = appConfigVersion.isEmpty() || appConfigVersion.get().equals(appConfig.version);
    boolean cacheableExposureConfig = exposureConfigVersion.isEmpty() || exposureConfigVersion.get().equals(exposureConfig.version);
    boolean cacheableExposureConfigV2 = exposureConfigVersionV2.isEmpty() || exposureConfigVersionV2.get().equals(exposureConfigV2.version);
    return statusResponse(result, cacheableBatchId && cacheableAppConfig && cacheableExposureConfig && cacheableExposureConfigV2);
}
Also used : ExposureConfigurationV2(fi.thl.covid19.exposurenotification.configuration.v2.ExposureConfigurationV2) AppConfiguration(fi.thl.covid19.exposurenotification.configuration.v1.AppConfiguration) ExposureConfiguration(fi.thl.covid19.exposurenotification.configuration.v1.ExposureConfiguration) BatchIntervals(fi.thl.covid19.exposurenotification.batch.BatchIntervals)

Example 9 with Status

use of fi.thl.covid19.exposurenotification.diagnosiskey.v1.Status in project koronavilkku-backend by THLfi.

the class DiagnosisKeyControllerDemoIT method assertListing.

private void assertListing(BatchId previous, List<BatchId> expected, boolean v2) throws Exception {
    BatchList list = new BatchList(expected);
    String listUrl = v2 ? LIST_URL_V2 : LIST_URL;
    mockMvc.perform(get(listUrl + previous)).andExpect(status().isOk()).andExpect(header().exists("Cache-Control")).andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(content().json(mapper.writeValueAsString(list)));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) BatchList(fi.thl.covid19.exposurenotification.diagnosiskey.v1.BatchList)

Example 10 with Status

use of fi.thl.covid19.exposurenotification.diagnosiskey.v1.Status in project koronavilkku-backend by THLfi.

the class PublishTokenVerificationServiceRest method getVerification.

@Override
public PublishTokenVerification getVerification(String token) {
    String url = publishTokenUrl + TOKEN_VERIFICATION_PATH;
    try {
        HttpHeaders headers = new HttpHeaders();
        headers.setAccept(List.of(MediaType.APPLICATION_JSON));
        headers.add(PUBLISH_TOKEN_HEADER, token);
        HttpEntity<String> entity = new HttpEntity<>(null, headers);
        ResponseEntity<PublishTokenVerification> reply = restTemplate.exchange(url, HttpMethod.GET, entity, PublishTokenVerification.class);
        if (reply.getStatusCode().is2xxSuccessful() && reply.hasBody()) {
            return reply.getBody();
        } else {
            LOG.warn("Server didn't verify publish token: {}", keyValue("status", reply.getStatusCode()));
            throw new TokenValidationException();
        }
    } catch (HttpClientErrorException e) {
        LOG.warn("Publish token not verified: {}", keyValue("result", e.getStatusCode()), e);
        throw new TokenValidationException();
    } catch (HttpServerErrorException e) {
        LOG.error("Error in token service: {}", keyValue("url", url), e);
    } catch (RestClientException e) {
        LOG.error("Error verifying token request: {}", keyValue("url", url), e);
    }
    throw new IllegalStateException("Could not handle token verification");
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) RestClientException(org.springframework.web.client.RestClientException) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) TokenValidationException(fi.thl.covid19.exposurenotification.error.TokenValidationException)

Aggregations

Status (com.microsoft.z3.Status)63 BoolExpr (com.microsoft.z3.BoolExpr)55 Test (org.junit.Test)49 Test (org.junit.jupiter.api.Test)20 Expr (com.microsoft.z3.Expr)10 IOException (java.io.IOException)10 JsonMapper.convertObjectToJsonString (com.arbindo.mimock.helpers.general.JsonMapper.convertObjectToJsonString)9 RandomDataGenerator.generateRandomAlphabeticString (com.arbindo.mimock.helpers.general.RandomDataGenerator.generateRandomAlphabeticString)9 Status (com.arbindo.mimock.manage.mimocks.models.v1.Status)9 Context (com.microsoft.z3.Context)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)9 Pageable (org.springframework.data.domain.Pageable)9 HttpStatus (org.springframework.http.HttpStatus)9 MvcResult (org.springframework.test.web.servlet.MvcResult)9 Mock (com.arbindo.mimock.entities.Mock)8 List (java.util.List)7 Solver (com.microsoft.z3.Solver)6 PageImpl (org.springframework.data.domain.PageImpl)6