Search in sources :

Example 6 with PolyglotAccess

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

the class ContextPolyglotAccessTest method testCustomPolyglotEvalBetweenSame.

@Test
public void testCustomPolyglotEvalBetweenSame() {
    PolyglotAccess access = PolyglotAccess.newBuilder().allowEvalBetween(LANGUAGE1, LANGUAGE1).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);
    assertPublicEvalDenied(language2, LANGUAGE1);
    assertPublicEvalAllowed(language2, LANGUAGE2);
    assertInternalEvalAllowed(language2, INTERNAL);
    assertInternalEvalDenied(language2, DEPENDENT);
    assertInternalEvalDenied(language2, LANGUAGE1);
    assertInternalEvalAllowed(language2, LANGUAGE2);
    assertNoEvalAccess(language1);
    assertNoEvalAccess(language2);
}
Also used : PolyglotAccess(org.graalvm.polyglot.PolyglotAccess) Env(com.oracle.truffle.api.TruffleLanguage.Env) Test(org.junit.Test)

Example 7 with PolyglotAccess

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

the class ContextPolyglotAccessTest method testCustomPolyglotBindingsErrors.

@Test
public void testCustomPolyglotBindingsErrors() {
    PolyglotAccess.Builder builder = PolyglotAccess.newBuilder();
    assertFails(() -> builder.allowBindingsAccess(null), NullPointerException.class);
    PolyglotAccess access = PolyglotAccess.newBuilder().allowBindingsAccess(NOT_EXISTING_LANGUAGE).build();
    Context.Builder cBuilder = Context.newBuilder().allowPolyglotAccess(access);
    AbstractPolyglotTest.assertFails(() -> cBuilder.build(), IllegalArgumentException.class, (e) -> assertEquals("Language '" + NOT_EXISTING_LANGUAGE + "' configured in polyglot bindings access rule is not installed or available.", e.getMessage()));
}
Also used : Context(org.graalvm.polyglot.Context) PolyglotAccess(org.graalvm.polyglot.PolyglotAccess) Test(org.junit.Test)

Example 8 with PolyglotAccess

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

the class ContextPolyglotAccessTest method testCustomBindingsAccess.

@Test
public void testCustomBindingsAccess() {
    PolyglotAccess access = // 
    PolyglotAccess.newBuilder().allowBindingsAccess(// 
    LANGUAGE1).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);
    assertBindingsAllowed(language1);
    assertBindingsNotAccessible(language2);
}
Also used : PolyglotAccess(org.graalvm.polyglot.PolyglotAccess) Env(com.oracle.truffle.api.TruffleLanguage.Env) Test(org.junit.Test)

Example 9 with PolyglotAccess

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

the class ContextPolyglotAccessTest method testCustomPolyglotEvalErrors.

@Test
public void testCustomPolyglotEvalErrors() {
    PolyglotAccess.Builder builder = PolyglotAccess.newBuilder();
    assertFails(() -> builder.allowEval(null, ""), NullPointerException.class);
    assertFails(() -> builder.allowEval("", null), NullPointerException.class);
    assertFails(() -> builder.denyEval(null, ""), NullPointerException.class);
    assertFails(() -> builder.denyEval("", null), NullPointerException.class);
    assertFails(() -> builder.allowEvalBetween((String[]) null), NullPointerException.class);
    assertFails(() -> builder.denyEvalBetween((String[]) null), NullPointerException.class);
    assertFails(() -> builder.allowEvalBetween((String) null), NullPointerException.class);
    assertFails(() -> builder.denyEvalBetween((String) null), NullPointerException.class);
    PolyglotAccess access = PolyglotAccess.newBuilder().allowEval(NOT_EXISTING_LANGUAGE, LANGUAGE1).build();
    Context.Builder cBuilder = Context.newBuilder().allowPolyglotAccess(access);
    assertFails(() -> cBuilder.build(), IllegalArgumentException.class);
    access = PolyglotAccess.newBuilder().allowEval(LANGUAGE1, LANGUAGE2).build();
    Context.Builder cBuilder2 = Context.newBuilder(LANGUAGE2).allowPolyglotAccess(access);
    AbstractPolyglotTest.assertFails(() -> cBuilder2.build(), IllegalArgumentException.class, (e) -> assertEquals("Language '" + LANGUAGE1 + "' configured in polyglot evaluation rule " + LANGUAGE1 + " -> " + LANGUAGE2 + " is not installed or available.", e.getMessage()));
}
Also used : Context(org.graalvm.polyglot.Context) PolyglotAccess(org.graalvm.polyglot.PolyglotAccess) Test(org.junit.Test)

Example 10 with PolyglotAccess

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

the class ContextPolyglotAccessTest method testCustomPolyglotEvalBetween.

@Test
public void testCustomPolyglotEvalBetween() {
    PolyglotAccess access = PolyglotAccess.newBuilder().allowEvalBetween(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);
    assertPublicEvalAllowed(language2, LANGUAGE1);
    assertPublicEvalAllowed(language2, LANGUAGE2);
    assertInternalEvalAllowed(language2, INTERNAL);
    assertInternalEvalDenied(language2, DEPENDENT);
    assertInternalEvalAllowed(language2, LANGUAGE1);
    assertInternalEvalAllowed(language2, LANGUAGE2);
}
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