Search in sources :

Example 6 with CachedScript

use of org.zaproxy.zap.extension.script.ScriptsCache.CachedScript in project zaproxy by zaproxy.

the class ScriptsCacheUnitTest method shouldNotCacheScriptsThatHaveErrors.

@Test
void shouldNotCacheScriptsThatHaveErrors() throws Exception {
    // Given
    Script script1 = mock(Script.class);
    ScriptWrapper scriptWrapper1 = mockScriptWrapper(script1);
    Script script2 = mock(Script.class);
    ScriptWrapper scriptWrapper2 = mockScriptWrapper(script2);
    ScriptException scriptException = mock(ScriptException.class);
    given(extensionScript.getInterface(scriptWrapper2, targetInterface)).willThrow(scriptException);
    given(extensionScript.getScripts(scriptType)).willReturn(asList(scriptWrapper1, scriptWrapper2));
    // When
    scriptsCache.refresh();
    // Then
    List<CachedScript<Script>> cachedScripts = scriptsCache.getCachedScripts();
    assertThat(cachedScripts, hasSize(1));
    assertCachedScript(cachedScripts.get(0), scriptWrapper1, script1);
    verify(extensionScript, times(1)).getScripts(scriptType);
    verify(extensionScript, times(1)).getInterface(scriptWrapper1, targetInterface);
    verify(extensionScript, times(1)).getInterface(scriptWrapper2, targetInterface);
    verify(extensionScript, times(1)).handleScriptException(scriptWrapper2, scriptException);
    verifyNoMoreInteractions(extensionScript);
}
Also used : CachedScript(org.zaproxy.zap.extension.script.ScriptsCache.CachedScript) ScriptException(javax.script.ScriptException) CachedScript(org.zaproxy.zap.extension.script.ScriptsCache.CachedScript) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Test (org.junit.jupiter.api.Test)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 CachedScript (org.zaproxy.zap.extension.script.ScriptsCache.CachedScript)6 ScriptException (javax.script.ScriptException)1