Search in sources :

Example 1 with PolyglotAccess

use of org.graalvm.polyglot.PolyglotAccess in project graal by oracle.

the class ContextPolyglotAccessTest method testCustomPolyglotEvalDirect.

@Test
public void testCustomPolyglotEvalDirect() {
    PolyglotAccess access = PolyglotAccess.newBuilder().allowEval(LANGUAGE1, LANGUAGE2).build();
    setupEnv(Context.newBuilder(ProxyLanguage.ID, LANGUAGE1, LANGUAGE2).allowPolyglotAccess(access).build());
    context.initialize(LANGUAGE1);
    context.initialize(LANGUAGE2);
    Env language1 = Language1.getContext(LANGUAGE1);
    Env language2 = Language2.getContext(LANGUAGE2);
    assertPublicEvalDenied(language1, INTERNAL);
    assertPublicEvalDenied(language1, DEPENDENT);
    assertPublicEvalAllowed(language1, LANGUAGE1);
    assertPublicEvalAllowed(language1, LANGUAGE2);
    assertInternalEvalAllowed(language1, INTERNAL);
    assertInternalEvalAllowed(language1, DEPENDENT);
    assertInternalEvalAllowed(language1, LANGUAGE1);
    assertInternalEvalAllowed(language1, LANGUAGE2);
    assertPublicEvalDenied(language2, INTERNAL);
    assertPublicEvalDenied(language2, DEPENDENT);
    assertPublicEvalDenied(language2, LANGUAGE1);
    assertPublicEvalAllowed(language2, LANGUAGE2);
    assertInternalEvalAllowed(language2, INTERNAL);
    assertInternalEvalDenied(language2, DEPENDENT);
    assertInternalEvalDenied(language2, LANGUAGE1);
    assertInternalEvalAllowed(language2, LANGUAGE2);
    assertNoEvalAccess(language2);
}
Also used : PolyglotAccess(org.graalvm.polyglot.PolyglotAccess) Env(com.oracle.truffle.api.TruffleLanguage.Env) Test(org.junit.Test)

Example 2 with PolyglotAccess

use of org.graalvm.polyglot.PolyglotAccess in project graal by oracle.

the class ContextPolyglotAccessTest method testCustomPolyglotEvalBetweenThree.

@Test
public void testCustomPolyglotEvalBetweenThree() {
    PolyglotAccess access = PolyglotAccess.newBuilder().allowEvalBetween(LANGUAGE1, LANGUAGE2, LANGUAGE3).build();
    setupEnv(Context.newBuilder(ProxyLanguage.ID, LANGUAGE1, LANGUAGE2, LANGUAGE3).allowPolyglotAccess(access).build());
    context.initialize(LANGUAGE1);
    context.initialize(LANGUAGE2);
    context.initialize(LANGUAGE3);
    Env language1 = Language1.getContext(LANGUAGE1);
    Env language2 = Language2.getContext(LANGUAGE2);
    Env language3 = Language2.getContext(LANGUAGE3);
    assertPublicEvalDenied(language1, INTERNAL);
    assertPublicEvalDenied(language1, DEPENDENT);
    assertPublicEvalAllowed(language1, LANGUAGE1);
    assertPublicEvalAllowed(language1, LANGUAGE2);
    assertPublicEvalAllowed(language1, LANGUAGE3);
    assertInternalEvalAllowed(language1, INTERNAL);
    assertInternalEvalAllowed(language1, DEPENDENT);
    assertInternalEvalAllowed(language1, LANGUAGE1);
    assertInternalEvalAllowed(language1, LANGUAGE2);
    assertInternalEvalAllowed(language1, LANGUAGE3);
    assertPublicEvalDenied(language2, INTERNAL);
    assertPublicEvalDenied(language2, DEPENDENT);
    assertPublicEvalAllowed(language2, LANGUAGE1);
    assertPublicEvalAllowed(language2, LANGUAGE2);
    assertPublicEvalAllowed(language2, LANGUAGE3);
    assertInternalEvalAllowed(language2, INTERNAL);
    assertInternalEvalDenied(language2, DEPENDENT);
    assertInternalEvalAllowed(language2, LANGUAGE1);
    assertInternalEvalAllowed(language2, LANGUAGE2);
    assertInternalEvalAllowed(language2, LANGUAGE3);
    assertPublicEvalDenied(language3, INTERNAL);
    assertPublicEvalDenied(language3, DEPENDENT);
    assertPublicEvalAllowed(language3, LANGUAGE1);
    assertPublicEvalAllowed(language3, LANGUAGE2);
    assertPublicEvalAllowed(language3, LANGUAGE3);
    assertInternalEvalAllowed(language3, INTERNAL);
    assertInternalEvalDenied(language3, DEPENDENT);
    assertInternalEvalAllowed(language3, LANGUAGE1);
    assertInternalEvalAllowed(language3, LANGUAGE2);
    assertInternalEvalAllowed(language3, LANGUAGE3);
}
Also used : PolyglotAccess(org.graalvm.polyglot.PolyglotAccess) Env(com.oracle.truffle.api.TruffleLanguage.Env) Test(org.junit.Test)

Example 3 with PolyglotAccess

use of org.graalvm.polyglot.PolyglotAccess in project graal by oracle.

the class ContextPolyglotAccessTest method testAllBindingsAccess.

@Test
public void testAllBindingsAccess() {
    PolyglotAccess access = PolyglotAccess.ALL;
    setupEnv(Context.newBuilder(ProxyLanguage.ID, LANGUAGE1, LANGUAGE2).allowPolyglotAccess(access).build());
    context.initialize(LANGUAGE1);
    context.initialize(LANGUAGE2);
    Env language1 = Language1.getContext(LANGUAGE1);
    Env language2 = Language2.getContext(LANGUAGE2);
    assertBindingsAllowed(language1);
    assertBindingsAllowed(language2);
}
Also used : PolyglotAccess(org.graalvm.polyglot.PolyglotAccess) Env(com.oracle.truffle.api.TruffleLanguage.Env) Test(org.junit.Test)

Example 4 with PolyglotAccess

use of org.graalvm.polyglot.PolyglotAccess in project graal by oracle.

the class ContextPolyglotAccessTest method testNoBindingsAccess.

@Test
public void testNoBindingsAccess() {
    PolyglotAccess access = PolyglotAccess.NONE;
    setupEnv(Context.newBuilder(ProxyLanguage.ID, LANGUAGE1, LANGUAGE2).allowPolyglotAccess(access).build());
    context.initialize(LANGUAGE1);
    context.initialize(LANGUAGE2);
    Env language1 = Language1.getContext(LANGUAGE1);
    Env language2 = Language2.getContext(LANGUAGE2);
    assertBindingsNotAccessible(language1);
    assertBindingsNotAccessible(language2);
}
Also used : PolyglotAccess(org.graalvm.polyglot.PolyglotAccess) Env(com.oracle.truffle.api.TruffleLanguage.Env) Test(org.junit.Test)

Example 5 with PolyglotAccess

use of org.graalvm.polyglot.PolyglotAccess in project graal by oracle.

the class ContextPolyglotAccessTest method testCustomPolyglotEvalSingleDeny.

@Test
public void testCustomPolyglotEvalSingleDeny() {
    PolyglotAccess access = // 
    PolyglotAccess.newBuilder().allowEvalBetween(LANGUAGE1, // 
    LANGUAGE2).denyEval(LANGUAGE1, // 
    LANGUAGE2).build();
    setupEnv(Context.newBuilder(ProxyLanguage.ID, LANGUAGE1, LANGUAGE2).allowPolyglotAccess(access).build());
    context.initialize(LANGUAGE1);
    context.initialize(LANGUAGE2);
    Env language1 = Language1.getContext(LANGUAGE1);
    Env language2 = Language2.getContext(LANGUAGE2);
    assertPublicEvalDenied(language1, INTERNAL);
    assertPublicEvalDenied(language1, DEPENDENT);
    assertPublicEvalAllowed(language1, LANGUAGE1);
    assertPublicEvalDenied(language1, LANGUAGE2);
    assertInternalEvalAllowed(language1, INTERNAL);
    assertInternalEvalAllowed(language1, DEPENDENT);
    assertInternalEvalAllowed(language1, LANGUAGE1);
    assertInternalEvalDenied(language1, LANGUAGE2);
    assertPublicEvalDenied(language2, INTERNAL);
    assertPublicEvalDenied(language2, DEPENDENT);
    assertPublicEvalAllowed(language2, LANGUAGE1);
    assertPublicEvalAllowed(language2, LANGUAGE2);
    assertInternalEvalAllowed(language2, INTERNAL);
    assertInternalEvalDenied(language2, DEPENDENT);
    assertInternalEvalAllowed(language2, LANGUAGE1);
    assertInternalEvalAllowed(language2, LANGUAGE2);
    assertNoEvalAccess(language1);
}
Also used : PolyglotAccess(org.graalvm.polyglot.PolyglotAccess) Env(com.oracle.truffle.api.TruffleLanguage.Env) Test(org.junit.Test)

Aggregations

PolyglotAccess (org.graalvm.polyglot.PolyglotAccess)12 Test (org.junit.Test)12 Env (com.oracle.truffle.api.TruffleLanguage.Env)10 Context (org.graalvm.polyglot.Context)2