Search in sources :

Example 66 with Foo

use of org.mvel2.tests.core.res.Foo in project drools by kiegroup.

the class SecurityPolicyTest method testUntrustedEnabled.

@Test
public void testUntrustedEnabled() throws Exception {
    String drl = "package org.foo.bar\n" + "import " + MaliciousExitHelper.class.getName().replace('$', '.') + " \n" + "rule R1 enabled( MaliciousExitHelper.isEnabled() ) \n" + "when\n" + "then\n" + "end\n";
    try {
        KieServices ks = KieServices.Factory.get();
        KieFileSystem kfs = ks.newKieFileSystem().write(ResourceFactory.newByteArrayResource(drl.getBytes()).setSourcePath("org/foo/bar/r1.drl"));
        ks.newKieBuilder(kfs).buildAll();
        ReleaseId releaseId = ks.getRepository().getDefaultReleaseId();
        KieContainer kc = ks.newKieContainer(releaseId);
        KieSession ksession = kc.newKieSession();
        ksession.fireAllRules();
        Assert.fail("The security policy for the rule should have prevented this from executing...");
    } catch (ShouldHavePrevented e) {
        Assert.fail("The security policy for the rule should have prevented this from executing...");
    } catch (Exception e) {
    // test succeeded. the policy in place prevented the rule from executing the System.exit().
    }
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) ConsequenceException(org.kie.api.runtime.rule.ConsequenceException) PropertyAccessException(org.mvel2.PropertyAccessException) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)27 Foo (org.mvel2.tests.core.res.Foo)22 ParserContext (org.mvel2.ParserContext)18 CompiledExpression (org.mvel2.compiler.CompiledExpression)15 Serializable (java.io.Serializable)14 HashMap (java.util.HashMap)12 Test (org.junit.Test)9 KieServices (org.kie.api.KieServices)9 KieFileSystem (org.kie.api.builder.KieFileSystem)9 ReleaseId (org.kie.api.builder.ReleaseId)9 KieContainer (org.kie.api.runtime.KieContainer)9 PropertyAccessException (org.mvel2.PropertyAccessException)9 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)9 KieSession (org.kie.api.runtime.KieSession)8 ConsequenceException (org.kie.api.runtime.rule.ConsequenceException)7 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)7 Map (java.util.Map)5 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)5 Interceptor (org.mvel2.integration.Interceptor)4 ASTNode (org.mvel2.ast.ASTNode)3