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

Commit

Permalink
add feature flag and force update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ubhaller committed Jul 20, 2021
1 parent cfebbe4 commit b104639
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package ch.admin.bag.covidcertificate.backend.config.wallet.ws.model;
package ch.admin.bag.covidcertificate.backend.config.shared.model;

import ch.admin.bag.covidcertificate.backend.config.shared.model.ConfigResponse;
import ch.admin.bag.covidcertificate.backend.config.shared.model.Faq;
import ch.admin.bag.covidcertificate.backend.config.shared.model.Language;
import ch.ubique.openapi.docannotations.Documentation;
import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# test p12 for local development use
ws.jws.p12=MIINSQIBAzCCDQ8GCSqGSIb3DQEHAaCCDQAEggz8MIIM+DCCB68GCSqGSIb3DQEHBqCCB6AwggecAgEAMIIHlQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQI+x7LZ9zcmVkCAggAgIIHaOU4SBYpPUzUm+Obc5SZ3MTKaXNjgWZnfz7/8DuvDEjpWUh+Mvj37kp3gX+8eQmwQTPcU5uWeWWrc8dcfxNKjShhF/i5eQt8EKIMKEKEk5cRa2CrIJ77/rCWDIkuYfteV984wPFbGZ/A1LT8NSsOBfhn/xiwEBpNb0ZyQNr+yuUZbSlLqRloPjZBRtdshDQdgUaA5Nbl+QO/SDWXxXdVudeNzYaWEyW5fWGYpbaCDde69pmQTNs8STNiopfR7mNTarRyxA6tfsYQJV54aR8rr3sm++9JxLU0KKJRwetCOpxMORtQAkKig+p6OAq/73qOGhAYAAWHs36Ki1t/HO0PwJ1H3VJOaSsTMP+OgNUpxqW+289vfwkL9QEpEsv6OCtfBC/aik8CJocyPcDUh4cXHICiKDBqMbURHTFhGqkvWo9ML39/fWx5XJUm+09tZooGV/u8SEEv2Jy9IktYCZLHB3D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IJvJsqlcqE4i29/f4xNWuVAMCxYgJyX6itZYLuqI8ZFckI5ygMQrgoeS/mOCE3r/XHZ6cOt5ZLvW7434Opt75b/zX+vrXxUbrgvANXLI1hEu9icT98fxlApAJBelPvkE5Iocpa2iU1J7ydQuuD+HzP4p+JZMbQwSU78eKhPMzQ4cFPsvTO2Nh+Oo+hLK0PqikcyqcwUw8HTSefc5L9nyNnPCvOAGqHpETURjgZU6UkCLGNBIhowqp6jVxnavA+Bmwq3tS0MMWc607V3vO0NkuJab87oMEBlo9j5+ImyPu+gANmJMioiWENmpH6LFqky5blDT5tIPeuiV90sSytve3bNrdjQlCXqXdm5ftUewK0HCVVsyBaQvvqlkReiqLsDCavMi/4wOs82k1B1vamKJCQDd6wYa4xBIDGBHL+hH7FXG72PAhN+Vj+uCtWI79oylKSxq+lUwdARVv16xNx+MHfyvH5K70j0nyIanylAQUddWbQK6K0NrWQqPmfZoigqOWEAnAU93p3Ky5LvRXMdOC6usy/dWy/p5lyVPer2HYWd2t1L9Euq50qCqCaFhUcTRUW1VIzUrI6KetlVlMSUwIwYJKoZIhvcNAQkVMRYEFIK2RpYoOGhJlVhZNI60I1JFWjcNMDEwITAJBgUrDgMCGgUABBRWMvkaO38E9Q4F7E1hrf+/1r4i2wQIswDDbBNBcXMCAggA
ws.jws.password=test
ws.jws.password=test

ws.wallet.light-certificate.active=true
ws.wallet.pdf-generation.active=true
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import ch.admin.bag.covidcertificate.backend.config.shared.model.ConfigResponse;
import ch.admin.bag.covidcertificate.backend.config.shared.model.Faq;
Expand Down Expand Up @@ -39,6 +40,10 @@ public static void assertIsNoForceUpdate(ConfigResponse resp) throws Exception {
assertFalse(resp.isForceUpdate());
}

public static void assertIsForceUpdate(ConfigResponse resp) throws Exception {
assertTrue(resp.isForceUpdate());
}

public static void assertInfoBox(ConfigResponse resp) throws Exception {
for (Language language : Language.values()) {
assertNotNull(resp.getInfoBox().get(language));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.admin.bag.covidcertificate.backend.config.shared;

import ch.admin.bag.covidcertificate.backend.config.shared.model.ConfigResponse;
import ch.admin.bag.covidcertificate.backend.config.shared.model.WalletConfigResponse;
import ch.admin.bag.covidcertificate.backend.config.shared.security.signature.JWSMessageConverter;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -32,22 +33,39 @@ public TestHelper(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}

public ConfigResponse toConfigResponse(
MockHttpServletResponse result, MediaType mediaType, String pathToCaPem)
public ConfigResponse internalToConfigResponse(
MockHttpServletResponse result,
MediaType mediaType,
String pathToCaPem,
Class<? extends ConfigResponse> clazz)
throws JsonProcessingException, UnsupportedEncodingException {
String responseStr = result.getContentAsString(StandardCharsets.UTF_8);
if (MediaType.APPLICATION_JSON.equalsTypeAndSubtype(mediaType)) {
return objectMapper.readValue(responseStr, ConfigResponse.class);
return objectMapper.readValue(responseStr, clazz);
} else if (JWSMessageConverter.JWS_MEDIA_TYPE.equalsTypeAndSubtype(mediaType)) {
// verify cert chain
Jws<Claims> claimsJws =
Jwts.parserBuilder()
.setSigningKeyResolver(new JwsKeyResolver(pathToCaPem))
.build()
.parseClaimsJws(responseStr);
return objectMapper.convertValue(claimsJws.getBody(), ConfigResponse.class);
return objectMapper.convertValue(claimsJws.getBody(), clazz);
} else {
throw new RuntimeException("unexpected media type: " + mediaType);
}
}

public ConfigResponse toConfigResponse(
MockHttpServletResponse result, MediaType mediaType, String pathToCaPem)
throws JsonProcessingException, UnsupportedEncodingException {
return internalToConfigResponse(result, mediaType, pathToCaPem, ConfigResponse.class);
}

public WalletConfigResponse toWalletConfigResponse(
MockHttpServletResponse result, MediaType mediaType, String pathToCaPem)
throws JsonProcessingException, UnsupportedEncodingException {
return (WalletConfigResponse)
internalToConfigResponse(
result, mediaType, pathToCaPem, WalletConfigResponse.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import ch.admin.bag.covidcertificate.backend.config.shared.model.Language;
import ch.admin.bag.covidcertificate.backend.config.shared.poeditor.Messages;
import ch.admin.bag.covidcertificate.backend.config.wallet.ws.controller.WalletConfigController;
import ch.admin.bag.covidcertificate.backend.config.wallet.ws.model.WalletConfigResponse;
import ch.admin.bag.covidcertificate.backend.config.shared.model.WalletConfigResponse;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ch.admin.bag.covidcertificate.backend.config.shared.poeditor.Messages;
import ch.admin.bag.covidcertificate.backend.config.shared.semver.Version;
import ch.admin.bag.covidcertificate.backend.config.wallet.ws.controller.WalletConfigController;
import ch.admin.bag.covidcertificate.backend.config.wallet.ws.model.WalletConfigResponse;
import ch.admin.bag.covidcertificate.backend.config.shared.model.WalletConfigResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ch.admin.bag.covidcertificate.backend.config.shared.helper.MockHelper;
import ch.admin.bag.covidcertificate.backend.config.shared.poeditor.Messages;
import ch.admin.bag.covidcertificate.backend.config.wallet.ws.controller.WalletConfigController;
import ch.admin.bag.covidcertificate.backend.config.wallet.ws.model.WalletConfigResponse;
import ch.admin.bag.covidcertificate.backend.config.shared.model.WalletConfigResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import ch.admin.bag.covidcertificate.backend.config.shared.helper.FaqHelper;
import ch.admin.bag.covidcertificate.backend.config.shared.poeditor.Messages;
import ch.admin.bag.covidcertificate.backend.config.shared.semver.Version;
import ch.admin.bag.covidcertificate.backend.config.wallet.ws.model.WalletConfigResponse;
import ch.admin.bag.covidcertificate.backend.config.shared.model.WalletConfigResponse;
import ch.ubique.openapi.docannotations.Documentation;
import org.springframework.http.CacheControl;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import static ch.admin.bag.covidcertificate.backend.config.shared.TestHelper.SECURITY_HEADERS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand All @@ -21,6 +22,7 @@
import ch.admin.bag.covidcertificate.backend.config.shared.TestHelper;
import ch.admin.bag.covidcertificate.backend.config.shared.model.ConfigResponse;
import ch.admin.bag.covidcertificate.backend.config.shared.model.Language;
import ch.admin.bag.covidcertificate.backend.config.shared.model.WalletConfigResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -112,6 +114,46 @@ public void testForUpdateNote() throws Exception {
ConfigAsserter.assertNoUpdate(resp);
}

@Test
public void testFeatureFlagsSet() throws Exception {
MockHttpServletResponse result =
mockMvc.perform(
get(BASE_URL + "/config")
.accept(acceptMediaType)
.header("accept", "application/json")
.param("osversion", "android9")
.param("appversion", "android-2.2.0")
.param("buildnr", "1622464850983"))
.andExpect(status().is2xxSuccessful())
.andReturn()
.getResponse();
WalletConfigResponse resp =
testHelper.toWalletConfigResponse(
result, acceptMediaType, TestHelper.PATH_TO_CA_PEM);
assertTrue(resp.getLightCertificateActive());
assertTrue(resp.getPdfGenerationActive());
}

@Test
public void testPdfFeatureDisabled() throws Exception {
MockHttpServletResponse result =
mockMvc.perform(
get(BASE_URL + "/config")
.accept(acceptMediaType)
.header("accept", "application/json")
.param("osversion", "android9")
.param("appversion", "android-2.1.0")
.param("buildnr", "1622464850983"))
.andExpect(status().is2xxSuccessful())
.andReturn()
.getResponse();
WalletConfigResponse resp =
testHelper.toWalletConfigResponse(
result, acceptMediaType, TestHelper.PATH_TO_CA_PEM);
assertTrue(resp.getLightCertificateActive());
assertFalse(resp.getPdfGenerationActive());
}

@Test
public void testNoForceUpdate() throws Exception {
MockHttpServletResponse result =
Expand All @@ -130,6 +172,24 @@ public void testNoForceUpdate() throws Exception {
ConfigAsserter.assertIsNoForceUpdate(resp);
}

@Test
public void testForceUpdate() throws Exception {
MockHttpServletResponse result =
mockMvc.perform(
get(BASE_URL + "/config")
.accept(acceptMediaType)
.header("accept", "application/json")
.param("osversion", "ios14.0")
.param("appversion", "ios-1.1.0")
.param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful())
.andReturn()
.getResponse();
ConfigResponse resp =
testHelper.toConfigResponse(result, acceptMediaType, TestHelper.PATH_TO_CA_PEM);
ConfigAsserter.assertIsForceUpdate(resp);
}

@Test
public void testFaqTexts() throws Exception {
MockHttpServletResponse result =
Expand Down Expand Up @@ -180,7 +240,8 @@ private void assertQuestions(ConfigResponse resp) {
assertEquals(faqEntryCount, expectedFaqEntryTitlesEn.size());

// true for those faq entries where a link is set
List<Boolean> isLinkSetList = List.of(false, false, false, true, false, false, false, false);
List<Boolean> isLinkSetList =
List.of(false, false, false, true, false, false, false, false);
assertEquals(faqEntryCount, isLinkSetList.size());

ConfigAsserter.assertFaq(
Expand Down

0 comments on commit b104639

Please sign in to comment.