Skip to content

Commit

Permalink
Uppercase Participant Codes
Browse files Browse the repository at this point in the history
  • Loading branch information
f11h committed May 17, 2024
1 parent 19d10b6 commit e4ec390
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ public void job() {
domains.forEach(
domain -> countries.forEach(
country -> didSpecifications.add(new DidSpecification(
List.of(domain, getCountryAsLowerCaseAlpha3(country)),
List.of(domain, getParticipantCode(country)),
() -> signerInformationService.getCertificatesByCountryDomain(country, domain),
trustedIssuerService::getAllDid)
)));

// Add all Domain independent and country specific DID
countries.forEach(
country -> didSpecifications.add(new DidSpecification(
List.of(WILDCARD_CHAR, getCountryAsLowerCaseAlpha3(country)),
List.of(WILDCARD_CHAR, getParticipantCode(country)),
() -> signerInformationService.getCertificatesByCountry(country),
trustedIssuerService::getAllDid)));

Expand All @@ -176,7 +176,7 @@ public void job() {
domain -> countries.forEach(
country -> groups.forEach(
group -> didSpecifications.add(new DidSpecification(
List.of(domain, getCountryAsLowerCaseAlpha3(country), group),
List.of(domain, getParticipantCode(country), group),
() -> signerInformationService.getCertificatesByDomainParticipantGroup(domain, country, group),
trustedIssuerService::getAllDid)))));

Expand Down Expand Up @@ -276,21 +276,21 @@ private String generateTrustList(DidSpecification specification) {
}
}

private String getCountryAsLowerCaseAlpha3(String country) {
private String getParticipantCode(String country) {

if (country == null || country.length() != 2 && country.length() != 3) {
return null;
} else if (country.length() == 3) {
return country;
return country.toUpperCase();
}

return configProperties.getDid().getVirtualCountries().computeIfAbsent(country, (c) -> {
try {
return new Locale("en", c).getISO3Country().toLowerCase();
return new Locale("en", c).getISO3Country().toUpperCase();
} catch (MissingResourceException e) {
log.error("Country Code to alpha 3 conversion issue for country {} : {}",
c, e.getMessage());
return c;
return c.toUpperCase();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

package tng.trustnetwork.keydistribution.service;

import static org.mockito.ArgumentMatchers.anySet;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doNothing;

Expand Down Expand Up @@ -218,12 +217,12 @@ void testTrustList(boolean isEcAlgorithm) throws Exception {
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc#" + URLEncoder.encode(certCscaEuKid, StandardCharsets.UTF_8)),
certCscaEuKid, certCscaEu, null, "xeu", "did:web:abc");
break;
case "did:web:abc:DCC:xeu:DSC":
Assertions.assertEquals("did:web:abc:DCC:xeu:DSC", parsed.getController());
case "did:web:abc:DCC:XEU:DSC":
Assertions.assertEquals("did:web:abc:DCC:XEU:DSC", parsed.getController());
Assertions.assertEquals(4, parsed.getVerificationMethod().size());

assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:xeu:DSC#" + URLEncoder.encode(certDscEuKid, StandardCharsets.UTF_8)),
certDscEuKid, certDscEu, null, "xeu", "did:web:abc:DCC:xeu:DSC");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:XEU:DSC#" + URLEncoder.encode(certDscEuKid, StandardCharsets.UTF_8)),
certDscEuKid, certDscEu, null, "xeu", "did:web:abc:DCC:XEU:DSC");
break;
case "did:web:abc:DCC":
Assertions.assertEquals("did:web:abc:DCC", parsed.getController());
Expand All @@ -234,62 +233,62 @@ void testTrustList(boolean isEcAlgorithm) throws Exception {
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC#" + URLEncoder.encode(certDscEuKid, StandardCharsets.UTF_8)),
certDscEuKid, certDscEu, null, "xeu", "did:web:abc:DCC");
break;
case "did:web:abc:-:xeu":
Assertions.assertEquals("did:web:abc:-:xeu", parsed.getController());
case "did:web:abc:-:XEU":
Assertions.assertEquals("did:web:abc:-:XEU", parsed.getController());
Assertions.assertEquals(5, parsed.getVerificationMethod().size());

assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:-:xeu#" + URLEncoder.encode(certCscaEuKid, StandardCharsets.UTF_8)),
certCscaEuKid, certCscaEu, null, "xeu", "did:web:abc:-:xeu");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:-:xeu#" + URLEncoder.encode(certDscEuKid, StandardCharsets.UTF_8)),
certDscEuKid, certDscEu, null, "xeu", "did:web:abc:-:xeu");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:-:XEU#" + URLEncoder.encode(certCscaEuKid, StandardCharsets.UTF_8)),
certCscaEuKid, certCscaEu, null, "xeu", "did:web:abc:-:XEU");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:-:XEU#" + URLEncoder.encode(certDscEuKid, StandardCharsets.UTF_8)),
certDscEuKid, certDscEu, null, "xeu", "did:web:abc:-:XEU");
break;
case "did:web:abc:-:deu":
Assertions.assertEquals("did:web:abc:-:deu", parsed.getController());
case "did:web:abc:-:DEU":
Assertions.assertEquals("did:web:abc:-:DEU", parsed.getController());
Assertions.assertEquals(5, parsed.getVerificationMethod().size());

assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:-:deu#" + URLEncoder.encode(certDscDeKid, StandardCharsets.UTF_8)),
certDscDeKid, certDscDe, null, "deu","did:web:abc:-:deu");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:-:deu#" + URLEncoder.encode(certCscaDeKid, StandardCharsets.UTF_8)),
certCscaDeKid, certCscaDe, null, "deu","did:web:abc:-:deu");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:-:DEU#" + URLEncoder.encode(certDscDeKid, StandardCharsets.UTF_8)),
certDscDeKid, certDscDe, null, "deu","did:web:abc:-:DEU");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:-:DEU#" + URLEncoder.encode(certCscaDeKid, StandardCharsets.UTF_8)),
certCscaDeKid, certCscaDe, null, "deu","did:web:abc:-:DEU");
break;
case "did:web:abc:DCC:xeu:CSCA":
Assertions.assertEquals("did:web:abc:DCC:xeu:CSCA", parsed.getController());
case "did:web:abc:DCC:XEU:CSCA":
Assertions.assertEquals("did:web:abc:DCC:XEU:CSCA", parsed.getController());
Assertions.assertEquals(4, parsed.getVerificationMethod().size());

assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:xeu:CSCA#" + URLEncoder.encode(certCscaEuKid, StandardCharsets.UTF_8)),
certCscaEuKid, certCscaEu, null, "xeu", "did:web:abc:DCC:xeu:CSCA");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:XEU:CSCA#" + URLEncoder.encode(certCscaEuKid, StandardCharsets.UTF_8)),
certCscaEuKid, certCscaEu, null, "xeu", "did:web:abc:DCC:XEU:CSCA");
break;
case "did:web:abc:DCC:deu:DSC":
Assertions.assertEquals("did:web:abc:DCC:deu:DSC", parsed.getController());
case "did:web:abc:DCC:DEU:DSC":
Assertions.assertEquals("did:web:abc:DCC:DEU:DSC", parsed.getController());
Assertions.assertEquals(4, parsed.getVerificationMethod().size());

assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:deu:DSC#" + URLEncoder.encode(certDscDeKid, StandardCharsets.UTF_8)),
certDscDeKid, certDscDe, null, "deu", "did:web:abc:DCC:deu:DSC");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:DEU:DSC#" + URLEncoder.encode(certDscDeKid, StandardCharsets.UTF_8)),
certDscDeKid, certDscDe, null, "deu", "did:web:abc:DCC:DEU:DSC");
break;
case "did:web:abc:DCC:deu:CSCA":
Assertions.assertEquals("did:web:abc:DCC:deu:CSCA", parsed.getController());
case "did:web:abc:DCC:DEU:CSCA":
Assertions.assertEquals("did:web:abc:DCC:DEU:CSCA", parsed.getController());
Assertions.assertEquals(4, parsed.getVerificationMethod().size());

assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:deu:CSCA#" + URLEncoder.encode(certCscaDeKid, StandardCharsets.UTF_8)),
certCscaDeKid, certCscaDe, null, "deu", "did:web:abc:DCC:deu:CSCA");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:DEU:CSCA#" + URLEncoder.encode(certCscaDeKid, StandardCharsets.UTF_8)),
certCscaDeKid, certCscaDe, null, "deu", "did:web:abc:DCC:DEU:CSCA");
break;
case "did:web:abc:DCC:deu":
Assertions.assertEquals("did:web:abc:DCC:deu", parsed.getController());
case "did:web:abc:DCC:DEU":
Assertions.assertEquals("did:web:abc:DCC:DEU", parsed.getController());
Assertions.assertEquals(5, parsed.getVerificationMethod().size());

assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:deu#" + URLEncoder.encode(certDscDeKid, StandardCharsets.UTF_8)),
certDscDeKid, certDscDe, null, "deu", "did:web:abc:DCC:deu");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:deu#" + URLEncoder.encode(certCscaDeKid, StandardCharsets.UTF_8)),
certCscaDeKid, certCscaDe, null, "deu", "did:web:abc:DCC:deu");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:DEU#" + URLEncoder.encode(certDscDeKid, StandardCharsets.UTF_8)),
certDscDeKid, certDscDe, null, "deu", "did:web:abc:DCC:DEU");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:DEU#" + URLEncoder.encode(certCscaDeKid, StandardCharsets.UTF_8)),
certCscaDeKid, certCscaDe, null, "deu", "did:web:abc:DCC:DEU");
break;
case "did:web:abc:DCC:xeu":
Assertions.assertEquals("did:web:abc:DCC:xeu", parsed.getController());
case "did:web:abc:DCC:XEU":
Assertions.assertEquals("did:web:abc:DCC:XEU", parsed.getController());
Assertions.assertEquals(5, parsed.getVerificationMethod().size());

assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:xeu#" + URLEncoder.encode(certDscEuKid, StandardCharsets.UTF_8)),
certDscEuKid, certDscEu, null, "xeu", "did:web:abc:DCC:xeu");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:xeu#" + URLEncoder.encode(certCscaEuKid, StandardCharsets.UTF_8)),
certCscaEuKid, certCscaEu, null, "xeu", "did:web:abc:DCC:xeu");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:XEU#" + URLEncoder.encode(certDscEuKid, StandardCharsets.UTF_8)),
certDscEuKid, certDscEu, null, "xeu", "did:web:abc:DCC:XEU");
assertVerificationMethod(getVerificationMethodByKid(parsed.getVerificationMethod(),"did:web:abc:DCC:XEU#" + URLEncoder.encode(certCscaEuKid, StandardCharsets.UTF_8)),
certCscaEuKid, certCscaEu, null, "xeu", "did:web:abc:DCC:XEU");
break;
default:
Assertions.fail("Unexpected Document in DID Collection! (" + parsed.getId() + ")");
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dgc:
"[https://www.w3.org/ns/did/v1]": did_v1.json
"[https://w3id.org/security/suites/jws-2020/v1]": jws-2020_v1.json
virtualCountries:
EU: xeu
EU: XEU

universal:
resolver: "https://dev.uniresolver.io/1.0/identifiers"
Expand Down

0 comments on commit e4ec390

Please sign in to comment.