From e96e04721962d842ccca4b1debffa2031b52a868 Mon Sep 17 00:00:00 2001 From: Ronja Quensel <72978761+ronjaquensel@users.noreply.github.com> Date: Thu, 20 Jul 2023 11:33:26 +0200 Subject: [PATCH] chore: handle missing destination in transfer protocol service (#3316) --- .../TransferProcessProtocolServiceImpl.java | 17 ++++++++---- ...ransferProcessProtocolServiceImplTest.java | 26 +++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessProtocolServiceImpl.java b/core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessProtocolServiceImpl.java index 7d06239f355..7ee9aed8906 100644 --- a/core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessProtocolServiceImpl.java +++ b/core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessProtocolServiceImpl.java @@ -37,6 +37,7 @@ import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.result.Result; import org.eclipse.edc.spi.telemetry.Telemetry; +import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.transaction.spi.TransactionContext; import org.jetbrains.annotations.NotNull; @@ -46,6 +47,7 @@ import static java.lang.String.format; import static java.util.UUID.randomUUID; +import static org.eclipse.edc.connector.transfer.dataplane.spi.TransferDataPlaneConstants.HTTP_PROXY; import static org.eclipse.edc.connector.transfer.spi.types.TransferProcess.Type.CONSUMER; import static org.eclipse.edc.connector.transfer.spi.types.TransferProcess.Type.PROVIDER; @@ -86,9 +88,12 @@ public ServiceResult notifyRequested(TransferRequestMessage mes return ServiceResult.badRequest("ContractId is not valid: " + contractIdResult.getFailureDetail()); } - var validDestination = dataAddressValidator.validate(message.getDataDestination()); - if (validDestination.failed()) { - return ServiceResult.badRequest(validDestination.getFailureMessages()); + var destination = message.getDataDestination(); + if (destination != null) { + var validDestination = dataAddressValidator.validate(destination); + if (validDestination.failed()) { + return ServiceResult.badRequest(validDestination.getFailureMessages()); + } } return transactionContext.execute(() -> @@ -132,12 +137,14 @@ public ServiceResult findById(String id, ClaimToken claimToken) @NotNull private ServiceResult requestedAction(TransferRequestMessage message, ContractId contractId) { var assetId = contractId.assetIdPart(); - + + var destination = message.getDataDestination() != null ? message.getDataDestination() : + DataAddress.Builder.newInstance().type(HTTP_PROXY).build(); var dataRequest = DataRequest.Builder.newInstance() .id(message.getProcessId()) .protocol(message.getProtocol()) .connectorAddress(message.getCallbackAddress()) - .dataDestination(message.getDataDestination()) + .dataDestination(destination) .assetId(assetId) .contractId(message.getContractId()) .build(); diff --git a/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessProtocolServiceImplTest.java b/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessProtocolServiceImplTest.java index e58530b30c0..ddf6b8f641c 100644 --- a/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessProtocolServiceImplTest.java +++ b/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessProtocolServiceImplTest.java @@ -55,6 +55,7 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.connector.transfer.dataplane.spi.TransferDataPlaneConstants.HTTP_PROXY; import static org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates.COMPLETED; import static org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates.INITIAL; import static org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates.REQUESTED; @@ -192,6 +193,31 @@ void notifyRequested_invalidDestination_shouldNotInitiateTransfer() { verify(store, never()).save(any()); verifyNoInteractions(listener); } + + @Test + void notifyRequested_missingDestination_shouldInitiateTransfer() { + var message = TransferRequestMessage.Builder.newInstance() + .processId("transferProcessId") + .protocol("protocol") + .contractId(ContractId.create("definitionId", "assetId").toString()) + .callbackAddress("http://any") + .build(); + when(negotiationStore.findContractAgreement(any())).thenReturn(contractAgreement()); + when(validationService.validateAgreement(any(), any())).thenReturn(Result.success(null)); + + var result = service.notifyRequested(message, claimToken()); + + assertThat(result).isSucceeded().satisfies(tp -> { + assertThat(tp.getCorrelationId()).isEqualTo("transferProcessId"); + assertThat(tp.getConnectorAddress()).isEqualTo("http://any"); + assertThat(tp.getAssetId()).isEqualTo("assetId"); + assertThat(tp.getDataDestination().getType()).isEqualTo(HTTP_PROXY); + }); + verify(listener).preCreated(any()); + verify(store).save(argThat(t -> t.getState() == INITIAL.code())); + verify(listener).initiated(any()); + verify(transactionContext, atLeastOnce()).execute(any(TransactionContext.ResultTransactionBlock.class)); + } @Test void notifyStarted_shouldTransitionToStarted() {