Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
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
38 changes: 38 additions & 0 deletions 38 policy/src/test/java/dev/cel/policy/CelPolicyCompilerImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import dev.cel.policy.PolicyTestHelper.PolicyTestSuite.PolicyTestSection.PolicyTestCase;
import dev.cel.policy.PolicyTestHelper.PolicyTestSuite.PolicyTestSection.PolicyTestCase.PolicyTestInput;
import dev.cel.policy.PolicyTestHelper.TestYamlPolicy;
import dev.cel.runtime.CelLateFunctionBindings;
import dev.cel.runtime.CelRuntime.CelFunctionBinding;
import java.io.IOException;
import java.util.Map;
Expand Down Expand Up @@ -212,6 +213,43 @@ public void evaluateYamlPolicy_nestedRuleProducesOptionalOutput() throws Excepti
assertThat(evalResult).hasValue(Optional.of(true));
}

@Test
public void evaluateYamlPolicy_lateBoundFunction() throws Exception {
String configSource =
"name: late_bound_function_config\n"
+ "functions:\n"
+ " - name: 'lateBoundFunc'\n"
+ " overloads:\n"
+ " - id: 'lateBoundFunc_string'\n"
+ " args:\n"
+ " - type_name: 'string'\n"
+ " return:\n"
+ " type_name: 'string'\n";
CelPolicyConfig celPolicyConfig = POLICY_CONFIG_PARSER.parse(configSource);
Cel cel = celPolicyConfig.extend(newCel(), CelOptions.DEFAULT);
String policySource =
"name: late_bound_function_policy\n"
+ "rule:\n"
+ " match:\n"
+ " - output: |\n"
+ " lateBoundFunc('foo')\n";
CelPolicy policy = POLICY_PARSER.parse(policySource);
CelAbstractSyntaxTree compiledPolicyAst =
CelPolicyCompilerFactory.newPolicyCompiler(cel).build().compile(policy);
String exampleValue = "bar";
CelLateFunctionBindings lateFunctionBindings =
CelLateFunctionBindings.from(
CelFunctionBinding.from(
"lateBoundFunc_string", String.class, arg -> arg + exampleValue));

String evalResult =
(String)
cel.createProgram(compiledPolicyAst)
.eval((unused) -> Optional.empty(), lateFunctionBindings);

assertThat(evalResult).isEqualTo("foo" + exampleValue);
}

private static final class EvaluablePolicyTestData {
private final TestYamlPolicy yamlPolicy;
private final PolicyTestCase testCase;
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.