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

IRS Policy Validation accepts subset of AND constraint #649

Closed
2 of 6 tasks
ds-jhartmann opened this issue May 15, 2024 · 7 comments
Closed
2 of 6 tasks

IRS Policy Validation accepts subset of AND constraint #649

ds-jhartmann opened this issue May 15, 2024 · 7 comments
Assignees
Labels
Milestone

Comments

@ds-jhartmann
Copy link
Contributor

ds-jhartmann commented May 15, 2024

Description

Current behaviour

When IRS accepted policy has a AND constraint with 2 constraints and the EDC offer policy has a AND constraint with 1 constraint, IRS accepts the Policy if one of the IRS accepted policies matches the EDC offer policy AND constraint.

Expected behavior

  • IRS accepted Policies have to match exactly the EDC offer policy.

Steps to reproduce the Bug

  • IRS accepted Policy with AND constraint A1 and A2
  • EDC offer with AND constraint A1
  • IRS job with contract negotiation.
    • actual: Negotiation is started with IRS accepting the policy
    • expected: Negotiation is aborted with IRS not accepting the policy because constraint A2 is missing in EDC offer
@github-project-automation github-project-automation bot moved this to inbox in IRS May 15, 2024
@ds-jhartmann ds-jhartmann added the bug Something isn't working label May 15, 2024
@ds-jhartmann ds-jhartmann changed the title IRS Policy Validation with and constraint too flexible IRS Policy Validation accepts subset of AND constraint May 15, 2024
@mkanal mkanal moved this from inbox to backlog in IRS Jun 5, 2024
ds-jhartmann pushed a commit to ds-jhartmann/item-relationship-service that referenced this issue Jun 13, 2024
…adjust-tavern-tests-to-http-206-code

feature/eclipse-tractusx#279: Added and adjusted tavern tests to http code 206 for running jobs
@mkanal mkanal moved this from backlog to next in IRS Jul 9, 2024
@ds-jhartmann
Copy link
Contributor Author

ds-jhartmann commented Jul 9, 2024

Planning 2

Check for policies is done here

public boolean hasAllConstraint(final Policy acceptedPolicy, final List<Constraint> constraints) {
final List<Constraints> acceptedConstraintsList = acceptedPolicy.getPermissions()
.stream()
.map(Permission::getConstraint)
.toList();
return constraints.stream().allMatch(constraint -> isValidOnList(constraint, acceptedConstraintsList));
}
private boolean isValidOnList(final Constraint constraint, final List<Constraints> acceptedConstraintsList) {
return acceptedConstraintsList.stream()
.anyMatch(acceptedConstraints -> isSameAs(constraint, acceptedConstraints));
}

Make sure that and constraints match for all constraints

This Test should validate that the check is working as expected: https://github.com/eclipse-tractusx/item-relationship-service/blob/a45960ba21905403ef6d55883709ad0e817221ac/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintCheckerServiceTest.java

    @Test
    void shouldNotAcceptAndConstraintWithOneLessElement1() {
        final AndConstraint andConstraint = createAndConstraint(
                List.of(createAtomicConstraint(TestConstants.FRAMEWORK_AGREEMENT_TRACEABILITY,
                                TestConstants.STATUS_ACTIVE),
                        createAtomicConstraint(TestConstants.PURPOSE, TestConstants.ID_3_1_TRACE)));

        final Policy acceptedPolicy = createPolicyWithAndConstraint(
                List.of(new Operand(TestConstants.FRAMEWORK_AGREEMENT_TRACEABILITY, TestConstants.STATUS_ACTIVE),
                        new Operand(TestConstants.MEMBERSHIP, TestConstants.STATUS_ACTIVE),
                        new Operand(TestConstants.PURPOSE, TestConstants.ID_3_1_TRACE)));

        boolean result = cut.hasAllConstraint(acceptedPolicy, List.of(andConstraint));

        assertThat(result).isFalse();
    }

@dsmf dsmf moved this from next to wip in IRS Jul 10, 2024
@dsmf dsmf self-assigned this Jul 10, 2024
@dsmf
Copy link
Contributor

dsmf commented Jul 10, 2024

@ds-jhartmann: shouldn't it be the other way around: andConstraint one constraint more than acceptedPolicy?

        final AndConstraint andConstraint = createAndConstraint(
                List.of(createAtomicConstraint(TestConstants.FRAMEWORK_AGREEMENT_TRACEABILITY,
                                TestConstants.STATUS_ACTIVE),
                        createAtomicConstraint(TestConstants.MEMBERSHIP, TestConstants.STATUS_ACTIVE),
                        createAtomicConstraint(TestConstants.PURPOSE, TestConstants.ID_3_1_TRACE)));

        final Policy acceptedPolicy = createPolicyWithAndConstraint(
                List.of(new Operand(TestConstants.FRAMEWORK_AGREEMENT_TRACEABILITY, TestConstants.STATUS_ACTIVE),
                        new Operand(TestConstants.PURPOSE, TestConstants.ID_3_1_TRACE)));

        boolean result = cut.hasAllConstraint(acceptedPolicy, List.of(andConstraint));

        assertThat(result).isFalse();

@ds-jhartmann
Copy link
Contributor Author

@ds-jhartmann: shouldn't it be the other way around: andConstraint one constraint more than acceptedPolicy?

Oh, you're right. The bug describes your behavior. However, the Test example I provided should also fail, since the Policy does not match exactly

dsmf added a commit to dsmf/tx-item-relationship-service that referenced this issue Jul 12, 2024
- but results in failures in PolicyCheckerServiceTest
dsmf added a commit to dsmf/tx-item-relationship-service that referenced this issue Jul 12, 2024
dsmf added a commit to dsmf/tx-item-relationship-service that referenced this issue Jul 12, 2024
…NameGenerator

in order to make test names more readable when executed in the IDE
dsmf added a commit to dsmf/tx-item-relationship-service that referenced this issue Jul 12, 2024
dsmf added a commit to dsmf/tx-item-relationship-service that referenced this issue Jul 12, 2024
dsmf added a commit to dsmf/tx-item-relationship-service that referenced this issue Jul 12, 2024
dsmf added a commit to dsmf/tx-item-relationship-service that referenced this issue Jul 12, 2024
dsmf added a commit to dsmf/tx-item-relationship-service that referenced this issue Jul 12, 2024
…constraints

(must have same amount of constraints to ensure that there isn't any subset match in any direction)
@dsmf
Copy link
Contributor

dsmf commented Jul 12, 2024

Outcome

PR

dsmf added a commit to dsmf/tx-item-relationship-service that referenced this issue Jul 12, 2024
@ds-jhartmann ds-jhartmann moved this from wip to test in IRS Jul 12, 2024
@mkanal mkanal added the R24.8 label Jul 15, 2024
@ds-kgassner
Copy link
Contributor

ds-kgassner commented Jul 15, 2024

Successfully tested:
Starting Point: EDC has 2 constraints

IRS accepted policy has 3 constraints: syntax and value match EDC policy
IRS accepted policy has 2 constraints: syntax and value match EDC policy
IRS accepted policy has 2 constraints: syntax does not match EDC policy
IRS accepted policy has 2 constraints: value does not match EDC policy

@dsmf dsmf moved this from test to review in IRS Jul 15, 2024
@mkanal mkanal added this to the 24.8 milestone Jul 22, 2024
@mkanal
Copy link
Contributor

mkanal commented Jul 22, 2024

Testscenario:

  • Create a policy 'X' with an additional constraint to the "default" policy.

image

Default policy contains the two constraints
image

Expected

  • Policy 'X' will not be accepted as there is an additional

@mkanal mkanal moved this from review to done in IRS Jul 22, 2024
@mkanal
Copy link
Contributor

mkanal commented Jul 22, 2024

LGFM. PO acceptance in behalf of @jzbmw .

@mkanal mkanal closed this as completed Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: done
Development

No branches or pull requests

4 participants