-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add version cel policy script builder Signed-off-by: vithikashukla <[email protected]> * add version support for coordinates cel policy Signed-off-by: vithikashukla <[email protected]> * Added unit test for version policy script builder Signed-off-by: vithikashukla <[email protected]> * added coordninates condition test Signed-off-by: vithikashukla <[email protected]> * added coordinates condition test Signed-off-by: vithikashukla <[email protected]> * added more conditions to test Signed-off-by: vithikashukla <[email protected]> * Added license condition test Signed-off-by: vithikashukla <[email protected]> * Update src/main/java/org/dependencytrack/policy/cel/CelPolicyEngine.java Co-authored-by: Niklas <[email protected]> Signed-off-by: VithikaS <[email protected]> * Added license group condition test Signed-off-by: vithikashukla <[email protected]> * updated comment Signed-off-by: vithikashukla <[email protected]> --------- Signed-off-by: vithikashukla <[email protected]> Signed-off-by: VithikaS <[email protected]> Co-authored-by: vithikashukla <[email protected]> Co-authored-by: Niklas <[email protected]>
- Loading branch information
1 parent
e2082bf
commit d19301c
Showing
4 changed files
with
342 additions
and
14 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
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
122 changes: 122 additions & 0 deletions
122
src/test/java/org/dependencytrack/policy/cel/compat/LicenseConditionTest.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,122 @@ | ||
package org.dependencytrack.policy.cel.compat; | ||
|
||
import org.dependencytrack.AbstractPostgresEnabledTest; | ||
import org.dependencytrack.model.Component; | ||
import org.dependencytrack.model.License; | ||
import org.dependencytrack.model.Policy; | ||
import org.dependencytrack.model.PolicyCondition; | ||
import org.dependencytrack.model.Project; | ||
import org.dependencytrack.policy.cel.CelPolicyEngine; | ||
import org.junit.Test; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class LicenseConditionTest extends AbstractPostgresEnabledTest { | ||
|
||
@Test | ||
public void hasMatch() { | ||
License license = new License(); | ||
license.setName("Apache 2.0"); | ||
license.setUuid(UUID.randomUUID()); | ||
license = qm.persist(license); | ||
|
||
Policy policy = qm.createPolicy("Test Policy", Policy.Operator.ANY, Policy.ViolationState.INFO); | ||
qm.createPolicyCondition(policy, PolicyCondition.Subject.LICENSE, PolicyCondition.Operator.IS, license.getUuid().toString()); | ||
final var project = new Project(); | ||
project.setName("acme-app"); | ||
qm.persist(project); | ||
|
||
final var component = new Component(); | ||
component.setName("acme-app"); | ||
component.setResolvedLicense(license); | ||
component.setProject(project); | ||
qm.persist(component); | ||
|
||
new CelPolicyEngine().evaluateProject(project.getUuid()); | ||
assertThat(qm.getAllPolicyViolations(component)).hasSize(1); | ||
} | ||
|
||
@Test | ||
public void noMatch() { | ||
License license = new License(); | ||
license.setName("Apache 2.0"); | ||
license.setUuid(UUID.randomUUID()); | ||
license = qm.persist(license); | ||
|
||
Policy policy = qm.createPolicy("Test Policy", Policy.Operator.ANY, Policy.ViolationState.INFO); | ||
qm.createPolicyCondition(policy, PolicyCondition.Subject.LICENSE, PolicyCondition.Operator.IS, UUID.randomUUID().toString()); | ||
final var project = new Project(); | ||
project.setName("acme-app"); | ||
qm.persist(project); | ||
|
||
final var component = new Component(); | ||
component.setName("acme-app"); | ||
component.setResolvedLicense(license); | ||
component.setProject(project); | ||
|
||
qm.persist(component); | ||
|
||
new CelPolicyEngine().evaluateProject(project.getUuid()); | ||
assertThat(qm.getAllPolicyViolations(component)).isEmpty(); | ||
} | ||
|
||
@Test | ||
public void wrongOperator() { | ||
License license = new License(); | ||
license.setName("Apache 2.0"); | ||
license.setUuid(UUID.randomUUID()); | ||
license = qm.persist(license); | ||
|
||
Policy policy = qm.createPolicy("Test Policy", Policy.Operator.ANY, Policy.ViolationState.INFO); | ||
qm.createPolicyCondition(policy, PolicyCondition.Subject.LICENSE, PolicyCondition.Operator.MATCHES, license.getUuid().toString()); | ||
final var project = new Project(); | ||
project.setName("acme-app"); | ||
qm.persist(project); | ||
|
||
final var component = new Component(); | ||
component.setName("acme-app"); | ||
component.setProject(project); | ||
component.setResolvedLicense(license); | ||
qm.persist(component); | ||
|
||
new CelPolicyEngine().evaluateProject(project.getUuid()); | ||
assertThat(qm.getAllPolicyViolations(component)).isEmpty(); | ||
} | ||
|
||
@Test | ||
public void valueIsUnresolved() { | ||
License license = new License(); | ||
license.setName("Apache 2.0"); | ||
license.setUuid(UUID.randomUUID()); | ||
license = qm.persist(license); | ||
|
||
Policy policy = qm.createPolicy("Test Policy", Policy.Operator.ANY, Policy.ViolationState.INFO); | ||
qm.createPolicyCondition(policy, PolicyCondition.Subject.LICENSE, PolicyCondition.Operator.IS, "unresolved"); | ||
|
||
final var project = new Project(); | ||
project.setName("acme-app"); | ||
qm.persist(project); | ||
|
||
Component componentWithoutLicense = new Component(); | ||
componentWithoutLicense.setName("second-component"); | ||
componentWithoutLicense.setProject(project); | ||
qm.persist(componentWithoutLicense); | ||
|
||
CelPolicyEngine policyEngine = new CelPolicyEngine(); | ||
|
||
policyEngine.evaluateProject(project.getUuid()); | ||
assertThat(qm.getAllPolicyViolations(componentWithoutLicense)).hasSize(1); | ||
|
||
final var componentWithLicense = new Component(); | ||
componentWithLicense.setName("acme-app"); | ||
componentWithLicense.setProject(project); | ||
componentWithLicense.setResolvedLicense(license); | ||
qm.persist(componentWithLicense); | ||
|
||
policyEngine.evaluateProject(project.getUuid()); | ||
assertThat(qm.getAllPolicyViolations(componentWithLicense)).hasSize(0); | ||
} | ||
} | ||
|
Oops, something went wrong.