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: only pass base URL for the CredentialService #3666

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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static org.eclipse.edc.spi.result.Result.success;

public class DefaultCredentialServiceClient implements CredentialServiceClient {
public static final String PRESENTATION_ENDPOINT = "/presentation/query";
private final EdcHttpClient httpClient;
private final JsonBuilderFactory jsonFactory;
private final ObjectMapper objectMapper;
Expand All @@ -63,14 +64,16 @@ public DefaultCredentialServiceClient(EdcHttpClient httpClient, JsonBuilderFacto
}

@Override
public Result<List<VerifiablePresentationContainer>> requestPresentation(String credentialServiceUrl, String selfIssuedTokenJwt, List<String> scopes) {
public Result<List<VerifiablePresentationContainer>> requestPresentation(String credentialServiceBaseUrl, String selfIssuedTokenJwt, List<String> scopes) {
var query = createPresentationQuery(scopes);

var url = credentialServiceBaseUrl + PRESENTATION_ENDPOINT;

try {
var requestJson = objectMapper.writeValueAsString(query);
var request = new Request.Builder()
.post(RequestBody.create(requestJson, MediaType.parse("application/json")))
.url(credentialServiceUrl)
.url(url)
.addHeader("Authorization", "%s".formatted(selfIssuedTokenJwt))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
import static org.eclipse.edc.junit.testfixtures.TestUtils.getResourceFileContentAsString;
import static org.eclipse.edc.spi.result.Result.success;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

class DefaultCredentialServiceClientTest {
Expand Down Expand Up @@ -73,6 +75,7 @@ void requestPresentation_singleLdpVp() throws IOException {
var result = client.requestPresentation(CS_URL, "foo", List.of());
assertThat(result.succeeded()).isTrue();
assertThat(result.getContent()).hasSize(1).allMatch(vpc -> vpc.format() == CredentialFormat.JSON_LD);
verify(httpClientMock).execute(argThat(rq -> rq.url().toString().endsWith("/presentation/query")));
}

@Test
Expand All @@ -84,6 +87,7 @@ void requestPresentation_singleJwtVp() throws IOException {
var result = client.requestPresentation(CS_URL, "foo", List.of());
assertThat(result.succeeded()).isTrue();
assertThat(result.getContent()).hasSize(1).allMatch(vpc -> vpc.format() == CredentialFormat.JWT);
verify(httpClientMock).execute(argThat(rq -> rq.url().toString().endsWith("/presentation/query")));
}

@Test
Expand All @@ -97,6 +101,7 @@ void requestPresentationLdp_multipleVp_mixed() throws IOException {
assertThat(result.getContent()).hasSize(2)
.anySatisfy(vp -> assertThat(vp.format()).isEqualTo(CredentialFormat.JSON_LD))
.anySatisfy(vp -> assertThat(vp.format()).isEqualTo(CredentialFormat.JWT));
verify(httpClientMock).execute(argThat(rq -> rq.url().toString().endsWith("/presentation/query")));
}

@Test
Expand All @@ -109,6 +114,7 @@ void requestPresentation_mulipleVp_onlyLdp() throws IOException {
assertThat(result.succeeded()).isTrue();
assertThat(result.getContent()).hasSize(2)
.allSatisfy(vp -> assertThat(vp.format()).isEqualTo(CredentialFormat.JSON_LD));
verify(httpClientMock).execute(argThat(rq -> rq.url().toString().endsWith("/presentation/query")));
}

@Test
Expand All @@ -121,6 +127,7 @@ void requestPresentation_mulipleVp_onlyJwt() throws IOException {
assertThat(result.succeeded()).isTrue();
assertThat(result.getContent()).hasSize(2)
.allSatisfy(vp -> assertThat(vp.format()).isEqualTo(CredentialFormat.JWT));
verify(httpClientMock).execute(argThat(rq -> rq.url().toString().endsWith("/presentation/query")));
}

@ParameterizedTest(name = "CS returns HTTP error code {0}")
Expand All @@ -132,6 +139,7 @@ void requestPresentation_csReturnsError(int httpCode) throws IOException {
var res = client.requestPresentation(CS_URL, "foo", List.of());
assertThat(res.failed()).isTrue();
assertThat(res.getFailureDetail()).isEqualTo("Presentation Query failed: HTTP %s, message: Test failure".formatted(httpCode));
verify(httpClientMock).execute(argThat(rq -> rq.url().toString().endsWith("/presentation/query")));
}

@DisplayName("CS returns an empty array, because no VC was found")
Expand All @@ -143,6 +151,7 @@ void requestPresentation_emptyArray() throws IOException {
var res = client.requestPresentation(CS_URL, "foo", List.of());
assertThat(res.succeeded()).isTrue();
assertThat(res.getContent()).isNotNull().doesNotContainNull().isEmpty();
verify(httpClientMock).execute(argThat(rq -> rq.url().toString().endsWith("/presentation/query")));
}

private VerifiablePresentation createPresentation() {
Expand Down
Loading