diff --git a/AGENTS.md b/AGENTS.md index b548b7a2b8..e60a0d6691 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -11,13 +11,17 @@ Helm charts. Remote: `project-construct-x/constructx-edc`; upstream: 3. **Construct-X additions** — keep changes minimal and upstream-aligned. The only Construct-X-specific code is a handful of extensions plus the runtime distributions under `edc-controlplane/edc-controlplane-construct-x/` and `edc-dataplane/edc-dataplane-construct-x/`. ## Construct-X runtimes (review these first for con-x work) -The `con-x-controlplane-postgresql-hashicorp-vault` and `con-x-dataplane-postgresql-hashicorp-vault` -modules do **not** compile sibling source. They are thin `shadowJar` aggregations of **pre-built, -published** upstream artifacts, assembled at runtime via EDC's ServiceLoader autoload (`mergeServiceFiles()`): +There are two variants per plane, differing only in the vault backend: +`con-x-{controlplane,dataplane}-postgresql-hashicorp-vault` (HashiCorp Vault) and +`con-x-{controlplane,dataplane}-postgresql-vault` (Postgres-backed `:edc-extensions:sql-vault`). +**Keep all four build files in sync** — every exclude/dependency change applies to both variants of a plane. +They are thin `shadowJar` aggregations of mostly **pre-built, published** upstream artifacts plus a few +in-repo extensions (`project(":edc-extensions:...")`), assembled at runtime via EDC's ServiceLoader autoload (`mergeServiceFiles()`): - Dependencies are upstream BOMs/artifacts: `org.eclipse.edc:*` and `org.eclipse.tractusx.edc:*` (e.g. `controlplane-dcp-bom`, `controlplane-feature-sql-bom`, `vault-hashicorp`, `tx-dcp`, `agreements`). -- **Versions are pinned inline** in each module's `build.gradle.kts` (`val edcVersion` / `val txVersion`), deviating from the repo-wide version-catalog rule. To bump, edit those local vals in both runtime build files. +- **Versions come from root `gradle.properties`**, deviating from the repo-wide version-catalog rule: `edcVersion` = `con-x-edcVersion`, `txVersion` = `version` (read via `project.property(...)` in each runtime's `build.gradle.kts`). In-repo extensions are still compiled against the version catalog's `edc` version, so they run on `con-x-edcVersion` binaries — when bumping, also build and test those extensions against the new EDC version. To bump EDC, change `con-x-edcVersion` only, then check the upstream BOMs for changed module composition. - Entrypoint: `mainClass = org.eclipse.edc.boot.system.runtime.BaseRuntime`. -- Dataplane intentionally `exclude`s `org.eclipse.edc:data-plane-util` in favor of the tractusx `dataplane-util`. +- Dataplanes intentionally `exclude` `org.eclipse.edc:data-plane-util` in favor of the tractusx `dataplane-util`. +- Controlplanes intentionally `exclude` the new `data-plane-signaling*` modules (pulled in by the EDC ≥ 0.18 controlplane BOM) and add legacy `transfer-data-plane-signaling` instead: the con-x dataplane is still the legacy JSON-LD EDC data plane. Without this, transfers terminate with `400 ... missing '@context'` and no EDR is created. Remove once the dataplane implements the new Data Plane Signaling spec. - To add a feature to a con-x runtime, add the BOM/artifact dependency here — don't wire code — unless authoring a genuinely new extension (then add it as a module and depend on it). - Build a single runtime image, e.g.: `./gradlew :edc-controlplane:edc-controlplane-construct-x:con-x-controlplane-postgresql-hashicorp-vault:dockerize` (note: that module's README has a typo, `postgres` vs `postgresql`). diff --git a/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-hashicorp-vault/README.md b/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-hashicorp-vault/README.md index 961933bd1c..bdd12b89df 100644 --- a/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-hashicorp-vault/README.md +++ b/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-hashicorp-vault/README.md @@ -5,5 +5,5 @@ From the project root directory, run ```shell -./gradlew :edc-controlplane:edc-controlplane-construct-x:con-x-controlplane-postgres-hashicorp-vault:dockerize +./gradlew :edc-controlplane:edc-controlplane-construct-x:con-x-controlplane-postgresql-hashicorp-vault:dockerize ``` diff --git a/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-hashicorp-vault/build.gradle.kts b/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-hashicorp-vault/build.gradle.kts index 2c0f6614c8..bbab221494 100644 --- a/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-hashicorp-vault/build.gradle.kts +++ b/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-hashicorp-vault/build.gradle.kts @@ -25,12 +25,23 @@ plugins { alias(libs.plugins.shadow) } +// Since EDC 0.18 the controlplane BOM ships the new Data Plane Signaling implementation +// (non JSON-LD), which the legacy EDC data plane in con-x-dataplane cannot understand. +// Keep the legacy JSON-LD signaling until the data plane is migrated. +configurations.all { + exclude(group = "org.eclipse.edc", module = "data-plane-signaling") + exclude(group = "org.eclipse.edc", module = "data-plane-signaling-core") + exclude(group = "org.eclipse.edc", module = "data-plane-signaling-api") + exclude(group = "org.eclipse.edc", module = "data-plane-signaling-oauth2") +} + val edcVersion = project.property("con-x-edcVersion") as String val txVersion = project.property("version") as String dependencies { implementation("org.eclipse.edc:controlplane-dcp-bom:$edcVersion") implementation("org.eclipse.edc:controlplane-feature-sql-bom:$edcVersion") + implementation("org.eclipse.edc:transfer-data-plane-signaling:$edcVersion") implementation("org.eclipse.edc:vault-hashicorp:$edcVersion") @@ -43,8 +54,8 @@ dependencies { // Hotfix version overrides - implementation("com.fasterxml.jackson.core:jackson-core:2.22.3") - implementation("com.fasterxml.jackson.core:jackson-databind:2.22.4") + implementation("com.fasterxml.jackson.core:jackson-core:2.23.0") + implementation("com.fasterxml.jackson.core:jackson-databind:2.23.0") } diff --git a/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-vault/README.md b/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-vault/README.md index 0aef39d29f..96dac325a7 100644 --- a/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-vault/README.md +++ b/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-vault/README.md @@ -14,5 +14,5 @@ a con-x EDC a bit less difficult. From the project root directory, run ```shell -./gradlew :edc-controlplane:edc-controlplane-construct-x:con-x-controlplane-postgres-vault:dockerize +./gradlew :edc-controlplane:edc-controlplane-construct-x:con-x-controlplane-postgresql-vault:dockerize ``` diff --git a/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-vault/build.gradle.kts b/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-vault/build.gradle.kts index 52c2d845e9..03e4118b32 100644 --- a/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-vault/build.gradle.kts +++ b/edc-controlplane/edc-controlplane-construct-x/con-x-controlplane-postgresql-vault/build.gradle.kts @@ -25,12 +25,23 @@ plugins { alias(libs.plugins.shadow) } +// Since EDC 0.18 the controlplane BOM ships the new Data Plane Signaling implementation +// (non JSON-LD), which the legacy EDC data plane in con-x-dataplane cannot understand. +// Keep the legacy JSON-LD signaling until the data plane is migrated. +configurations.all { + exclude(group = "org.eclipse.edc", module = "data-plane-signaling") + exclude(group = "org.eclipse.edc", module = "data-plane-signaling-core") + exclude(group = "org.eclipse.edc", module = "data-plane-signaling-api") + exclude(group = "org.eclipse.edc", module = "data-plane-signaling-oauth2") +} + val edcVersion = project.property("con-x-edcVersion") as String val txVersion = project.property("version") as String dependencies { implementation("org.eclipse.edc:controlplane-dcp-bom:$edcVersion") implementation("org.eclipse.edc:controlplane-feature-sql-bom:$edcVersion") + implementation("org.eclipse.edc:transfer-data-plane-signaling:$edcVersion") implementation(project(":edc-extensions:sql-vault")) @@ -43,8 +54,8 @@ dependencies { // Hotfix version overrides - implementation("com.fasterxml.jackson.core:jackson-core:2.22.3") - implementation("com.fasterxml.jackson.core:jackson-databind:2.22.4") + implementation("com.fasterxml.jackson.core:jackson-core:2.23.0") + implementation("com.fasterxml.jackson.core:jackson-databind:2.23.0") } tasks.withType { diff --git a/edc-controlplane/edc-controlplane-construct-x/local/bruno/con-x-local-test/environments/local-con-x-env.bru b/edc-controlplane/edc-controlplane-construct-x/local/bruno/con-x-local-test/environments/local-con-x-env.bru index 3ba5c16c63..4533f88762 100644 --- a/edc-controlplane/edc-controlplane-construct-x/local/bruno/con-x-local-test/environments/local-con-x-env.bru +++ b/edc-controlplane/edc-controlplane-construct-x/local/bruno/con-x-local-test/environments/local-con-x-env.bru @@ -20,7 +20,7 @@ vars { ISS_PART_CONT: con-x-issuer CONS_PART_CONT: user-consumer PROV_PART_CONT: user-provider - MEM_CRED_ID: https://w3id.org/constructx/credentials/v1.0/ConstructXMembershipCredential + MEM_CRED_ID: https://w3id.org/constructx/credentials/v0.1/MembershipCredential CUSTOM_CRED_ID: https://foo.org/constructx/bar/credentials/v1/Baustelle123Credential TARGET_ASSET_ID: demoAssetIdOne CRFORMAT: VC1_0_JWT diff --git a/edc-dataplane/edc-dataplane-construct-x/con-x-dataplane-postgresql-hashicorp-vault/build.gradle.kts b/edc-dataplane/edc-dataplane-construct-x/con-x-dataplane-postgresql-hashicorp-vault/build.gradle.kts index e1fbbed5e0..ba14687c9d 100644 --- a/edc-dataplane/edc-dataplane-construct-x/con-x-dataplane-postgresql-hashicorp-vault/build.gradle.kts +++ b/edc-dataplane/edc-dataplane-construct-x/con-x-dataplane-postgresql-hashicorp-vault/build.gradle.kts @@ -45,8 +45,8 @@ dependencies { // Hotfix version overrides - implementation("com.fasterxml.jackson.core:jackson-core:2.22.3") - implementation("com.fasterxml.jackson.core:jackson-databind:2.22.4") + implementation("com.fasterxml.jackson.core:jackson-core:2.23.0") + implementation("com.fasterxml.jackson.core:jackson-databind:2.23.0") } diff --git a/edc-dataplane/edc-dataplane-construct-x/con-x-dataplane-postgresql-vault/build.gradle.kts b/edc-dataplane/edc-dataplane-construct-x/con-x-dataplane-postgresql-vault/build.gradle.kts index 2c4a4e3dc0..322d84d193 100644 --- a/edc-dataplane/edc-dataplane-construct-x/con-x-dataplane-postgresql-vault/build.gradle.kts +++ b/edc-dataplane/edc-dataplane-construct-x/con-x-dataplane-postgresql-vault/build.gradle.kts @@ -45,8 +45,8 @@ dependencies { // Hotfix version overrides - implementation("com.fasterxml.jackson.core:jackson-core:2.22.3") - implementation("com.fasterxml.jackson.core:jackson-databind:2.22.4") + implementation("com.fasterxml.jackson.core:jackson-core:2.23.0") + implementation("com.fasterxml.jackson.core:jackson-databind:2.23.0") } diff --git a/edc-extensions/basic-abac/README.md b/edc-extensions/basic-abac/README.md index a483b34b1c..5ec13a91c1 100644 --- a/edc-extensions/basic-abac/README.md +++ b/edc-extensions/basic-abac/README.md @@ -171,5 +171,6 @@ There is a technical necessity that the controlplane minimally needs at least on edc.abac.defaultcredential=https://w3id.org/my/very/special/FooMembershipCredential ``` -You are not required to use that property. If you don't, it will default to `https://w3id.org/constructx/credentials/v1.0/ConstructXMembershipCredential`. +You are not required to use that property. If you don't, it will default to +`https://w3id.org/constructx/credentials/v0.1/MembershipCredential`. diff --git a/edc-extensions/basic-abac/src/main/java/de/fraunhofer/isst/edc/extension/basic_abac/dev/BasicAbacExtension.java b/edc-extensions/basic-abac/src/main/java/de/fraunhofer/isst/edc/extension/basic_abac/dev/BasicAbacExtension.java index 4302cea8d1..4e9f503846 100644 --- a/edc-extensions/basic-abac/src/main/java/de/fraunhofer/isst/edc/extension/basic_abac/dev/BasicAbacExtension.java +++ b/edc-extensions/basic-abac/src/main/java/de/fraunhofer/isst/edc/extension/basic_abac/dev/BasicAbacExtension.java @@ -50,7 +50,7 @@ public class BasicAbacExtension implements ServiceExtension { @Setting(description = "The default credential type to be used", - defaultValue = "https://w3id.org/constructx/credentials/v1.0/ConstructXMembershipCredential", + defaultValue = "https://w3id.org/constructx/credentials/v0.1/MembershipCredential", key = "edc.abac.defaultcredential") private String defaultCredential; diff --git a/edc-extensions/sql-vault/README.md b/edc-extensions/sql-vault/README.md index 80f5cc1404..f697528134 100644 --- a/edc-extensions/sql-vault/README.md +++ b/edc-extensions/sql-vault/README.md @@ -14,7 +14,7 @@ extension and stick to the HashiCorp vault extension, if you require maximum sec ### Usage -This extension will self-register at boot-time and then deploy initial secrets, which you can define via as described in the following. +This extension will self-register at boot time and deploy initial secrets afterward, which can be defined as described below. #### Secret definition via explicit property diff --git a/edc-extensions/sql-vault/build.gradle.kts b/edc-extensions/sql-vault/build.gradle.kts index 2791209076..312ef193a2 100644 --- a/edc-extensions/sql-vault/build.gradle.kts +++ b/edc-extensions/sql-vault/build.gradle.kts @@ -21,7 +21,7 @@ plugins { repositories { mavenCentral() } -val edcVersion = "0.17.0" +val edcVersion = project.property("con-x-edcVersion") as String dependencies { implementation("org.eclipse.edc:sql-lib:${edcVersion}") diff --git a/edc-extensions/sql-vault/src/main/java/de/fraunhofer/isst/edc/extension/sqlvault/dev/SqlVault.java b/edc-extensions/sql-vault/src/main/java/de/fraunhofer/isst/edc/extension/sqlvault/dev/SqlVault.java index ec012d4ba6..e0cb221464 100644 --- a/edc-extensions/sql-vault/src/main/java/de/fraunhofer/isst/edc/extension/sqlvault/dev/SqlVault.java +++ b/edc-extensions/sql-vault/src/main/java/de/fraunhofer/isst/edc/extension/sqlvault/dev/SqlVault.java @@ -49,6 +49,7 @@ public SqlVault(DataSourceRegistry dataSourceRegistry, String dataSourceName, return queryExecutor.single(connection, false, resultSet -> resultSet.getString("secret"), command, key); } catch (Exception e) { + monitor.severe("Error resolving secret for key: " + key, e); return null; } }); diff --git a/edc-extensions/sql-vault/src/main/java/de/fraunhofer/isst/edc/extension/sqlvault/dev/SqlVaultExtension.java b/edc-extensions/sql-vault/src/main/java/de/fraunhofer/isst/edc/extension/sqlvault/dev/SqlVaultExtension.java index 0419186f0a..aecbcb9004 100644 --- a/edc-extensions/sql-vault/src/main/java/de/fraunhofer/isst/edc/extension/sqlvault/dev/SqlVaultExtension.java +++ b/edc-extensions/sql-vault/src/main/java/de/fraunhofer/isst/edc/extension/sqlvault/dev/SqlVaultExtension.java @@ -91,8 +91,9 @@ public void start() { String[] kvPairs = initData.split(";;;"); for (String kvPair : kvPairs) { try { - String[] kv = kvPair.split(":::"); - sqlVault.storeSecret(kv[0], kv[1]); + String[] kv = kvPair.split(":::", 2); + sqlVault.storeSecret(kv[0], kv[1]) + .onFailure(f -> monitor.warning("Error storing sql vault data for key " + kv[0] + ": " + f.getFailureDetail())); } catch (Exception e) { monitor.warning("Error storing sql vault data: " + kvPair); } @@ -105,8 +106,9 @@ public void start() { if (Files.isRegularFile(path)) { String key = path.getFileName().toString(); try { - String value = Files.readString(path); - sqlVault.storeSecret(key, value); + String value = Files.readString(path).strip(); + sqlVault.storeSecret(key, value) + .onFailure(f -> monitor.warning("Error storing sql vault data for key " + key + ": " + f.getFailureDetail())); } catch (Exception ex) { monitor.warning("Error reading value for key: " + key); } diff --git a/edc-extensions/sql-vault/src/test/java/SqlVaultTest.java b/edc-extensions/sql-vault/src/test/java/SqlVaultTest.java deleted file mode 100644 index e5e580deef..0000000000 --- a/edc-extensions/sql-vault/src/test/java/SqlVaultTest.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2026 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. (represented by Fraunhofer ISST) - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -import static org.mockito.Mockito.mock; - -public class SqlVaultTest { - - -} diff --git a/edc-extensions/sql-vault/src/test/java/de/fraunhofer/isst/edc/extension/sqlvault/dev/SqlVaultExtensionTest.java b/edc-extensions/sql-vault/src/test/java/de/fraunhofer/isst/edc/extension/sqlvault/dev/SqlVaultExtensionTest.java new file mode 100644 index 0000000000..831b1814e1 --- /dev/null +++ b/edc-extensions/sql-vault/src/test/java/de/fraunhofer/isst/edc/extension/sqlvault/dev/SqlVaultExtensionTest.java @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2026 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. (represented by Fraunhofer ISST) + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package de.fraunhofer.isst.edc.extension.sqlvault.dev; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.edc.boot.system.injection.ObjectFactory; +import org.eclipse.edc.junit.extensions.DependencyInjectionExtension; +import org.eclipse.edc.spi.monitor.Monitor; +import org.eclipse.edc.spi.system.ServiceExtensionContext; +import org.eclipse.edc.spi.system.configuration.ConfigFactory; +import org.eclipse.edc.spi.types.TypeManager; +import org.eclipse.edc.sql.QueryExecutor; +import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper; +import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; +import org.eclipse.edc.transaction.spi.NoopTransactionContext; +import org.eclipse.edc.transaction.spi.TransactionContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import javax.sql.DataSource; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.contains; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.RETURNS_SELF; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(DependencyInjectionExtension.class) +class SqlVaultExtensionTest { + + private static final String UPSERT = "ON CONFLICT (id) DO UPDATE"; + + private final DataSourceRegistry dataSourceRegistry = mock(); + private final DataSource dataSource = mock(); + private final Connection connection = mock(); + private final QueryExecutor queryExecutor = mock(); + private final SqlSchemaBootstrapper schemaBootstrapper = mock(); + private final TypeManager typeManager = mock(); + private final Monitor monitor = mock(Monitor.class, RETURNS_SELF); + + @TempDir + Path tempDir; + + @BeforeEach + void setUp(ServiceExtensionContext context) throws SQLException { + when(dataSourceRegistry.resolve(anyString())).thenReturn(dataSource); + when(dataSource.getConnection()).thenReturn(connection); + when(typeManager.getMapper()).thenReturn(new ObjectMapper()); + when(queryExecutor.execute(any(), anyString(), any(Object[].class))).thenReturn(1); + + context.registerService(DataSourceRegistry.class, dataSourceRegistry); + context.registerService(TransactionContext.class, new NoopTransactionContext()); + context.registerService(TypeManager.class, typeManager); + context.registerService(QueryExecutor.class, queryExecutor); + context.registerService(SqlSchemaBootstrapper.class, schemaBootstrapper); + when(context.getMonitor()).thenReturn(monitor); + } + + @Test + void initialize_registersSchemaForConfiguredDatasource(ServiceExtensionContext context, ObjectFactory factory) { + withConfig(context, Map.of("edc.sql.store.vault.datasource", "vault-ds")); + + start(context, factory); + + verify(schemaBootstrapper).addStatementFromResource("vault-ds", "sql-vault.sql"); + } + + @Test + void start_storesInitDataPairs(ServiceExtensionContext context, ObjectFactory factory) { + withConfig(context, Map.of("edc.sql.store.vault.initdata", "foo:::123;;;bar:::456")); + + start(context, factory); + + verify(queryExecutor).execute(eq(connection), contains(UPSERT), eq("foo"), eq("123")); + verify(queryExecutor).execute(eq(connection), contains(UPSERT), eq("bar"), eq("456")); + } + + @Test + void start_keepsSeparatorInsideValue(ServiceExtensionContext context, ObjectFactory factory) { + withConfig(context, Map.of("edc.sql.store.vault.initdata", "foo:::a:::b")); + + start(context, factory); + + verify(queryExecutor).execute(eq(connection), contains(UPSERT), eq("foo"), eq("a:::b")); + } + + @Test + void start_skipsMalformedPairButStoresTheRest(ServiceExtensionContext context, ObjectFactory factory) { + withConfig(context, Map.of("edc.sql.store.vault.initdata", "broken;;;foo:::123")); + + start(context, factory); + + verify(queryExecutor).execute(eq(connection), contains(UPSERT), eq("foo"), eq("123")); + verify(queryExecutor, never()).execute(any(), anyString(), eq("broken"), any()); + verify(monitor).warning(contains("broken")); + } + + @Test + void start_logsWarningWhenStoringFails(ServiceExtensionContext context, ObjectFactory factory) { + when(queryExecutor.execute(any(), anyString(), any(Object[].class))).thenReturn(0); + withConfig(context, Map.of("edc.sql.store.vault.initdata", "foo:::123")); + + start(context, factory); + + verify(monitor).warning(contains("key foo")); + } + + @Test + void start_storesSecretsFromDirectory(ServiceExtensionContext context, ObjectFactory factory) throws Exception { + Files.writeString(tempDir.resolve("file-secret-one"), "value-one\n"); + Files.writeString(tempDir.resolve("file-secret-two"), "value-two"); + Files.createDirectory(tempDir.resolve("subdir")); + withConfig(context, Map.of("edc.sql.store.vault.directory", tempDir.toString())); + + start(context, factory); + + verify(queryExecutor).execute(eq(connection), contains(UPSERT), eq("file-secret-one"), eq("value-one")); + verify(queryExecutor).execute(eq(connection), contains(UPSERT), eq("file-secret-two"), eq("value-two")); + verify(queryExecutor, never()).execute(any(), anyString(), eq("subdir"), any()); + } + + @Test + void start_warnsWhenDirectoryIsMissing(ServiceExtensionContext context, ObjectFactory factory) { + var missing = tempDir.resolve("does-not-exist"); + withConfig(context, Map.of("edc.sql.store.vault.directory", missing.toString())); + + start(context, factory); + + verify(monitor).warning(contains("No init data directory found")); + verify(queryExecutor, never()).execute(any(), anyString(), any(Object[].class)); + } + + private void withConfig(ServiceExtensionContext context, Map settings) { + var config = new HashMap<>(settings); + // never fall back to the real default directory of the machine running the tests + config.putIfAbsent("edc.sql.store.vault.directory", tempDir.resolve("unused").toString()); + when(context.getConfig()).thenReturn(ConfigFactory.fromMap(config)); + } + + private void start(ServiceExtensionContext context, ObjectFactory factory) { + var extension = factory.constructInstance(SqlVaultExtension.class); + extension.initialize(context); + extension.provideSqlVault(context); + extension.start(); + } +} diff --git a/edc-extensions/sql-vault/src/test/java/de/fraunhofer/isst/edc/extension/sqlvault/dev/SqlVaultTest.java b/edc-extensions/sql-vault/src/test/java/de/fraunhofer/isst/edc/extension/sqlvault/dev/SqlVaultTest.java new file mode 100644 index 0000000000..589bb262a2 --- /dev/null +++ b/edc-extensions/sql-vault/src/test/java/de/fraunhofer/isst/edc/extension/sqlvault/dev/SqlVaultTest.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2026 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. (represented by Fraunhofer ISST) + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package de.fraunhofer.isst.edc.extension.sqlvault.dev; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.edc.spi.monitor.Monitor; +import org.eclipse.edc.sql.QueryExecutor; +import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; +import org.eclipse.edc.transaction.spi.NoopTransactionContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.sql.Connection; +import java.sql.SQLException; +import javax.sql.DataSource; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.contains; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.RETURNS_SELF; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +class SqlVaultTest { + + private static final String DATASOURCE = "vault-ds"; + + private final DataSourceRegistry dataSourceRegistry = mock(); + private final DataSource dataSource = mock(); + private final Connection connection = mock(); + private final QueryExecutor queryExecutor = mock(); + private final Monitor monitor = mock(Monitor.class, RETURNS_SELF); + + private SqlVault vault; + + @BeforeEach + void setUp() throws SQLException { + when(dataSourceRegistry.resolve(DATASOURCE)).thenReturn(dataSource); + when(dataSource.getConnection()).thenReturn(connection); + vault = new SqlVault(dataSourceRegistry, DATASOURCE, new NoopTransactionContext(), new ObjectMapper(), + queryExecutor, monitor); + } + + @Test + void resolveSecret_returnsStoredValue() throws SQLException { + when(queryExecutor.single(eq(connection), eq(false), any(), contains("SELECT secret FROM sql_vault"), eq("foo"))) + .thenReturn("bar"); + + assertThat(vault.resolveSecret("foo")).isEqualTo("bar"); + verify(connection).close(); + } + + @Test + void resolveSecret_returnsNullWhenNotFound() { + when(queryExecutor.single(any(), eq(false), any(), anyString(), eq("unknown"))).thenReturn(null); + + assertThat(vault.resolveSecret("unknown")).isNull(); + } + + @Test + void resolveSecret_returnsNullAndLogsOnError() throws SQLException { + when(dataSource.getConnection()).thenThrow(new SQLException("db down")); + + assertThat(vault.resolveSecret("foo")).isNull(); + verify(monitor).severe(contains("foo"), isA(SQLException.class)); + } + + @Test + void storeSecret_upsertsKeyAndValue() throws SQLException { + when(queryExecutor.execute(eq(connection), contains("ON CONFLICT (id) DO UPDATE"), eq("foo"), eq("bar"))) + .thenReturn(1); + + assertThat(vault.storeSecret("foo", "bar")).isSucceeded(); + verify(connection).close(); + } + + @Test + void storeSecret_failsWhenNoRowWasChanged() { + when(queryExecutor.execute(any(), anyString(), any(Object[].class))).thenReturn(0); + + assertThat(vault.storeSecret("foo", "bar")).isFailed(); + } + + @Test + void storeSecret_failsOnDatabaseError() throws SQLException { + when(dataSource.getConnection()).thenThrow(new SQLException("db down")); + + assertThat(vault.storeSecret("foo", "bar")).isFailed().detail().contains("db down"); + } + + @Test + void deleteSecret_deletesKey() { + when(queryExecutor.execute(eq(connection), contains("DELETE FROM sql_vault"), eq("foo"))).thenReturn(1); + + assertThat(vault.deleteSecret("foo")).isSucceeded(); + } + + @Test + void deleteSecret_failsWhenKeyDoesNotExist() { + when(queryExecutor.execute(eq(connection), contains("DELETE FROM sql_vault"), eq("unknown"))).thenReturn(0); + + assertThat(vault.deleteSecret("unknown")).isFailed(); + } + + @Test + void partitionedMethods_delegateToDefaultMethods() { + when(queryExecutor.execute(eq(connection), contains("ON CONFLICT"), eq("foo"), eq("bar"))).thenReturn(1); + when(queryExecutor.single(eq(connection), eq(false), any(), anyString(), eq("foo"))).thenReturn("bar"); + + assertThat(vault.storeSecret("some-partition", "foo", "bar")).isSucceeded(); + assertThat(vault.resolveSecret("some-partition", "foo")).isEqualTo("bar"); + } +} diff --git a/gradle.properties b/gradle.properties index e4215b2eb1..c37c26d6db 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ txWebsiteUrl=https://github.com/eclipse-tractusx/tractusx-edc.git txScmUrl=https://github.com/eclipse-tractusx/tractusx-edc.git # construction-x-properties -con-x-edcVersion=0.17.0 +con-x-edcVersion=0.18.2 diff --git a/resources/Dockerfile b/resources/Dockerfile index 63ee68aab5..d9f4b0025b 100644 --- a/resources/Dockerfile +++ b/resources/Dockerfile @@ -19,7 +19,7 @@ # SPDX-License-Identifier: Apache-2.0 ################################################################################# -FROM eclipse-temurin:25-jre-alpine@sha256:28db6fdf60e38945e43d840c0333aeaec66c15943070104f7586fd3c9d1665b0 +FROM eclipse-temurin:25-jre-alpine@sha256:69c2a26e9894016e274c880fa542956d005b3755f84db765145185e87405bd89 RUN apk upgrade --no-cache \ && rm -rf /var/cache/apk/*