Skip to content

Commit

Permalink
fix: issuanceDate fallback in vc transformer (#4159)
Browse files Browse the repository at this point in the history
  • Loading branch information
lholthof authored May 4, 2024
1 parent d77b676 commit a2e2822
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public JwtToVerifiableCredentialTransformer(Monitor monitor) {
extractDate(vc.get(EXPIRATION_DATE_PROPERTY), claims.getExpirationTime()).ifPresent(builder::expirationDate);

// issuance date
extractDate(vc.get(ISSUANCE_DATE_PROPERTY), claims.getExpirationTime()).ifPresent(builder::issuanceDate);
extractDate(vc.get(ISSUANCE_DATE_PROPERTY), claims.getIssueTime()).ifPresent(builder::issuanceDate);

builder.issuer(new Issuer(claims.getIssuer(), Map.of()));
builder.name(claims.getSubject()); // todo: is this correct?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public interface TestData {
]
}
""";

String EXAMPLE_VC_JSONLD_ISSUER_IS_URL = """
{
"@context": [
Expand Down Expand Up @@ -130,6 +131,7 @@ public interface TestData {
}
}
""";

String EXAMPLE_VP_JSONLD = """
{
"@context": [
Expand Down Expand Up @@ -176,30 +178,33 @@ public interface TestData {
}
}
""";
String EXAMPLE_JWT_VP = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImRpZDpleGFtcGxlOjB4YWJjI2" +
"tleTEifQ.eyJpc3MiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJqdGkiOiJ1cm46dXVpZDozOTc4MzQ0Zi0" +
"4NTk2LTRjM2EtYTk3OC04ZmNhYmEzOTAzYzUiLCJhdWQiOiJkaWQ6ZXhhbXBsZTo0YTU3NTQ2OTczNDM2ZjZmNmM0YTRhNTc1NzMiLCJuYmY" +
"iOjE1NDE0OTM3MjQsImlhdCI6MTU0MTQ5MzcyNCwiZXhwIjoxNTczMDI5NzIzLCJub25jZSI6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ZFVPAgpwFgIcIMAVB7uyOVR0P8PA3JdFQg""";
7EbH9P_HKksL5jVPzLNMHLE68Z907J22n3cthZFVPAgpwFgIcIMAVB7uyOVR0P8PA3JdFQg
""";

String EXAMPLE_JWT_VP_SINGLE_VC = """
eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImRpZDpleGFtcGxlOjB4YWJjI2tleTEifQ.eyJpc3MiOiJkaWQ6ZXhhbXBsZTpl
Expand Down Expand Up @@ -289,4 +295,23 @@ public interface TestData {
lOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.YQKQUu_zreDs69AZ8YqpMGHLl9V_tWH4N
S9P9l67J1wWHf0QCyt5hyuA8ckM4seV-1TRbeiHwdJ3VRkDMcwFcg
""";

String EXAMPLE_JWT_VC_NO_DATES = """
eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImRpZDpleGFtcGxlOmFiZmUxM2Y3MTI
xMjA0MzFjMjc2ZTEyZWNhYiNrZXlzLTEifQ.eyJzdWIiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzE
yZWJjNmYxYzI3NmUxMmVjMjEiLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbH
MvMzczMiIsImlzcyI6Imh0dHBzOi8vZXhhbXBsZS5jb20va2V5cy9mb28uandrIiwibmJmIjoxN
TQxNDkzNzI0LCJpYXQiOjE1NDE0OTM3MjQsImV4cCI6MTU3MzAyOTcyMywibm9uY2UiOiI2NjAh
NjM0NUZTZXIiLCJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmV
kZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbG
VzL3YxIl0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiLCJVbml2ZXJzaXR5RGVncmVlQ
3JlZGVudGlhbCJdLCJjcmVkZW50aWFsU3ViamVjdCI6eyJkZWdyZWUiOnsidHlwZSI6IkJhY2hl
bG9yRGVncmVlIiwibmFtZSI6IjxzcGFuIGxhbmc9J2ZyLUNBJz5CYWNjYWxhdXLDqWF0IGVuIG1
1c2lxdWVzIG51bcOpcmlxdWVzPC9zcGFuPiJ9fX19.KLJo5GAyBND3LDTn9H7FQokEsUEi8jKwX
hGvoN3JtRa51xrNDgXDb0cq1UTYB-rK4Ft9YVmR1NI_ZOF8oGc_7wAp8PHbF2HaWodQIoOBxxT-
4WNqAxft7ET6lkH-4S6Ux3rSGAmczMohEEf8eCeN-jC8WekdPl6zKZQj0YPB1rx6X0-xlFBs7cl
6Wt8rfBP_tZ9YgVWrQmUWypSioc0MUyiphmyEbLZagTyPlUyflGlEdqrZAv6eSe6RtxJy6M1-lD
7a5HTzanYTWBPAUHDZGyGKXdJw-W_x0IWChBzI8t3kpG253fg6V3tPgHeKXE94fz_QpYfg--7kL
syBAfQGbg
""";
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void transform() throws JsonProcessingException {
assertThat(vc.getName()).isNotNull();
assertThat(vc.getCredentialStatus()).isNotNull();
assertThat(vc.getIssuer()).isNotNull().extracting(Issuer::id).isEqualTo("https://university.example/issuers/565049");
assertThat(vc.getIssuanceDate().isBefore(vc.getExpirationDate())).isTrue();
verify(context, never()).reportProblem(anyString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.transform.spi.TransformerContext;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.iam.identitytrust.transform.TestData.EXAMPLE_JWT_VC;
import static org.eclipse.edc.iam.identitytrust.transform.TestData.EXAMPLE_JWT_VC_NO_DATES;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoInteractions;

Expand All @@ -37,6 +39,20 @@ void transform_success() {
assertThat(vc.getCredentialStatus()).isNotNull();
assertThat(vc.getCredentialSubject()).doesNotContainNull().isNotEmpty();
assertThat(vc.getCredentialSubject().stream().findFirst().orElseThrow().getId()).isNotNull();
assertThat(vc.getIssuanceDate()).isNotNull();

verifyNoInteractions(context);
}

@Test
@DisplayName("VC claims do not contain dates, but JWT 'iat' and 'exp' are used as fallbacks")
void transform_credentialHasNoDates() {
var vc = transformer.transform(EXAMPLE_JWT_VC_NO_DATES, context);

assertThat(vc).isNotNull();
assertThat(vc.getIssuanceDate()).isNotNull();
assertThat(vc.getExpirationDate()).isNotNull();
assertThat(vc.getIssuanceDate()).isBefore(vc.getExpirationDate());

verifyNoInteractions(context);
}
Expand Down

0 comments on commit a2e2822

Please sign in to comment.