Skip to content

Commit

Permalink
feat: make pub/priv aliases mandatory at startup (eclipse-edc#4304)
Browse files Browse the repository at this point in the history
* feat: make pub/priv alias mandatory at startup

* test cleanup

* get rid of the backend service
  • Loading branch information
ndr-brt authored Jun 26, 2024
1 parent 8956e78 commit cb57f7f
Show file tree
Hide file tree
Showing 31 changed files with 276 additions and 688 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.edc.connector.controlplane.services.spi.asset.AssetService;
import org.eclipse.edc.connector.dataplane.selector.spi.client.DataPlaneClientFactory;
import org.eclipse.edc.connector.dataplane.selector.spi.store.DataPlaneInstanceStore;
import org.eclipse.edc.junit.annotations.ComponentTest;
import org.eclipse.edc.junit.extensions.EdcExtension;
import org.eclipse.edc.spi.event.EventRouter;
import org.eclipse.edc.spi.event.EventSubscriber;
Expand All @@ -42,6 +43,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

@ComponentTest
@ExtendWith(EdcExtension.class)
public class AssetEventDispatchTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.edc.connector.controlplane.services.spi.contractdefinition.ContractDefinitionService;
import org.eclipse.edc.connector.dataplane.selector.spi.client.DataPlaneClientFactory;
import org.eclipse.edc.connector.dataplane.selector.spi.store.DataPlaneInstanceStore;
import org.eclipse.edc.junit.annotations.ComponentTest;
import org.eclipse.edc.junit.extensions.EdcExtension;
import org.eclipse.edc.spi.event.EventRouter;
import org.eclipse.edc.spi.event.EventSubscriber;
Expand All @@ -40,6 +41,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

@ComponentTest
@ExtendWith(EdcExtension.class)
public class ContractDefinitionEventDispatchTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.edc.connector.controlplane.services.spi.contractnegotiation.ContractNegotiationProtocolService;
import org.eclipse.edc.connector.dataplane.selector.spi.client.DataPlaneClientFactory;
import org.eclipse.edc.connector.dataplane.selector.spi.store.DataPlaneInstanceStore;
import org.eclipse.edc.junit.annotations.ComponentTest;
import org.eclipse.edc.junit.extensions.EdcExtension;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.spi.agent.ParticipantAgentService;
Expand Down Expand Up @@ -66,6 +67,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ComponentTest
@ExtendWith(EdcExtension.class)
class ContractNegotiationEventDispatchTest {
private static final String CONSUMER = "consumer";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.edc.connector.controlplane.services.spi.policydefinition.PolicyDefinitionService;
import org.eclipse.edc.connector.dataplane.selector.spi.client.DataPlaneClientFactory;
import org.eclipse.edc.connector.dataplane.selector.spi.store.DataPlaneInstanceStore;
import org.eclipse.edc.junit.annotations.ComponentTest;
import org.eclipse.edc.junit.extensions.EdcExtension;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.spi.event.EventRouter;
Expand All @@ -41,6 +42,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

@ComponentTest
@ExtendWith(EdcExtension.class)
public class PolicyDefinitionEventDispatchTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.edc.connector.controlplane.transfer.spi.types.protocol.TransferStartMessage;
import org.eclipse.edc.connector.core.event.EventExecutorServiceContainer;
import org.eclipse.edc.connector.dataplane.selector.spi.client.DataPlaneClientFactory;
import org.eclipse.edc.junit.annotations.ComponentTest;
import org.eclipse.edc.junit.extensions.RuntimeExtension;
import org.eclipse.edc.junit.extensions.RuntimePerClassExtension;
import org.eclipse.edc.policy.model.Policy;
Expand Down Expand Up @@ -79,6 +80,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ComponentTest
public class TransferProcessEventDispatchTest {

public static final Duration TIMEOUT = Duration.ofSeconds(30);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.runtime.metamodel.annotation.Setting;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.result.Result;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
Expand Down Expand Up @@ -59,7 +60,6 @@ public String name() {
return NAME;
}


@Provider(isDefault = true)
public DataPlaneAccessControlService defaultAccessControlService(ServiceExtensionContext context) {
context.getMonitor().debug("DataPlane Access Control: default implementation is used, will always return Result.success()");
Expand All @@ -68,24 +68,24 @@ public DataPlaneAccessControlService defaultAccessControlService(ServiceExtensio

@Provider(isDefault = true)
public DataPlaneAccessTokenService defaultAccessTokenService(ServiceExtensionContext context) {
var tokenVerifierPublicKeyAlias = context.getConfig().getString(TOKEN_VERIFIER_PUBLIC_KEY_ALIAS);
var tokenSignerPrivateKeyAlias = context.getConfig().getString(TOKEN_SIGNER_PRIVATE_KEY_ALIAS);
var monitor = context.getMonitor().withPrefix("DataPlane IAM");
return new DefaultDataPlaneAccessTokenServiceImpl(new JwtGenerationService(),
accessTokenDataStore, context.getMonitor().withPrefix("DataPlane IAM"),
getPrivateKeySupplier(context), publicKeyIdSupplier(context), tokenValidationService, localPublicKeyService);
accessTokenDataStore, monitor, getPrivateKeySupplier(tokenSignerPrivateKeyAlias, monitor),
publicKeyIdSupplier(tokenVerifierPublicKeyAlias), tokenValidationService, localPublicKeyService);
}

private Supplier<String> publicKeyIdSupplier(ServiceExtensionContext context) {
return () -> context.getConfig().getString(TOKEN_VERIFIER_PUBLIC_KEY_ALIAS);
private Supplier<String> publicKeyIdSupplier(String tokenVerifierPublicKeyAlias) {
return () -> tokenVerifierPublicKeyAlias;
}

@NotNull
private Supplier<PrivateKey> getPrivateKeySupplier(ServiceExtensionContext context) {
return () -> {
var alias = context.getConfig().getString(TOKEN_SIGNER_PRIVATE_KEY_ALIAS);
return privateKeyResolver.resolvePrivateKey(alias)
.orElse(f -> {
context.getMonitor().warning("Cannot resolve private key: " + f.getFailureDetail());
return null;
});
};
private Supplier<PrivateKey> getPrivateKeySupplier(String tokenSignerPrivateKeyAlias, Monitor monitor) {
return () -> privateKeyResolver.resolvePrivateKey(tokenSignerPrivateKeyAlias)
.orElse(f -> {
monitor.warning("Cannot resolve private key: " + f.getFailureDetail());
return null;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.eclipse.edc.connector.spi.service.SecretService;
import org.eclipse.edc.edr.spi.store.EndpointDataReferenceStore;
import org.eclipse.edc.jsonld.spi.JsonLd;
import org.eclipse.edc.junit.annotations.EndToEndTest;
import org.eclipse.edc.junit.annotations.ComponentTest;
import org.eclipse.edc.junit.extensions.RuntimeExtension;
import org.eclipse.edc.junit.extensions.RuntimePerClassExtension;
import org.eclipse.edc.policy.model.AndConstraint;
Expand Down Expand Up @@ -86,7 +86,7 @@
import static org.eclipse.edc.util.io.Ports.getFreePort;
import static org.mockito.Mockito.mock;

@EndToEndTest
@ComponentTest
public class SerdeIntegrationTest {

@RegisterExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ void setUp(RuntimeExtension extension) {
"web.http.control.port", String.valueOf(port),
"web.http.control.path", "/control",
"edc.core.retry.retries.max", "0",
"edc.dataplane.send.retry.limit", "0"
"edc.dataplane.send.retry.limit", "0",
"edc.transfer.proxy.token.verifier.publickey.alias", "alias",
"edc.transfer.proxy.token.signer.privatekey.alias", "alias"
));

extension.registerSystemExtension(ServiceExtension.class, new TransferServiceMockExtension(service));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.eclipse.edc.connector.dataplane.selector.spi.store.DataPlaneInstanceStore;
import org.eclipse.edc.connector.dataplane.selector.spi.strategy.SelectionStrategy;
import org.eclipse.edc.connector.dataplane.selector.spi.strategy.SelectionStrategyRegistry;
import org.eclipse.edc.junit.annotations.ComponentTest;
import org.eclipse.edc.junit.annotations.ApiTest;
import org.eclipse.edc.junit.extensions.EdcExtension;
import org.eclipse.edc.spi.types.domain.DataAddress;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -49,7 +49,7 @@
import static org.eclipse.edc.util.io.Ports.getFreePort;
import static org.hamcrest.Matchers.equalTo;

@ComponentTest
@ApiTest
@ExtendWith(EdcExtension.class)
public class DataPlaneSelectorApiV2ControllerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import io.restassured.specification.RequestSpecification;
import jakarta.json.JsonArray;
import org.eclipse.edc.connector.dataplane.selector.spi.store.DataPlaneInstanceStore;
import org.eclipse.edc.junit.annotations.ComponentTest;
import org.eclipse.edc.junit.annotations.ApiTest;
import org.eclipse.edc.junit.extensions.EdcExtension;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -32,7 +32,7 @@
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
import static org.eclipse.edc.util.io.Ports.getFreePort;

@ComponentTest
@ApiTest
@ExtendWith(EdcExtension.class)
public class DataPlaneSelectorApiV3ControllerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
import org.eclipse.edc.connector.dataplane.http.spi.HttpRequestParamsProvider;
import org.eclipse.edc.connector.dataplane.spi.pipeline.PipelineService;
import org.eclipse.edc.connector.dataplane.spi.pipeline.StreamResult;
import org.eclipse.edc.junit.extensions.EdcExtension;
import org.eclipse.edc.junit.annotations.ComponentTest;
import org.eclipse.edc.junit.extensions.RuntimeExtension;
import org.eclipse.edc.junit.extensions.RuntimePerClassExtension;
import org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.HttpResponse;

import java.util.Map;
import java.util.UUID;

import static java.util.Collections.emptyMap;
Expand All @@ -39,17 +42,24 @@
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.stop.Stop.stopQuietly;

@ExtendWith(EdcExtension.class)
@ComponentTest
public class DataPlaneHttpExtensionTest {

private static ClientAndServer sourceServer;
private static ClientAndServer destinationServer;
private static final int SOURCE_PORT = getFreePort();
private static final int DESTINATION_PORT = getFreePort();

@RegisterExtension
private static final RuntimeExtension RUNTIME = new RuntimePerClassExtension()
.setConfiguration(Map.of(
"edc.transfer.proxy.token.verifier.publickey.alias", "alias",
"edc.transfer.proxy.token.signer.privatekey.alias", "alias"
))
.registerServiceMock(TransferProcessApiClient.class, mock());

@BeforeAll
public static void setUp(EdcExtension extension) {
extension.registerServiceMock(TransferProcessApiClient.class, mock());
public static void setUp() {
sourceServer = startClientAndServer(SOURCE_PORT);
destinationServer = startClientAndServer(DESTINATION_PORT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import org.eclipse.edc.connector.dataplane.spi.DataFlowStates;
import org.eclipse.edc.connector.dataplane.spi.schema.DataFlowRequestSchema;
import org.eclipse.edc.junit.annotations.ComponentTest;
import org.eclipse.edc.junit.extensions.EdcRuntimeExtension;
import org.eclipse.edc.junit.extensions.EmbeddedRuntime;
import org.eclipse.edc.junit.extensions.RuntimeExtension;
import org.eclipse.edc.junit.extensions.RuntimePerClassExtension;
import org.eclipse.edc.spi.types.TypeManager;
import org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -104,15 +106,17 @@ public class DataPlaneHttpIntegrationTests {
private static ClientAndServer validationApiMockServer;
private final Duration timeout = Duration.ofSeconds(30);

@RegisterExtension
static EdcRuntimeExtension dataPlane = new EdcRuntimeExtension(
private static final EmbeddedRuntime RUNTIME = new EmbeddedRuntime(
"data-plane-server",
Map.of(
"web.http.public.port", valueOf(PUBLIC_API_PORT),
"web.http.public.path", PUBLIC_PATH,
"web.http.control.port", valueOf(CONTROL_API_PORT),
"web.http.control.path", CONTROL_PATH,
"edc.dataplane.token.validation.endpoint", VALIDATION_API_HOST
"edc.dataplane.token.validation.endpoint", VALIDATION_API_HOST,
"edc.transfer.proxy.token.verifier.publickey.alias", "alias",
"edc.transfer.proxy.token.signer.privatekey.alias", "alias",
"edc.core.retry.retries.max", "0"
),
":extensions:common:metrics:micrometer-core",
":core:data-plane:data-plane-core",
Expand Down Expand Up @@ -149,6 +153,10 @@ public void resetMockServer() {

@Nested
class Pull {

@RegisterExtension
static RuntimeExtension dataPlane = new RuntimePerClassExtension(RUNTIME);

@Test
void transfer_pull_withSourceQueryParamsAndPath_success(TypeManager typeManager) {
// prepare data source and validation servers
Expand Down Expand Up @@ -227,6 +235,10 @@ void shouldProxyMethodAndBody_whenSet(TypeManager typeManager) {

@Nested
class Push {

@RegisterExtension
static RuntimeExtension dataPlane = new RuntimePerClassExtension(RUNTIME);

@Test
void transfer_toHttpSink_success(TypeManager typeManager) {
var body = UUID.randomUUID().toString();
Expand Down
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ include(":spi:policy-monitor:policy-monitor-spi")
include(":tests:junit-base")

// modules for system tests ------------------------------------------------------------------------
include(":system-tests:e2e-transfer-test:backend-service")
include(":system-tests:e2e-transfer-test:control-plane")
include(":system-tests:e2e-transfer-test:data-plane")
include(":system-tests:e2e-transfer-test:runner")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public class DataPlaneSelectorEndToEndTest {
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api",
"web.http.control.port", String.valueOf(dataPlaneControlPort),
"web.http.control.path", "/control"
"web.http.control.path", "/control",
"edc.transfer.proxy.token.verifier.publickey.alias", "alias",
"edc.transfer.proxy.token.signer.privatekey.alias", "alias"
),
":core:data-plane:data-plane-core",
":extensions:data-plane:data-plane-http",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public class DataplaneSelectorControlApiEndToEndTest {
"web.http.path", "/api",
"web.http.control.port", String.valueOf(getFreePort()),
"web.http.control.path", "/control",
"edc.dpf.selector.url", String.format("http://localhost:%d/control/v1/dataplanes", controlPlaneControlPort)
"edc.dpf.selector.url", String.format("http://localhost:%d/control/v1/dataplanes", controlPlaneControlPort),
"edc.transfer.proxy.token.verifier.publickey.alias", "alias",
"edc.transfer.proxy.token.signer.privatekey.alias", "alias"
),
":system-tests:e2e-dataplane-tests:runtimes:data-plane",
":extensions:data-plane:data-plane-self-registration",
Expand Down
1 change: 0 additions & 1 deletion system-tests/e2e-transfer-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ This tests verifies some complete scenarios of contract negotiation and data tra

## Modules detail

* [backend-service](./backend-service): it represents an external application that interacts with the EDC.
* [control-plane](./control-plane): it's responsible for handling the contract negotiation phase using in-memory persistence
* [data-plane](./data-plane): it handles the data transfer phase acting as a proxy
* [runner](./runner): it contains the test implementation
Expand Down
30 changes: 0 additions & 30 deletions system-tests/e2e-transfer-test/backend-service/build.gradle.kts

This file was deleted.

Loading

0 comments on commit cb57f7f

Please sign in to comment.