From b1046396fdc70e586d04a68a46d2232d97968b7c Mon Sep 17 00:00:00 2001 From: Felix Haller Date: Tue, 20 Jul 2021 09:42:22 +0200 Subject: [PATCH] add feature flag and force update unit tests --- .../shared}/model/WalletConfigResponse.java | 5 +- .../resources/application-local.properties | 5 +- .../backend/config/shared/ConfigAsserter.java | 5 ++ .../backend/config/shared/TestHelper.java | 26 ++++++-- .../ws/config/mock/MockFaqLinkConfig.java | 2 +- .../ws/config/mock/MockForceUpdateConfig.java | 2 +- .../ws/config/mock/MockInfoBoxConfig.java | 2 +- .../ws/controller/WalletConfigController.java | 2 +- .../config/wallet/ws/BaseControllerTest.java | 63 ++++++++++++++++++- 9 files changed, 98 insertions(+), 14 deletions(-) rename ch-covidcertificate-backend-config/{ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws => ch-covidcertificate-backend-config-shared/src/main/java/ch/admin/bag/covidcertificate/backend/config/shared}/model/WalletConfigResponse.java (84%) diff --git a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/model/WalletConfigResponse.java b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-shared/src/main/java/ch/admin/bag/covidcertificate/backend/config/shared/model/WalletConfigResponse.java similarity index 84% rename from ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/model/WalletConfigResponse.java rename to ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-shared/src/main/java/ch/admin/bag/covidcertificate/backend/config/shared/model/WalletConfigResponse.java index 05113ee..3594820 100644 --- a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/model/WalletConfigResponse.java +++ b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-shared/src/main/java/ch/admin/bag/covidcertificate/backend/config/shared/model/WalletConfigResponse.java @@ -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; diff --git a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-shared/src/main/resources/application-local.properties b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-shared/src/main/resources/application-local.properties index ed51776..f5a566c 100644 --- a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-shared/src/main/resources/application-local.properties +++ b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-shared/src/main/resources/application-local.properties @@ -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/fWx5XJU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VXnX18naxtXcSB1QhqOd9Seic3ml5BiB5IJvJsqlcqE4i29/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 \ No newline at end of file +ws.jws.password=test + +ws.wallet.light-certificate.active=true +ws.wallet.pdf-generation.active=true \ No newline at end of file diff --git a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-shared/src/test/java/ch/admin/bag/covidcertificate/backend/config/shared/ConfigAsserter.java b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-shared/src/test/java/ch/admin/bag/covidcertificate/backend/config/shared/ConfigAsserter.java index e92f806..801965b 100644 --- a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-shared/src/test/java/ch/admin/bag/covidcertificate/backend/config/shared/ConfigAsserter.java +++ b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-shared/src/test/java/ch/admin/bag/covidcertificate/backend/config/shared/ConfigAsserter.java @@ -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; @@ -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)); diff --git a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-shared/src/test/java/ch/admin/bag/covidcertificate/backend/config/shared/TestHelper.java b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-shared/src/test/java/ch/admin/bag/covidcertificate/backend/config/shared/TestHelper.java index 5842f6b..2cd71f1 100644 --- a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-shared/src/test/java/ch/admin/bag/covidcertificate/backend/config/shared/TestHelper.java +++ b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-shared/src/test/java/ch/admin/bag/covidcertificate/backend/config/shared/TestHelper.java @@ -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; @@ -32,12 +33,15 @@ 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 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 claimsJws = @@ -45,9 +49,23 @@ public ConfigResponse toConfigResponse( .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); + } } diff --git a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/config/mock/MockFaqLinkConfig.java b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/config/mock/MockFaqLinkConfig.java index 94a20c6..7a4ef8c 100644 --- a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/config/mock/MockFaqLinkConfig.java +++ b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/config/mock/MockFaqLinkConfig.java @@ -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; diff --git a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/config/mock/MockForceUpdateConfig.java b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/config/mock/MockForceUpdateConfig.java index 390f635..89ca17a 100644 --- a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/config/mock/MockForceUpdateConfig.java +++ b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/config/mock/MockForceUpdateConfig.java @@ -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; diff --git a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/config/mock/MockInfoBoxConfig.java b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/config/mock/MockInfoBoxConfig.java index 4f9dc06..49989a3 100644 --- a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/config/mock/MockInfoBoxConfig.java +++ b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/config/mock/MockInfoBoxConfig.java @@ -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; diff --git a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/controller/WalletConfigController.java b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/controller/WalletConfigController.java index 85282d2..bdaf401 100644 --- a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/controller/WalletConfigController.java +++ b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/main/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/controller/WalletConfigController.java @@ -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; diff --git a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/test/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/BaseControllerTest.java b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/test/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/BaseControllerTest.java index 2842c76..d6421e9 100644 --- a/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/test/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/BaseControllerTest.java +++ b/ch-covidcertificate-backend-config/ch-covidcertificate-backend-config-wallet-ws/src/test/java/ch/admin/bag/covidcertificate/backend/config/wallet/ws/BaseControllerTest.java @@ -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; @@ -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; @@ -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 = @@ -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 = @@ -180,7 +240,8 @@ private void assertQuestions(ConfigResponse resp) { assertEquals(faqEntryCount, expectedFaqEntryTitlesEn.size()); // true for those faq entries where a link is set - List isLinkSetList = List.of(false, false, false, true, false, false, false, false); + List isLinkSetList = + List.of(false, false, false, true, false, false, false, false); assertEquals(faqEntryCount, isLinkSetList.size()); ConfigAsserter.assertFaq(