Search in sources :

Example 46 with ScriptContext

use of javax.script.ScriptContext in project zaproxy by zaproxy.

the class ScriptVarsUnitTest method shouldNotReturnScriptCustomVariablesFromOtherScriptsUsingScriptContext.

@Test
void shouldNotReturnScriptCustomVariablesFromOtherScriptsUsingScriptContext() {
    // Given
    ScriptContext scriptContext1 = createScriptContextWithName("ScriptName1");
    ScriptContext scriptContext2 = createScriptContextWithName("ScriptName2");
    String key = createKey();
    // When
    ScriptVars.setScriptCustomVar(scriptContext1, key, createCustomValue());
    // Then
    assertThat(ScriptVars.getScriptCustomVar(scriptContext2, key), is(nullValue()));
}
Also used : SimpleScriptContext(javax.script.SimpleScriptContext) ScriptContext(javax.script.ScriptContext) Test(org.junit.jupiter.api.Test)

Example 47 with ScriptContext

use of javax.script.ScriptContext in project zaproxy by zaproxy.

the class ScriptVarsUnitTest method shouldNotReturnScriptVariablesFromOtherScriptsUsingScriptContext.

@Test
void shouldNotReturnScriptVariablesFromOtherScriptsUsingScriptContext() {
    // Given
    ScriptContext scriptContext1 = createScriptContextWithName("ScriptName1");
    ScriptContext scriptContext2 = createScriptContextWithName("ScriptName2");
    String key = createKey();
    // When
    ScriptVars.setScriptVar(scriptContext1, key, createValue());
    // Then
    assertThat(ScriptVars.getScriptVar(scriptContext2, key), is(nullValue()));
}
Also used : SimpleScriptContext(javax.script.SimpleScriptContext) ScriptContext(javax.script.ScriptContext) Test(org.junit.jupiter.api.Test)

Example 48 with ScriptContext

use of javax.script.ScriptContext in project zaproxy by zaproxy.

the class ScriptVarsUnitTest method shouldSetScriptVariableUsingScriptContext.

@Test
void shouldSetScriptVariableUsingScriptContext() {
    // Given
    String key = createKey();
    String value = createValue();
    String scriptName = "ScriptName";
    ScriptContext scriptContext = createScriptContextWithName(scriptName);
    // When
    ScriptVars.setScriptVar(scriptContext, key, value);
    // Then
    assertThat(ScriptVars.getScriptVars(scriptName), hasEntry(key, value));
    assertThat(ScriptVars.getScriptVar(scriptContext, key), is(equalTo(value)));
}
Also used : SimpleScriptContext(javax.script.SimpleScriptContext) ScriptContext(javax.script.ScriptContext) Test(org.junit.jupiter.api.Test)

Example 49 with ScriptContext

use of javax.script.ScriptContext in project zaproxy by zaproxy.

the class ScriptVarsUnitTest method createScriptContextWithName.

private static ScriptContext createScriptContextWithName(Object scriptName) {
    ScriptContext context = new SimpleScriptContext();
    context.setAttribute(ExtensionScript.SCRIPT_NAME_ATT, scriptName, ScriptContext.ENGINE_SCOPE);
    return context;
}
Also used : SimpleScriptContext(javax.script.SimpleScriptContext) SimpleScriptContext(javax.script.SimpleScriptContext) ScriptContext(javax.script.ScriptContext)

Example 50 with ScriptContext

use of javax.script.ScriptContext in project zaproxy by zaproxy.

the class ScriptVarsUnitTest method shouldNotSetScriptVariableWithInvalidValueLengthUsingScriptContext.

@Test
void shouldNotSetScriptVariableWithInvalidValueLengthUsingScriptContext() {
    // Given
    ScriptContext scriptContext = createScriptContextWithName("ScriptName");
    // When / Then
    assertThrows(IllegalArgumentException.class, () -> ScriptVars.setScriptVar(scriptContext, createKey(), createValueWithInvalidLength()));
}
Also used : SimpleScriptContext(javax.script.SimpleScriptContext) ScriptContext(javax.script.ScriptContext) Test(org.junit.jupiter.api.Test)

Aggregations

ScriptContext (javax.script.ScriptContext)126 SimpleScriptContext (javax.script.SimpleScriptContext)83 Bindings (javax.script.Bindings)33 Test (org.junit.Test)30 SimpleBindings (javax.script.SimpleBindings)28 Test (org.junit.jupiter.api.Test)19 ScriptEngine (javax.script.ScriptEngine)18 ScriptException (javax.script.ScriptException)18 HashMap (java.util.HashMap)13 CompiledScript (javax.script.CompiledScript)11 IOException (java.io.IOException)9 Map (java.util.Map)8 ScriptEngineManager (javax.script.ScriptEngineManager)8 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)7 Test (org.testng.annotations.Test)7 StringWriter (java.io.StringWriter)6 NashornScriptEngine (jdk.nashorn.api.scripting.NashornScriptEngine)6 XWikiException (com.xpn.xwiki.XWikiException)5 Reader (java.io.Reader)5 StringReader (java.io.StringReader)5