Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make equality comparison of VCs based on ID #387

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
maven/mavencentral/com.apicatalog/carbon-did/0.3.0, Apache-2.0, approved, clearlydefined

Check warning on line 1 in DEPENDENCIES

View workflow job for this annotation

GitHub Actions / check / Dash-Verify-Licenses

Restricted Dependencies found

Some dependencies are marked 'restricted' - please review them
maven/mavencentral/com.apicatalog/copper-multibase/0.5.0, Apache-2.0, approved, #14501
maven/mavencentral/com.apicatalog/copper-multicodec/0.1.1, Apache-2.0, approved, #14500
maven/mavencentral/com.apicatalog/iron-verifiable-credentials/0.14.0, Apache-2.0, approved, clearlydefined
Expand Down Expand Up @@ -350,17 +350,20 @@
maven/mavencentral/org.junit-pioneer/junit-pioneer/2.2.0, EPL-2.0, approved, #11857
maven/mavencentral/org.junit.jupiter/junit-jupiter-api/5.10.1, EPL-2.0, approved, #9714
maven/mavencentral/org.junit.jupiter/junit-jupiter-api/5.10.2, EPL-2.0, approved, #9714
maven/mavencentral/org.junit.jupiter/junit-jupiter-api/5.10.3, EPL-2.0, approved, #9714
maven/mavencentral/org.junit.jupiter/junit-jupiter-engine/5.10.1, EPL-2.0, approved, #9711
maven/mavencentral/org.junit.jupiter/junit-jupiter-engine/5.10.2, EPL-2.0, approved, #9711
maven/mavencentral/org.junit.jupiter/junit-jupiter-engine/5.10.3, EPL-2.0, approved, #9711
maven/mavencentral/org.junit.jupiter/junit-jupiter-params/5.10.1, EPL-2.0, approved, #15304
maven/mavencentral/org.junit.jupiter/junit-jupiter-params/5.10.2, EPL-2.0, approved, #15250
maven/mavencentral/org.junit.jupiter/junit-jupiter-params/5.10.3, EPL-2.0, approved, #15250
maven/mavencentral/org.junit.platform/junit-platform-commons/1.10.1, EPL-2.0, approved, #9715
maven/mavencentral/org.junit.platform/junit-platform-commons/1.10.2, EPL-2.0, approved, #9715
maven/mavencentral/org.junit.platform/junit-platform-commons/1.10.3, EPL-2.0, approved, #9715
maven/mavencentral/org.junit.platform/junit-platform-engine/1.10.1, EPL-2.0, approved, #9709
maven/mavencentral/org.junit.platform/junit-platform-engine/1.10.2, EPL-2.0, approved, #9709
maven/mavencentral/org.junit.platform/junit-platform-launcher/1.10.2, EPL-2.0, approved, #15216
maven/mavencentral/org.junit.platform/junit-platform-engine/1.10.3, EPL-2.0, approved, #9709
maven/mavencentral/org.junit.platform/junit-platform-launcher/1.10.3, EPL-2.0, approved, #15216
maven/mavencentral/org.junit/junit-bom/5.10.1, EPL-2.0, approved, #9844
maven/mavencentral/org.junit/junit-bom/5.10.2, EPL-2.0, approved, #9844
maven/mavencentral/org.junit/junit-bom/5.10.3, EPL-2.0, approved, #9844
maven/mavencentral/org.junit/junit-bom/5.9.2, EPL-2.0, approved, #4711
maven/mavencentral/org.jvnet.mimepull/mimepull/1.9.15, CDDL-1.1 OR GPL-2.0-only WITH Classpath-exception-2.0, approved, CQ21484
maven/mavencentral/org.mock-server/mockserver-client-java/5.15.0, Apache-2.0 AND LGPL-3.0-only, approved, #9324
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public QueryResult query(String participantContextId, PresentationQueryMessage q

// now narrow down the requested credentials to only contain allowed credentials
var content = allowedCred.getContent();
var isValidQuery = new HashSet<>(content).containsAll(requestedCredentials);
var isValidQuery = new HashSet<>(content.stream().map(VerifiableCredentialResource::getId).toList())
.containsAll(requestedCredentials.stream().map(VerifiableCredentialResource::getId).toList());

// filter out any expired, revoked or suspended credentials
return isValidQuery ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ class CredentialQueryResolverImplTest {
private final Monitor monitor = mock();
private final CredentialQueryResolverImpl resolver = new CredentialQueryResolverImpl(storeMock, new EdcScopeToCriterionTransformer(), revocationServiceMock, monitor);

private static VerifiableCredentialResource.Builder createCredentialResource(VerifiableCredential cred) {
return VerifiableCredentialResource.Builder.newInstance()
.credential(new VerifiableCredentialContainer("foobar", CredentialFormat.JSON_LD, cred))
.holderId("test-holder")
.issuerId("test-issuer")
.participantId(TEST_PARTICIPANT_CONTEXT_ID);
}

@BeforeEach
void setUp() {
when(revocationServiceMock.checkValidity(any())).thenReturn(Result.success());
Expand Down Expand Up @@ -119,6 +111,22 @@ void query_singleScopeString() {
assertThat(res.getContent()).containsExactly(credential.getVerifiableCredential());
}

@Test
void query_verifyDifferentObjects() {
var credential1 = createCredentialResource(createCredential("TestCredential").build()).id("id1").build();
var credential2 = createCredentialResource(createCredential("TestCredential").build()).id("id1").build();

when(storeMock.query(any()))
.thenAnswer(i -> success(List.of(credential1)))
.thenAnswer(i -> success(List.of(credential2)));

var res = resolver.query(TEST_PARTICIPANT_CONTEXT_ID,
createPresentationQuery("org.eclipse.edc.vc.type:TestCredential:read"), List.of("org.eclipse.edc.vc.type:TestCredential:read"));

assertThat(res.succeeded()).withFailMessage(res::getFailureDetail).isTrue();
assertThat(res.getContent()).usingRecursiveFieldByFieldElementComparator().containsExactly(credential1.getVerifiableCredential());
}

@Test
void query_whenParticipantIdMismatch_expectEmptyResult() {
when(storeMock.query(any())).thenAnswer(i -> success(List.of()));
Expand Down Expand Up @@ -291,6 +299,14 @@ void query_whenRevokedCredential_doesNotInclude() {
verify(monitor).warning(eq("Credential '%s' not valid: revoked".formatted(credential.getId())));
}

private VerifiableCredentialResource.Builder createCredentialResource(VerifiableCredential cred) {
return VerifiableCredentialResource.Builder.newInstance()
.credential(new VerifiableCredentialContainer("foobar", CredentialFormat.JSON_LD, cred))
.holderId("test-holder")
.issuerId("test-issuer")
.participantId(TEST_PARTICIPANT_CONTEXT_ID);
}

private VerifiableCredential.Builder createCredential(String... type) {
return VerifiableCredential.Builder.newInstance()
.types(Arrays.asList(type))
Expand Down
Loading