Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Apr 5, 2024
1 parent ed6240f commit e399f9f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.jupiter.api.Test;

import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat;
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.AUDIENCE_PROPERTY;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -45,7 +46,7 @@ void propertiesFor() {
var result = provider.propertiesFor(TransferProcess.Builder.newInstance().build(), Policy.Builder.newInstance().assignee(bpn).build());

assertThat(result).isSucceeded().satisfies(properties -> {
Assertions.assertThat(properties).containsEntry("audience", did);
Assertions.assertThat(properties).containsEntry(AUDIENCE_PROPERTY, did);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat;
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.AUDIENCE_PROPERTY;
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.EDR_PROPERTY_EXPIRES_IN;
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.EDR_PROPERTY_REFRESH_ENDPOINT;
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.EDR_PROPERTY_REFRESH_TOKEN;
Expand Down Expand Up @@ -112,7 +113,7 @@ void setup() throws JOSEException {
@Test
void obtainToken() {
var tokenId = "test-token-id";
var edr = tokenRefreshService.obtainToken(tokenParams(tokenId), DataAddress.Builder.newInstance().type("test-type").build(), Map.of("audience", CONSUMER_DID));
var edr = tokenRefreshService.obtainToken(tokenParams(tokenId), DataAddress.Builder.newInstance().type("test-type").build(), Map.of(AUDIENCE_PROPERTY, CONSUMER_DID));
assertThat(edr).isSucceeded();
// assert access token contents
assertThat(asClaims(edr.getContent().getToken()))
Expand All @@ -132,7 +133,7 @@ void obtainToken() {
assertThat(storedData).isNotNull();
assertThat(storedData.additionalProperties())
.hasSize(2)
.containsEntry("audience", CONSUMER_DID)
.containsEntry(AUDIENCE_PROPERTY, CONSUMER_DID)
.containsEntry("authType", "bearer");

}
Expand All @@ -142,7 +143,7 @@ void obtainToken() {
void refresh_success() throws JOSEException {

var tokenId = "test-token-id";
var edr = tokenRefreshService.obtainToken(tokenParams(tokenId), DataAddress.Builder.newInstance().type("test-type").build(), Map.of("audience", CONSUMER_DID))
var edr = tokenRefreshService.obtainToken(tokenParams(tokenId), DataAddress.Builder.newInstance().type("test-type").build(), Map.of(AUDIENCE_PROPERTY, CONSUMER_DID))
.orElseThrow(f -> new RuntimeException(f.getFailureDetail()));

var accessToken = edr.getToken();
Expand Down Expand Up @@ -170,7 +171,7 @@ void refresh_originalTokenWasIssuedToDifferentPrincipal() throws JOSEException {


var tokenId = "test-token-id";
var edr = tokenRefreshService.obtainToken(tokenParams(tokenId), DataAddress.Builder.newInstance().type("test-type").build(), Map.of("audience", "did:web:trudy"))
var edr = tokenRefreshService.obtainToken(tokenParams(tokenId), DataAddress.Builder.newInstance().type("test-type").build(), Map.of(AUDIENCE_PROPERTY, "did:web:trudy"))
.orElseThrow(f -> new RuntimeException(f.getFailureDetail()));

// bob attempts to create an auth token with an EDR he stole from trudy
Expand All @@ -193,7 +194,7 @@ void refresh_issuerNotVerifiable() throws JOSEException {
when(didPkResolverMock.resolveKey(eq(trudyKey.getKeyID()))).thenReturn(Result.success(trudyKey.toPublicKey()));

var tokenId = "test-token-id";
var edr = tokenRefreshService.obtainToken(tokenParams(tokenId), DataAddress.Builder.newInstance().type("test-type").build(), Map.of("audience", "did:web:trudy"))
var edr = tokenRefreshService.obtainToken(tokenParams(tokenId), DataAddress.Builder.newInstance().type("test-type").build(), Map.of(AUDIENCE_PROPERTY, "did:web:trudy"))
.orElseThrow(f -> new RuntimeException(f.getFailureDetail()));

// bob poses as trudy, using her key-ID and DID, but has to use his own private key
Expand All @@ -212,7 +213,7 @@ void refresh_issuerNotVerifiable() throws JOSEException {
@Test
void refresh_whenNoAccessTokenClaim() throws JOSEException {
var tokenId = "test-token-id";
var edr = tokenRefreshService.obtainToken(tokenParams(tokenId), DataAddress.Builder.newInstance().type("test-type").build(), Map.of("audience", CONSUMER_DID))
var edr = tokenRefreshService.obtainToken(tokenParams(tokenId), DataAddress.Builder.newInstance().type("test-type").build(), Map.of(AUDIENCE_PROPERTY, CONSUMER_DID))
.orElseThrow(f -> new RuntimeException(f.getFailureDetail()));

var accessToken = edr.getToken();
Expand All @@ -232,7 +233,7 @@ void refresh_whenNoAccessTokenClaim() throws JOSEException {
@Test
void refresh_whenIssNotEqualToSub() throws JOSEException {
var tokenId = "test-token-id";
var edr = tokenRefreshService.obtainToken(tokenParams(tokenId), DataAddress.Builder.newInstance().type("test-type").build(), Map.of("audience", CONSUMER_DID))
var edr = tokenRefreshService.obtainToken(tokenParams(tokenId), DataAddress.Builder.newInstance().type("test-type").build(), Map.of(AUDIENCE_PROPERTY, CONSUMER_DID))
.orElseThrow(f -> new RuntimeException(f.getFailureDetail()));

var accessToken = edr.getToken();
Expand Down Expand Up @@ -260,7 +261,7 @@ void resolve_whenExpired_shouldFail() {
.claims(JwtRegisteredClaimNames.ISSUED_AT, Instant.now().minusSeconds(600).getEpochSecond())
.claims(JwtRegisteredClaimNames.EXPIRATION_TIME, Instant.now().minusSeconds(300).getEpochSecond())
.build(),
DataAddress.Builder.newInstance().type("test-type").build(), Map.of("audience", CONSUMER_DID))
DataAddress.Builder.newInstance().type("test-type").build(), Map.of(AUDIENCE_PROPERTY, CONSUMER_DID))
.orElseThrow(f -> new RuntimeException(f.getFailureDetail()));

assertThat(tokenRefreshService.resolve(edr.getToken())).isFailed()
Expand All @@ -275,7 +276,7 @@ void resolve_success() {
var edr = tokenRefreshService.obtainToken(tokenParamsBuilder(tokenId)
.claims(JwtRegisteredClaimNames.ISSUED_AT, Instant.now().getEpochSecond())
.build(),
DataAddress.Builder.newInstance().type("test-type").build(), Map.of("audience", CONSUMER_DID))
DataAddress.Builder.newInstance().type("test-type").build(), Map.of(AUDIENCE_PROPERTY, CONSUMER_DID))
.orElseThrow(f -> new RuntimeException(f.getFailureDetail()));

assertThat(tokenRefreshService.resolve(edr.getToken())).isSucceeded();
Expand All @@ -288,7 +289,7 @@ void resolve_notFound() {
var edr = tokenRefreshService.obtainToken(tokenParamsBuilder(tokenId)
.claims(JwtRegisteredClaimNames.ISSUED_AT, Instant.now().getEpochSecond())
.build(),
DataAddress.Builder.newInstance().type("test-type").build(), Map.of("audience", CONSUMER_DID))
DataAddress.Builder.newInstance().type("test-type").build(), Map.of(AUDIENCE_PROPERTY, CONSUMER_DID))
.orElseThrow(f -> new RuntimeException(f.getFailureDetail()));
tokenDataStore.deleteById(tokenId).orElseThrow(f -> new AssertionError(f.getFailureDetail()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE;
import static org.eclipse.edc.util.io.Ports.getFreePort;
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.EDR_PROPERTY_EXPIRES_IN;
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.EDR_PROPERTY_REFRESH_AUDIENCE;
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.EDR_PROPERTY_REFRESH_ENDPOINT;
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.EDR_PROPERTY_REFRESH_TOKEN;
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
Expand Down Expand Up @@ -85,6 +86,7 @@ public class EdrCacheApiEndToEndTest {
with(SOKRATES.getConfiguration(), Map.of("edc.iam.issuer.id", "did:web:sokrates")));
private final ObjectMapper mapper = new ObjectMapper();
private String refreshEndpoint;
private String refreshAudience;
private ClientAndServer mockedRefreshApi;
private ECKey providerSigningKey;

Expand All @@ -99,6 +101,7 @@ void setup() throws JOSEException {
providerSigningKey = new ECKeyGenerator(Curve.P_256).keyID("did:web:provider#key-1").generate();
var port = getFreePort();
refreshEndpoint = "http://localhost:%s/refresh".formatted(port);
refreshAudience = "did:web:sokrates";
mockedRefreshApi = startClientAndServer(port);
}

Expand Down Expand Up @@ -305,6 +308,7 @@ private void storeEdr(String transferProcessId, boolean isExpired) {
.property(EDR_PROPERTY_REFRESH_TOKEN, createJwt(providerSigningKey, new JWTClaimsSet.Builder().build()))
.property(EDR_PROPERTY_EXPIRES_IN, "300")
.property(EDR_PROPERTY_REFRESH_ENDPOINT, refreshEndpoint)
.property(EDR_PROPERTY_REFRESH_AUDIENCE, refreshAudience)
.build();
var entry = EndpointDataReferenceEntry.Builder.newInstance()
.clock(isExpired ? // defaults to an expired token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import static org.apache.http.HttpHeaders.AUTHORIZATION;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE;
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.AUDIENCE_PROPERTY;
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.TX_AUTH_NS;
import static org.hamcrest.Matchers.containsString;

Expand Down Expand Up @@ -361,7 +362,7 @@ private DataFlowStartMessage createStartMessage(String processId, String audienc
.assetId("test-asset")
.callbackAddress(URI.create("https://foo.bar/callback"))
.agreementId("test-agreement")
.property("audience", audience)
.property(AUDIENCE_PROPERTY, audience)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies {
// use basic (all in-mem) control plane
implementation(project(":edc-controlplane:edc-controlplane-base")) {
exclude(module = "bdrs-client")
exclude("org.eclipse.edc", "identity-trust-issuers-configuration")
}
implementation(project(":core:json-ld-core"))
implementation(project(":edc-extensions:cx-policy"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
implementation(project(":edc-controlplane:edc-controlplane-base")) {
exclude(module = "bdrs-client")
exclude(module = "tx-iatp-sts-dim")
exclude("org.eclipse.edc", "identity-trust-issuers-configuration")
}
implementation(project(":edc-extensions:cx-policy"))
implementation(project(":core:json-ld-core"))
Expand Down
1 change: 1 addition & 0 deletions edc-tests/runtime/iatp/runtime-memory-sts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
exclude(module = "ssi-miw-credential-client")
exclude(module = "ssi-identity-extractor")
exclude(module = "tx-iatp-sts-dim")
exclude("org.eclipse.edc", "identity-trust-issuers-configuration")
}
implementation(project(":core:json-ld-core"))
implementation(project(":edc-tests:runtime:extensions"))
Expand Down

0 comments on commit e399f9f

Please sign in to comment.