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

chore: re-enabled IATP E2E tests #1012

Merged
merged 3 commits into from
Jan 31, 2024
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
304 changes: 145 additions & 159 deletions DEPENDENCIES

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@
package org.eclipse.tractusx.edc.edr.store.sql.schema;

import org.eclipse.edc.spi.query.QuerySpec;
import org.eclipse.edc.sql.translation.SqlOperatorTranslator;
import org.eclipse.edc.sql.translation.SqlQueryStatement;

import static java.lang.String.format;

public class BaseSqlEdrStatements implements EdrStatements {

private final SqlOperatorTranslator sqlOperatorTranslator;

public BaseSqlEdrStatements(SqlOperatorTranslator sqlOperatorTranslator) {
this.sqlOperatorTranslator = sqlOperatorTranslator;
}

@Override
public String getFindByTransferProcessIdTemplate() {
return format("SELECT * FROM %s WHERE %s = ?", getEdrTable(), getTransferProcessIdColumn());
Expand All @@ -29,7 +36,7 @@ public String getFindByTransferProcessIdTemplate() {
@Override
public SqlQueryStatement createQuery(QuerySpec querySpec) {
var select = format("SELECT * FROM %s", getEdrTable());
return new SqlQueryStatement(select, querySpec, new EdrMapping(this));
return new SqlQueryStatement(select, querySpec, new EdrMapping(this), sqlOperatorTranslator);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@

package org.eclipse.tractusx.edc.edr.store.sql.schema.postgres;

import org.eclipse.edc.sql.translation.PostgresqlOperatorTranslator;
import org.eclipse.tractusx.edc.edr.store.sql.schema.BaseSqlEdrStatements;

public class PostgresEdrStatements extends BaseSqlEdrStatements {


public PostgresEdrStatements() {
super(new PostgresqlOperatorTranslator());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,10 @@ public String getProtocol() {
public String getCounterPartyAddress() {
return "test";
}

@Override
public String getCounterPartyId() {
return "id";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Provides;
import org.eclipse.edc.runtime.metamodel.annotation.Setting;
import org.eclipse.edc.spi.iam.AudienceResolver;
import org.eclipse.edc.spi.iam.IdentityService;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.types.domain.message.RemoteMessage;
import org.eclipse.edc.token.spi.TokenValidationRulesRegistry;
import org.eclipse.tractusx.edc.iam.ssi.identity.rule.SsiAudienceValidationRule;
import org.eclipse.tractusx.edc.iam.ssi.spi.SsiCredentialClient;
import org.eclipse.tractusx.edc.iam.ssi.spi.SsiTokenValidationService;

import static org.eclipse.tractusx.edc.iam.ssi.spi.SsiConstants.SSI_TOKEN_CONTEXT;

@Provides({ IdentityService.class, SsiTokenValidationService.class })
@Provides({ IdentityService.class, SsiTokenValidationService.class, AudienceResolver.class })
@Extension(SsiIdentityServiceExtension.EXTENSION_NAME)
public class SsiIdentityServiceExtension implements ServiceExtension {

Expand Down Expand Up @@ -58,6 +60,7 @@ public void initialize(ServiceExtensionContext context) {

context.registerService(IdentityService.class, identityService);
context.registerService(SsiTokenValidationService.class, tokenValidationService);
context.registerService(AudienceResolver.class, RemoteMessage::getCounterPartyAddress);
}

private void configureRules(ServiceExtensionContext context, TokenValidationRulesRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
package org.eclipse.tractusx.edc.lifecycle;

import org.eclipse.edc.junit.extensions.EdcRuntimeExtension;
import org.eclipse.edc.spi.iam.AudienceResolver;
import org.eclipse.edc.spi.iam.IdentityService;
import org.eclipse.edc.spi.security.Vault;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.system.injection.InjectionContainer;
import org.eclipse.edc.spi.types.domain.message.RemoteMessage;
import org.eclipse.tractusx.edc.token.MockBpnIdentityService;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
Expand All @@ -42,6 +44,7 @@ public ParticipantRuntime(String moduleName, String runtimeName, String bpn, Map
this.properties = properties;
if (!properties.containsKey("tx.ssi.miw.url") && !properties.containsKey("edc.iam.issuer.id")) {
this.registerServiceMock(IdentityService.class, new MockBpnIdentityService(bpn));
this.registerServiceMock(AudienceResolver.class, RemoteMessage::getCounterPartyAddress);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import jakarta.json.JsonObject;
import org.eclipse.edc.iam.did.spi.document.DidDocument;
import org.eclipse.edc.iam.did.spi.document.VerificationMethod;
import org.eclipse.edc.identityhub.spi.store.model.VerifiableCredentialResource;
import org.eclipse.edc.identityhub.spi.model.VerifiableCredentialResource;
import org.eclipse.edc.identitytrust.model.CredentialFormat;
import org.eclipse.edc.identitytrust.model.CredentialSubject;
import org.eclipse.edc.identitytrust.model.Issuer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Map<String, String> iatpConfiguration(TxParticipant... others) {
{

put("edc.iam.sts.oauth.token.url", stsUri + "/token");
put("edc.iam.sts.oauth.client.id", did);
put("edc.iam.sts.oauth.client.id", getBpn());
put("edc.iam.sts.oauth.client.secret.alias", "client_secret_alias");
put("edc.iam.issuer.id", did);
put("edc.ih.iam.id", participant.getBpn());
Expand All @@ -90,8 +90,11 @@ public Map<String, String> iatpConfiguration(TxParticipant... others) {

Stream.concat(Stream.of(participant), Arrays.stream(others)).forEach(p -> {
var prefix = format("tx.iam.iatp.audiences.%s", p.getName().toLowerCase());
iatpConfiguration.put(prefix + ".from", p.getProtocolEndpoint().getUrl().toString());
iatpConfiguration.put(prefix + ".to", p.getBpn());
var participantDid = DID_EXAMPLE + p.getName().toLowerCase();
iatpConfiguration.put(prefix + "_endpoint" + ".from", p.getProtocolEndpoint().getUrl().toString());
iatpConfiguration.put(prefix + "_endpoint" + ".to", participantDid);
iatpConfiguration.put(prefix + "_id" + ".from", p.getBpn());
iatpConfiguration.put(prefix + "_id" + ".to", participantDid);
});
return iatpConfiguration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import static java.lang.String.format;
import static org.eclipse.edc.junit.testfixtures.TestUtils.getFreePort;
Expand Down Expand Up @@ -49,8 +50,9 @@ public Map<String, String> stsConfiguration(IatpParticipant... participants) {
Arrays.stream(participants).forEach(participant -> {
var prefix = format("edc.iam.sts.clients.%s", participant.getName().toLowerCase());
stsConfiguration.put(prefix + ".name", participant.getName());
stsConfiguration.put(prefix + ".id", participant.didUrl());
stsConfiguration.put(prefix + ".id", UUID.randomUUID().toString());
stsConfiguration.put(prefix + ".client_id", participant.getBpn());
stsConfiguration.put(prefix + ".did", participant.didUrl());
stsConfiguration.put(prefix + ".secret.alias", "client_secret_alias");
stsConfiguration.put(prefix + ".private-key.alias", participant.verificationId());
stsConfiguration.put(prefix + ".public-key.reference", participant.verificationId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@

import jakarta.json.JsonObject;
import org.eclipse.edc.junit.annotations.EndToEndTest;
import org.junit.jupiter.api.Disabled;

import java.util.Map;

import static org.eclipse.tractusx.edc.helpers.PolicyHelperFunctions.TX_CREDENTIAL_NAMESPACE;
import static org.eclipse.tractusx.edc.helpers.PolicyHelperFunctions.frameworkPolicy;

@EndToEndTest
// waiting for https://github.com/eclipse-edc/Connector/issues/3796
@Disabled
public class IatpFrameworkAgreementHttpConsumerPullWithProxyInMemoryTest extends IatpHttpConsumerPullWithProxyInMemoryTest {

@Override
protected JsonObject createContractPolicy(String bpn) {
return frameworkPolicy(Map.of(TX_CREDENTIAL_NAMESPACE + "FrameworkAgreement.pcf", "active"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import org.eclipse.edc.iam.did.spi.document.DidDocument;
import org.eclipse.edc.iam.did.spi.resolution.DidResolverRegistry;
import org.eclipse.edc.identityhub.spi.generator.PresentationCreatorRegistry;
import org.eclipse.edc.identityhub.spi.model.VerifiableCredentialResource;
import org.eclipse.edc.identityhub.spi.store.CredentialStore;
import org.eclipse.edc.identityhub.spi.store.model.VerifiableCredentialResource;
import org.eclipse.edc.identitytrust.model.CredentialFormat;
import org.eclipse.edc.jsonld.spi.JsonLd;
import org.eclipse.edc.junit.annotations.EndToEndTest;
Expand All @@ -31,7 +31,6 @@
import org.eclipse.tractusx.edc.lifecycle.tx.iatp.SecureTokenService;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.IOException;
Expand All @@ -43,8 +42,6 @@
import static org.eclipse.tractusx.edc.helpers.PolicyHelperFunctions.frameworkPolicy;

@EndToEndTest
// waiting for https://github.com/eclipse-edc/Connector/issues/3796
@Disabled
public class IatpHttpConsumerPullWithProxyInMemoryTest extends AbstractHttpConsumerPullWithProxyTest {

protected static final DataspaceIssuer DATASPACE_ISSUER_PARTICIPANT = new DataspaceIssuer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

package org.eclipse.tractusx.edc.iatp;

import org.eclipse.edc.identitytrust.AudienceResolver;
import org.eclipse.edc.spi.iam.AudienceResolver;
import org.eclipse.edc.spi.types.domain.message.RemoteMessage;

import java.util.Map;
import java.util.Optional;
Expand All @@ -31,8 +32,7 @@ public TestAudienceMapper(Map<String, String> audienceMapping) {
}

@Override
public String resolve(String s) {
return Optional.ofNullable(audienceMapping.get(s)).orElse(s);
public String resolve(RemoteMessage remoteMessage) {
return Optional.ofNullable(audienceMapping.get(remoteMessage.getCounterPartyId())).orElse(remoteMessage.getCounterPartyId());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

package org.eclipse.tractusx.edc.iatp;

import org.eclipse.edc.identitytrust.AudienceResolver;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.runtime.metamodel.annotation.Setting;
import org.eclipse.edc.spi.iam.AudienceResolver;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;

import java.util.HashMap;

@Extension("Audience mapper extension")
public class TestAudienceMapperExtension implements ServiceExtension {

@Setting
private static final String TX_IATP_AUDIENCES = "tx.iam.iatp.audiences";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.edc.policy.model.Permission;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.spi.agent.ParticipantAgentService;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;

Expand All @@ -41,6 +42,9 @@ public class CredentialPolicyEvaluationExtension implements ServiceExtension {
private RuleBindingRegistry ruleBindingRegistry;


@Inject
private ParticipantAgentService participantAgentService;

@Override
public void initialize(ServiceExtensionContext context) {

Expand All @@ -55,6 +59,8 @@ public void initialize(ServiceExtensionContext context) {
registerUseCase("sustainability");
registerUseCase("quality");
registerUseCase("resiliency");

participantAgentService.register(new IdentityExtractor());
}

private void bindPermissionFunction(AtomicConstraintFunction<Permission> function, String scope, String constraintType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* 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
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
*
*/

package org.eclipse.tractusx.edc.iatp.policy;

import org.eclipse.edc.spi.agent.ParticipantAgentServiceExtension;
import org.eclipse.edc.spi.iam.ClaimToken;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

import static org.eclipse.edc.spi.agent.ParticipantAgent.PARTICIPANT_IDENTITY;

public class IdentityExtractor implements ParticipantAgentServiceExtension {
@Override
public @NotNull Map<String, String> attributesFor(ClaimToken claimToken) {
return Map.of(PARTICIPANT_IDENTITY, getClaim(String.class, "holderIdentifier", claimToken.getClaims()));
}

protected <T> T getClaim(Class<T> type, String postfix, Map<String, Object> claims) {
return claims.entrySet().stream().filter(e -> e.getKey().endsWith(postfix))
.findFirst()
.map(Map.Entry::getValue)
.map(type::cast)
.orElse(null);
}
}
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
format.version = "1.1"

[versions]
edc = "0.5.0"
edc = "0.5.1-20240131-SNAPSHOT"
postgres = "42.7.1"
awaitility = "4.2.0"
nimbus = "9.37.3"
Expand Down Expand Up @@ -158,7 +158,7 @@ edc-micrometer-core = { module = "org.eclipse.edc:micrometer-core", version.ref
edc-micrometer-jersey = { module = "org.eclipse.edc:jersey-micrometer", version.ref = "edc" }
edc-micrometer-jetty = { module = "org.eclipse.edc:jetty-micrometer", version.ref = "edc" }
edc-monitor-jdklogger = { module = "org.eclipse.edc:monitor-jdk-logger", version.ref = "edc" }
edc-transfer-dynamicreceiver = { module = "org.eclipse.edc:transfer-pull-http-dynamic-receiver", version = "0.5.1-20240122-SNAPSHOT" }
edc-transfer-dynamicreceiver = { module = "org.eclipse.edc:transfer-pull-http-dynamic-receiver", version.ref = "edc" }
edc-transfer-receiver = { module = "org.eclipse.edc:transfer-pull-http-receiver", version.ref = "edc" }

# other deps
Expand Down
Loading