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

Commit

Permalink
Merge pull request #17 from admin-ch/feature/sdk-update
Browse files Browse the repository at this point in the history
update SDK to 2.0.3 (including test cases)
  • Loading branch information
gstoehld authored Nov 18, 2021
2 parents 6c8e312 + cde59b8 commit 4fd635f
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<dependency>
<groupId>ch.admin.bag.covidcertificate</groupId>
<artifactId>sdk-core</artifactId>
<version>1.1.3-sero</version>
<version>2.0.3</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Rule> rules;
@NotNull private RuleValueSets valueSets;
@NotNull private Map<String, String[]> valueSets;
@NotNull private Long validDuration;
@NotNull private List<DisplayRule> displayRules;

public List<Rule> getRules() {
return rules;
Expand All @@ -21,14 +24,6 @@ public void setRules(List<Rule> rules) {
this.rules = rules;
}

public RuleValueSets getValueSets() {
return valueSets;
}

public void setValueSets(RuleValueSets valueSets) {
this.valueSets = valueSets;
}

public Long getValidDuration() {
return validDuration;
}
Expand All @@ -37,44 +32,185 @@ public void setValidDuration(Long validDuration) {
this.validDuration = validDuration;
}

public List<DisplayRule> getDisplayRules() {
return displayRules;
}

public void setDisplayRules(
List<DisplayRule> displayRules) {
this.displayRules = displayRules;
}

public Map<String, String[]> getValueSets() {
return valueSets;
}

public void setValueSets(Map<String, String[]> 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<String> affectedFields;
@NotNull private String certificateType;
@NotNull private String country;
@NotNull private List<ch.admin.bag.covidcertificate.sdk.core.models.trustlist.Description> 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<String> getAffectedFields() {
return affectedFields;
}

public void setId(String id) {
this.id = id;
public void setAffectedFields(List<String> 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<ch.admin.bag.covidcertificate.sdk.core.models.trustlist.Description> getDescription() {
return description;
}

public void setDescription(String description) {
public void setDescription(
List<ch.admin.bag.covidcertificate.sdk.core.models.trustlist.Description> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 $
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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:}")
Expand Down Expand Up @@ -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<DisplayRule> 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<Void> getRequestEntity(String endpoint, Map<String, String> params)
Expand Down Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -118,4 +119,4 @@ void verificationTest() {
instanceof CheckRevocationState.SUCCESS);
;
}
}
}
Loading

0 comments on commit 4fd635f

Please sign in to comment.