From cde59b8600ab04a7827831bae39a5bd9688f929f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gst=C3=B6hl?= Date: Tue, 16 Nov 2021 16:20:47 +0100 Subject: [PATCH] update SDK to 2.0.3 (including test cases) --- .../pom.xml | 2 +- .../check/ws/model/IntermediateRuleSet.java | 192 +++++++++++++++--- .../check/ws/verification/TestData.kt | 13 +- .../ws/verification/VerificationService.java | 35 +++- .../check/ws/util/LibWrapperTest.java | 5 +- .../ws/util/VerificationServiceTest.java | 52 +++-- 6 files changed, 236 insertions(+), 63 deletions(-) diff --git a/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/pom.xml b/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/pom.xml index b15b233..af18b2e 100644 --- a/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/pom.xml +++ b/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/pom.xml @@ -74,7 +74,7 @@ ch.admin.bag.covidcertificate sdk-core - 1.1.3-sero + 2.0.3 diff --git a/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/model/IntermediateRuleSet.java b/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/model/IntermediateRuleSet.java index c8ebc99..4bac00e 100644 --- a/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/model/IntermediateRuleSet.java +++ b/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/model/IntermediateRuleSet.java @@ -1,17 +1,20 @@ package ch.admin.bag.covidcertificate.backend.verification.check.ws.model; -import ch.admin.bag.covidcertificate.sdk.core.models.trustlist.RuleValueSets; +//import ch.admin.bag.covidcertificate.sdk.core.models.trustlist.RuleValueSets; +import ch.admin.bag.covidcertificate.sdk.core.models.trustlist.Description; import com.fasterxml.jackson.annotation.JsonRawValue; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; +import java.util.Map; import javax.validation.constraints.NotNull; public class IntermediateRuleSet { @NotNull private List rules; - @NotNull private RuleValueSets valueSets; + @NotNull private Map valueSets; @NotNull private Long validDuration; + @NotNull private List displayRules; public List getRules() { return rules; @@ -21,14 +24,6 @@ public void setRules(List rules) { this.rules = rules; } - public RuleValueSets getValueSets() { - return valueSets; - } - - public void setValueSets(RuleValueSets valueSets) { - this.valueSets = valueSets; - } - public Long getValidDuration() { return validDuration; } @@ -37,44 +32,185 @@ public void setValidDuration(Long validDuration) { this.validDuration = validDuration; } + public List getDisplayRules() { + return displayRules; + } + + public void setDisplayRules( + List displayRules) { + this.displayRules = displayRules; + } + + public Map getValueSets() { + return valueSets; + } + + public void setValueSets(Map valueSets) { + this.valueSets = valueSets; + } + public static class Rule { + private static final ObjectMapper objectMapper = new ObjectMapper(); - @NotNull private String id; - private String businessDescription; - @NotNull private String description; - @NotNull private String inputParameter; + @NotNull private List affectedFields; + @NotNull private String certificateType; + @NotNull private String country; + @NotNull private List description; + @NotNull private String engine; + @NotNull private String engineVersion; + @NotNull private String identifier; @NotNull @JsonRawValue private Object logic; + @NotNull private String schemaVersion; + @NotNull private String type; - public String getId() { - return id; + public List getAffectedFields() { + return affectedFields; } - public void setId(String id) { - this.id = id; + public void setAffectedFields(List affectedFields) { + this.affectedFields = affectedFields; + } + + public String getCertificateType() { + return certificateType; + } + + public void setCertificateType(String certificateType) { + this.certificateType = certificateType; } - public String getBusinessDescription() { - return businessDescription; + public String getCountry() { + return country; } - public void setBusinessDescription(String businessDescription) { - this.businessDescription = businessDescription; + public void setCountry(String country) { + this.country = country; } - public String getDescription() { + public List getDescription() { return description; } - public void setDescription(String description) { + public void setDescription( + List description) { this.description = description; } - public String getInputParameter() { - return inputParameter; + public String getEngine() { + return engine; + } + + public void setEngine(String engine) { + this.engine = engine; + } + + public String getEngineVersion() { + return engineVersion; + } + + public void setEngineVersion(String engineVersion) { + this.engineVersion = engineVersion; + } + + public String getSchemaVersion() { + return schemaVersion; + } + + public void setSchemaVersion(String schemaVersion) { + this.schemaVersion = schemaVersion; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getValidFrom() { + return validFrom; + } + + public void setValidFrom(String validFrom) { + this.validFrom = validFrom; + } + + public String getValidTo() { + return validTo; } - public void setInputParameter(String inputParameter) { - this.inputParameter = inputParameter; + public void setValidTo(String validTo) { + this.validTo = validTo; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + @NotNull private String validFrom; + @NotNull private String validTo; + @NotNull private String version; + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + + @JsonRawValue + public String getLogic() { + try { + return logic == null ? null : objectMapper.writeValueAsString(logic); + } catch (JsonProcessingException e) { + return null; + } + } + + public void setLogic(Object logic) { + this.logic = logic; + } + + public static class Description{ + private String desc; + private String lang; + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + public String getLang() { + return lang; + } + + public void setLang(String lang) { + this.lang = lang; + } + } + } + + public static class DisplayRule { + private static final ObjectMapper objectMapper = new ObjectMapper(); + @NotNull private String id; + @NotNull @JsonRawValue private Object logic; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; } @JsonRawValue diff --git a/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/verification/TestData.kt b/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/verification/TestData.kt index ef488fd..9d13fd0 100644 --- a/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/verification/TestData.kt +++ b/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/verification/TestData.kt @@ -25,18 +25,11 @@ object TestData { RevokedCertificates(revokedKeyIds, Long.MAX_VALUE), ruleSet ?: RuleSet( emptyList(), - RuleValueSets( - null, - null, - null, - null, - null, - null, - AcceptanceCriterias(0, 0, 0, 0, 0, 0) - ), + emptyList(), + emptyMap(), 0L + ) ) - ) } // Note that this String (taken directly from a QR code) has some \ that escape $ diff --git a/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/verification/VerificationService.java b/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/verification/VerificationService.java index 5a5c4b6..20e5cb7 100644 --- a/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/verification/VerificationService.java +++ b/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/verification/VerificationService.java @@ -3,6 +3,7 @@ import ch.admin.bag.covidcertificate.backend.verification.check.model.HCertPayload; import ch.admin.bag.covidcertificate.backend.verification.check.model.cert.CertFormat; import ch.admin.bag.covidcertificate.backend.verification.check.ws.model.DecodingException; +// import ch.admin.bag.covidcertificate.backend.verification.check.ws.model.IntermediateRuleSet; import ch.admin.bag.covidcertificate.backend.verification.check.ws.model.IntermediateRuleSet; import ch.admin.bag.covidcertificate.backend.verification.check.ws.model.TrustListConfig; import ch.admin.bag.covidcertificate.sdk.core.decoder.CertificateDecoder; @@ -14,6 +15,7 @@ import ch.admin.bag.covidcertificate.sdk.core.models.state.VerificationState; import ch.admin.bag.covidcertificate.sdk.core.models.state.VerificationState.INVALID; import ch.admin.bag.covidcertificate.sdk.core.models.state.VerificationState.SUCCESS; +import ch.admin.bag.covidcertificate.sdk.core.models.trustlist.DisplayRule; import ch.admin.bag.covidcertificate.sdk.core.models.trustlist.Jwk; import ch.admin.bag.covidcertificate.sdk.core.models.trustlist.Jwks; import ch.admin.bag.covidcertificate.sdk.core.models.trustlist.RevokedCertificates; @@ -70,7 +72,7 @@ public class VerificationService { @Value("${verifier.revocation.endpoint:/trust/v2/revocationList}") private String revocationEndpoint; - @Value("${verifier.rules.endpoint:/trust/v1/verificationRules}") + @Value("${verifier.rules.endpoint:/trust/v2/verificationRules}") private String rulesEndpoint; @Value("${verifier.api-key:}") @@ -210,15 +212,32 @@ private RuleSet getNationalRules() throws URISyntaxException { .map( rule -> new Rule( - rule.getId(), - rule.getBusinessDescription(), + rule.getAffectedFields(), + rule.getCertificateType(), + rule.getCountry(), rule.getDescription(), - rule.getInputParameter(), - rule.getLogic())) + rule.getEngine(), + rule.getEngineVersion(), + rule.getIdentifier(), + rule.getLogic(), + rule.getSchemaVersion(), + rule.getType(), + rule.getValidFrom(), + rule.getValidTo(), + rule.getVersion())) .collect(Collectors.toList()); + List displayRules = + intermediateRuleSet.getDisplayRules().stream() + .map(rule -> new DisplayRule(rule.getId(), rule.getLogic())) + .collect(Collectors.toList()); + logger.info("downloaded {} rules", rules.size()); + return new RuleSet( - rules, intermediateRuleSet.getValueSets(), intermediateRuleSet.getValidDuration()); + displayRules, + rules, + intermediateRuleSet.getValueSets(), + intermediateRuleSet.getValidDuration()); } private RequestEntity getRequestEntity(String endpoint, Map params) @@ -250,7 +269,9 @@ public CertificateHolder decodeHCert(HCertPayload hCertPayload) { if (decodeState instanceof DecodeState.SUCCESS) { return ((DecodeState.SUCCESS) decodeState).getCertificateHolder(); } else { - throw new DecodingException("Couldn't decode hcert: " + ((DecodeState.ERROR) decodeState).getError().getMessage()); + throw new DecodingException( + "Couldn't decode hcert: " + + ((DecodeState.ERROR) decodeState).getError().getMessage()); } } diff --git a/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/util/LibWrapperTest.java b/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/util/LibWrapperTest.java index 16c2505..ed99377 100644 --- a/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/util/LibWrapperTest.java +++ b/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/util/LibWrapperTest.java @@ -50,7 +50,8 @@ class LibWrapperTest { private static final Logger logger = LoggerFactory.getLogger(LibWrapperTest.class); private static CertificateVerifier certificateVerifier = new CertificateVerifier(); - @Autowired ObjectMapper objectMapper; + @Autowired + ObjectMapper objectMapper; @Test void decodeTest() { @@ -118,4 +119,4 @@ void verificationTest() { instanceof CheckRevocationState.SUCCESS); ; } -} +} \ No newline at end of file diff --git a/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/util/VerificationServiceTest.java b/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/util/VerificationServiceTest.java index f7c76dd..b3bcca5 100644 --- a/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/util/VerificationServiceTest.java +++ b/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/util/VerificationServiceTest.java @@ -2,7 +2,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; +//import ch.admin.bag.covidcertificate.backend.verification.check.ws.model.IntermediateRuleSet; import ch.admin.bag.covidcertificate.backend.verification.check.ws.model.IntermediateRuleSet; +import ch.admin.bag.covidcertificate.sdk.core.models.trustlist.DisplayRule; import ch.admin.bag.covidcertificate.sdk.core.models.trustlist.Jwks; import ch.admin.bag.covidcertificate.sdk.core.models.trustlist.Rule; import ch.admin.bag.covidcertificate.sdk.core.models.trustlist.RuleSet; @@ -18,6 +20,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -40,7 +43,7 @@ class VerificationServiceTest { private static final HttpClient httpClient = HttpClient.newHttpClient(); private static final String verifierBaseUrl = "verifier.test.ch"; private static final String dscEndpoint = "/trust/v1/keys/updates"; - private static final String rulesEndpoint = "/trust/v1/verificationRules"; + private static final String rulesEndpoint = "/trust/v2/verificationRules"; private static final String revocationEndpoint = "/trust/v2/revocationList"; private static Map etagMap = new HashMap<>(); @Autowired ObjectMapper objectMapper; @@ -70,20 +73,39 @@ void getRulesTest() throws URISyntaxException, IOException, InterruptedException if (response.isBlank()) { logger.info("ETag hasn't changed - No need to update"); } else { - final var rules = objectMapper.readValue(response, IntermediateRuleSet.class); - assertNotNull(rules); - List rulesList = new ArrayList<>(); - for (var rule : rules.getRules()) { - rulesList.add( - new Rule( - rule.getId(), - rule.getBusinessDescription(), - rule.getDescription(), - rule.getInputParameter(), - rule.getLogic())); - } - final var ruleSet = - new RuleSet(rulesList, rules.getValueSets(), rules.getValidDuration()); + final var intermediateRuleSet = objectMapper.readValue(response, IntermediateRuleSet.class); + assertNotNull(intermediateRuleSet); + List rules = + intermediateRuleSet.getRules().stream() + .map( + rule -> + new Rule( + rule.getAffectedFields(), + rule.getCertificateType(), + rule.getCountry(), + rule.getDescription(), + rule.getEngine(), + rule.getEngineVersion(), + rule.getIdentifier(), + rule.getLogic(), + rule.getSchemaVersion(), + rule.getType(), + rule.getValidFrom(), + rule.getValidTo(), + rule.getVersion())) + .collect(Collectors.toList()); + List displayRules = + intermediateRuleSet.getDisplayRules().stream() + .map(rule -> new DisplayRule(rule.getId(), rule.getLogic())) + .collect(Collectors.toList()); + + logger.info("downloaded {} rules", rules.size()); + + final var ruleSet = new RuleSet( + displayRules, + rules, + intermediateRuleSet.getValueSets(), + intermediateRuleSet.getValidDuration()); assertNotNull(ruleSet); } }