forked from sovity/edc-ce
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rework always-true policy definition (sovity#1005)
Co-authored-by: Richard Treier <[email protected]>
- Loading branch information
Showing
18 changed files
with
319 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Env variables for docker-compose.yaml | ||
EDC_IMAGE=ghcr.io/sovity/edc-dev:9.0.0 | ||
TEST_BACKEND_IMAGE=ghcr.io/sovity/test-backend:9.0.0 | ||
EDC_UI_IMAGE=ghcr.io/sovity/edc-ui:4.0.0 | ||
EDC_IMAGE=ghcr.io/sovity/edc-dev:10.0.0 | ||
TEST_BACKEND_IMAGE=ghcr.io/sovity/test-backend:10.0.0 | ||
EDC_UI_IMAGE=ghcr.io/sovity/edc-ui:4.1.0 | ||
EDC_UI_ACTIVE_PROFILE=sovity-open-source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...sions/postgres-flyway/src/main/resources/db/migration/V11__migrate_always_true_policy.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- | ||
-- Copyright (c) 2024 sovity GmbH | ||
-- | ||
-- 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: | ||
-- sovity GmbH - initial API and implementation | ||
-- | ||
|
||
update edc_policydefinitions | ||
set permissions = jsonb_set( | ||
permissions::jsonb, | ||
'{0,constraints}', | ||
'[]'::jsonb)::json | ||
where policy_id = 'always-true'; |
57 changes: 57 additions & 0 deletions
57
tests/src/test/java/de/sovity/edc/e2e/AlwaysTrueMigrationNewConsumerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package de.sovity.edc.e2e; | ||
|
||
import de.sovity.edc.client.EdcClient; | ||
import de.sovity.edc.client.gen.model.OperatorDto; | ||
import de.sovity.edc.client.gen.model.UiPolicyExpressionType; | ||
import de.sovity.edc.e2e.common.AlwaysTruePolicyMigrationCommonTest; | ||
import de.sovity.edc.extension.e2e.extension.Consumer; | ||
import de.sovity.edc.extension.e2e.extension.E2eScenario; | ||
import de.sovity.edc.extension.e2e.extension.E2eTestExtension; | ||
import de.sovity.edc.extension.e2e.extension.Provider; | ||
import de.sovity.edc.extension.policy.AlwaysTruePolicyConstants; | ||
import de.sovity.edc.extension.utils.junit.DisabledOnGithub; | ||
import lombok.val; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.mockserver.integration.ClientAndServer; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class AlwaysTrueMigrationNewConsumerTest { | ||
|
||
@RegisterExtension | ||
private static final E2eTestExtension E2E_TEST_EXTENSION = E2eTestExtension.builder() | ||
.additionalConsumerMigrationLocation("classpath:db/additional-test-data/always-true-policy-migrated") | ||
.additionalProviderMigrationLocation("classpath:db/additional-test-data/always-true-policy-legacy") | ||
.build(); | ||
|
||
@Test | ||
@DisabledOnGithub | ||
void always_true_agreements_still_work_after_migration( | ||
E2eScenario scenario, | ||
ClientAndServer mockServer, | ||
@Provider EdcClient providerClient, | ||
@Consumer EdcClient consumerClient | ||
) { | ||
// assert correct policies | ||
val oldAlwaysTruePolicyCreatedAfterMigration = providerClient.uiApi().getPolicyDefinitionPage().getPolicies().stream().filter( | ||
policy -> policy.getPolicyDefinitionId().equals(AlwaysTruePolicyConstants.POLICY_DEFINITION_ID) | ||
).findFirst().orElseThrow().getPolicy().getExpression(); | ||
|
||
val migratedAlwaysTruePolicy = consumerClient.uiApi().getPolicyDefinitionPage().getPolicies().stream().filter( | ||
policy -> policy.getPolicyDefinitionId().equals(AlwaysTruePolicyConstants.POLICY_DEFINITION_ID) | ||
).findFirst().orElseThrow().getPolicy().getExpression(); | ||
|
||
assertThat(oldAlwaysTruePolicyCreatedAfterMigration.getType()).isEqualTo(UiPolicyExpressionType.CONSTRAINT); | ||
assertThat(oldAlwaysTruePolicyCreatedAfterMigration.getConstraint().getLeft()).isEqualTo( | ||
AlwaysTruePolicyConstants.EXPRESSION_LEFT_VALUE); | ||
assertThat(oldAlwaysTruePolicyCreatedAfterMigration.getConstraint().getRight().getValue()).isEqualTo( | ||
AlwaysTruePolicyConstants.EXPRESSION_RIGHT_VALUE); | ||
assertThat(oldAlwaysTruePolicyCreatedAfterMigration.getConstraint().getOperator()).isEqualTo(OperatorDto.EQ); | ||
|
||
assertThat(migratedAlwaysTruePolicy.getType()).isEqualTo(UiPolicyExpressionType.EMPTY); | ||
assertThat(migratedAlwaysTruePolicy.getConstraint()).isNull(); | ||
|
||
AlwaysTruePolicyMigrationCommonTest.alwaysTruePolicyMigrationTest(scenario, mockServer, providerClient, consumerClient); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
tests/src/test/java/de/sovity/edc/e2e/AlwaysTrueMigrationNewProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package de.sovity.edc.e2e; | ||
|
||
import de.sovity.edc.client.EdcClient; | ||
import de.sovity.edc.client.gen.model.OperatorDto; | ||
import de.sovity.edc.client.gen.model.UiPolicyExpressionType; | ||
import de.sovity.edc.e2e.common.AlwaysTruePolicyMigrationCommonTest; | ||
import de.sovity.edc.extension.e2e.extension.Consumer; | ||
import de.sovity.edc.extension.e2e.extension.E2eScenario; | ||
import de.sovity.edc.extension.e2e.extension.E2eTestExtension; | ||
import de.sovity.edc.extension.e2e.extension.Provider; | ||
import de.sovity.edc.extension.policy.AlwaysTruePolicyConstants; | ||
import de.sovity.edc.extension.utils.junit.DisabledOnGithub; | ||
import lombok.val; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.mockserver.integration.ClientAndServer; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
class AlwaysTrueMigrationNewProviderTest { | ||
|
||
@RegisterExtension | ||
private static final E2eTestExtension E2E_TEST_EXTENSION = E2eTestExtension.builder() | ||
.additionalConsumerMigrationLocation("classpath:db/additional-test-data/alwaysTruePolicyMigrationTest") | ||
.additionalProviderMigrationLocation("") | ||
.build(); | ||
|
||
@Test | ||
@DisabledOnGithub | ||
void always_true_agreements_still_work_after_migration( | ||
E2eScenario scenario, | ||
ClientAndServer mockServer, | ||
@Provider EdcClient providerClient, | ||
@Consumer EdcClient consumerClient | ||
) { | ||
// assert correct policies | ||
val newAlwaysTruePolicyOnProvider = providerClient.uiApi().getPolicyDefinitionPage().getPolicies().stream().filter( | ||
policy -> policy.getPolicyDefinitionId().equals(AlwaysTruePolicyConstants.POLICY_DEFINITION_ID) | ||
).findFirst().orElseThrow().getPolicy().getExpression(); | ||
|
||
val oldAlwaysTruePolicyOnConsumer = consumerClient.uiApi().getPolicyDefinitionPage().getPolicies().stream().filter( | ||
policy -> policy.getPolicyDefinitionId().equals(AlwaysTruePolicyConstants.POLICY_DEFINITION_ID) | ||
).findFirst().orElseThrow().getPolicy().getExpression(); | ||
|
||
assertThat(oldAlwaysTruePolicyOnConsumer.getType()).isEqualTo(UiPolicyExpressionType.CONSTRAINT); | ||
assertThat(oldAlwaysTruePolicyOnConsumer.getConstraint().getLeft()).isEqualTo(AlwaysTruePolicyConstants.EXPRESSION_LEFT_VALUE); | ||
assertThat(oldAlwaysTruePolicyOnConsumer.getConstraint().getRight().getValue()).isEqualTo( | ||
AlwaysTruePolicyConstants.EXPRESSION_RIGHT_VALUE); | ||
assertThat(oldAlwaysTruePolicyOnConsumer.getConstraint().getOperator()).isEqualTo(OperatorDto.EQ); | ||
|
||
assertThat(newAlwaysTruePolicyOnProvider.getType()).isEqualTo(UiPolicyExpressionType.EMPTY); | ||
assertThat(newAlwaysTruePolicyOnProvider.getConstraint()).isNull(); | ||
|
||
AlwaysTruePolicyMigrationCommonTest.alwaysTruePolicyMigrationTest(scenario, mockServer, providerClient, consumerClient); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
tests/src/test/java/de/sovity/edc/e2e/common/AlwaysTruePolicyMigrationCommonTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package de.sovity.edc.e2e.common; | ||
|
||
import de.sovity.edc.client.EdcClient; | ||
import de.sovity.edc.client.gen.model.InitiateTransferRequest; | ||
import de.sovity.edc.client.gen.model.TransferProcessSimplifiedState; | ||
import de.sovity.edc.extension.e2e.extension.E2eScenario; | ||
import de.sovity.edc.utils.jsonld.vocab.Prop; | ||
import jakarta.ws.rs.HttpMethod; | ||
import lombok.val; | ||
import org.mockserver.integration.ClientAndServer; | ||
import org.mockserver.model.HttpRequest; | ||
import org.mockserver.model.HttpResponse; | ||
|
||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; | ||
|
||
public class AlwaysTruePolicyMigrationCommonTest { | ||
|
||
public static void alwaysTruePolicyMigrationTest(E2eScenario scenario, ClientAndServer mockServer, EdcClient providerClient, EdcClient consumerClient) { | ||
// arrange | ||
val destinationPath = "/destination/some/path/"; | ||
val destinationUrl = "http://localhost:" + mockServer.getPort() + destinationPath; | ||
mockServer.when(HttpRequest.request(destinationPath).withMethod("POST")).respond(it -> HttpResponse.response().withStatusCode(200)); | ||
|
||
val asset = scenario.createAsset(); | ||
scenario.createContractDefinition(asset); //this automatically uses the always-true policy | ||
val negotiation = scenario.negotiateAssetAndAwait(asset); | ||
|
||
// act | ||
val transfer = scenario.transferAndAwait( | ||
InitiateTransferRequest.builder() | ||
.contractAgreementId(negotiation.getContractAgreementId()) | ||
.dataSinkProperties( | ||
Map.of( | ||
Prop.Edc.BASE_URL, destinationUrl, | ||
Prop.Edc.METHOD, HttpMethod.POST, | ||
Prop.Edc.TYPE, "HttpData" | ||
) | ||
) | ||
.build() | ||
); | ||
val transferProcess = consumerClient.uiApi().getTransferHistoryPage().getTransferEntries().stream().filter( | ||
process -> process.getTransferProcessId().equals(transfer) | ||
).findFirst().orElseThrow(); | ||
|
||
// assert | ||
assertThat(transferProcess.getState().getSimplifiedState()).isEqualTo(TransferProcessSimplifiedState.OK); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ditional-test-data/always-true-policy-legacy/V11_1__test_always_true_policy_migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
insert into edc.public.edc_policydefinitions | ||
(policy_id, permissions, prohibitions, duties, extensible_properties, policy_type, created_at) | ||
values ('always-true', '[ | ||
{ | ||
"edctype": "dataspaceconnector:permission", | ||
"target": null, | ||
"action": { | ||
"type": "USE", | ||
"includedIn": null, | ||
"constraint": null | ||
}, | ||
"assignee": null, | ||
"assigner": null, | ||
"constraints": [ | ||
{ | ||
"edctype": "AtomicConstraint", | ||
"leftExpression": { | ||
"edctype": "dataspaceconnector:literalexpression", | ||
"value": "ALWAYS_TRUE" | ||
}, | ||
"rightExpression": { | ||
"edctype": "dataspaceconnector:literalexpression", | ||
"value": "true" | ||
}, | ||
"operator": "EQ" | ||
} | ||
], | ||
"duties": [] | ||
} | ||
]', | ||
'[]', | ||
'[]', | ||
'{}', | ||
'{"@policytype":"set"}', | ||
1721740661) |
35 changes: 35 additions & 0 deletions
35
...tional-test-data/always-true-policy-migrated/V10_1__test_always_true_policy_migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
insert into edc.public.edc_policydefinitions | ||
(policy_id, permissions, prohibitions, duties, extensible_properties, policy_type, created_at) | ||
values ('always-true', '[ | ||
{ | ||
"edctype": "dataspaceconnector:permission", | ||
"target": null, | ||
"action": { | ||
"type": "USE", | ||
"includedIn": null, | ||
"constraint": null | ||
}, | ||
"assignee": null, | ||
"assigner": null, | ||
"constraints": [ | ||
{ | ||
"edctype": "AtomicConstraint", | ||
"leftExpression": { | ||
"edctype": "dataspaceconnector:literalexpression", | ||
"value": "ALWAYS_TRUE" | ||
}, | ||
"rightExpression": { | ||
"edctype": "dataspaceconnector:literalexpression", | ||
"value": "true" | ||
}, | ||
"operator": "EQ" | ||
} | ||
], | ||
"duties": [] | ||
} | ||
]', | ||
'[]', | ||
'[]', | ||
'{}', | ||
'{"@policytype":"set"}', | ||
1721740661) |
Oops, something went wrong.