use of org.zaproxy.zap.extension.script.ScriptWrapper in project zaproxy by zaproxy.
the class ScriptsActiveScannerUnitTest method shouldCreateScriptsCacheWithExpectedConfiguration.
@Test
@SuppressWarnings("unchecked")
void shouldCreateScriptsCacheWithExpectedConfiguration() throws Exception {
// Given
ActiveScript script = mock(ActiveScript.class);
ScriptWrapper scriptWrapper = createScriptWrapper(script, ActiveScript.class);
given(extensionScript.getScripts(SCRIPT_TYPE)).willReturn(asList(scriptWrapper));
VariantFactory variantFactory = mock(VariantFactory.class);
given(variantFactory.createVariants(any(), any())).willReturn(asList(mock(Variant.class)));
given(model.getVariantFactory()).willReturn(variantFactory);
ScriptsActiveScanner scriptsActiveScanner = new ScriptsActiveScanner();
scriptsActiveScanner.init(message, parent);
// When
scriptsActiveScanner.scan();
// Then
ArgumentCaptor<Configuration<ActiveScript>> argumentCaptor = ArgumentCaptor.forClass(Configuration.class);
verify(extensionScript).createScriptsCache(argumentCaptor.capture());
Configuration<ActiveScript> configuration = argumentCaptor.getValue();
assertThat(configuration.getScriptType(), is(equalTo(SCRIPT_TYPE)));
assertThat(configuration.getTargetInterface(), is(equalTo(TARGET_INTERFACE_CACHE)));
assertThat(configuration.getInterfaceProvider(), is(not(nullValue())));
assertThat(configuration.getInterfaceErrorMessageProvider(), is(nullValue()));
}
use of org.zaproxy.zap.extension.script.ScriptWrapper in project zaproxy by zaproxy.
the class ScriptsActiveScannerUnitTest method shouldScanNodesWithActiveScript2.
@Test
void shouldScanNodesWithActiveScript2() throws Exception {
// Given
ActiveScript2 script1 = mock(ActiveScript2.class);
ScriptWrapper scriptWrapper1 = createScriptWrapper(script1, ActiveScript2.class);
ActiveScript2 script2 = mock(ActiveScript2.class);
ScriptWrapper scriptWrapper2 = createScriptWrapper(script2, ActiveScript2.class);
given(extensionScript.getScripts(SCRIPT_TYPE)).willReturn(asList(scriptWrapper1, scriptWrapper2));
VariantFactory variantFactory = mock(VariantFactory.class);
given(variantFactory.createVariants(any(), any())).willReturn(asList(mock(Variant.class)));
given(model.getVariantFactory()).willReturn(variantFactory);
ScriptsActiveScanner scriptsActiveScanner = new ScriptsActiveScanner();
scriptsActiveScanner.init(message, parent);
// When
scriptsActiveScanner.scan();
// Then
verify(script1, times(1)).scanNode(scriptsActiveScanner, message);
verify(script2, times(1)).scanNode(scriptsActiveScanner, message);
}
use of org.zaproxy.zap.extension.script.ScriptWrapper in project zaproxy by zaproxy.
the class ScriptsActiveScannerUnitTest method shouldNotCallScanNodeOnDisabledActiveScript2.
@Test
void shouldNotCallScanNodeOnDisabledActiveScript2() throws Exception {
// Given
ScriptWrapper scriptWrapper1 = mock(ScriptWrapper.class);
given(scriptWrapper1.isEnabled()).willReturn(false);
ActiveScript2 script2 = mock(ActiveScript2.class);
ScriptWrapper scriptWrapper2 = createScriptWrapper(script2, ActiveScript2.class);
given(extensionScript.getScripts(SCRIPT_TYPE)).willReturn(asList(scriptWrapper1, scriptWrapper2));
VariantFactory variantFactory = mock(VariantFactory.class);
given(variantFactory.createVariants(any(), any())).willReturn(asList(mock(Variant.class)));
given(model.getVariantFactory()).willReturn(variantFactory);
ScriptsActiveScanner scriptsActiveScanner = new ScriptsActiveScanner();
scriptsActiveScanner.init(message, parent);
// When
scriptsActiveScanner.scan();
// Then
verify(extensionScript, times(0)).getInterface(scriptWrapper1, ActiveScript2.class);
verify(script2, times(1)).scanNode(scriptsActiveScanner, message);
}
use of org.zaproxy.zap.extension.script.ScriptWrapper in project zaproxy by zaproxy.
the class ScriptsActiveScannerUnitTest method shouldStopScanningNodesWithActiveScript2WhenScanStopped.
@Test
void shouldStopScanningNodesWithActiveScript2WhenScanStopped() throws Exception {
// Given
ActiveScript2 script1 = mock(ActiveScript2.class);
doAnswer(stopScan()).when(script1).scanNode(any(), any());
ScriptWrapper scriptWrapper1 = createScriptWrapper(script1, ActiveScript2.class);
ScriptWrapper scriptWrapper2 = mock(ScriptWrapper.class);
given(extensionScript.getScripts(SCRIPT_TYPE)).willReturn(asList(scriptWrapper1, scriptWrapper2));
ScriptsActiveScanner scriptsActiveScanner = new ScriptsActiveScanner();
scriptsActiveScanner.init(message, parent);
// When
scriptsActiveScanner.scan();
// Then
verify(script1, times(1)).scanNode(scriptsActiveScanner, message);
verify(extensionScript, times(0)).getInterface(scriptWrapper2, ActiveScript2.class);
}
use of org.zaproxy.zap.extension.script.ScriptWrapper in project zaproxy by zaproxy.
the class ScriptsActiveScannerUnitTest method shouldFailScriptsThatDoNotImplementNeitherActiveScript2NorActiveScript.
@Test
void shouldFailScriptsThatDoNotImplementNeitherActiveScript2NorActiveScript() {
// Given
ScriptWrapper scriptWrapper = mock(ScriptWrapper.class);
given(scriptWrapper.isEnabled()).willReturn(true);
given(extensionScript.getScripts(SCRIPT_TYPE)).willReturn(asList(scriptWrapper));
VariantFactory variantFactory = mock(VariantFactory.class);
given(variantFactory.createVariants(any(), any())).willReturn(asList(mock(Variant.class)));
given(model.getVariantFactory()).willReturn(variantFactory);
ScriptsActiveScanner scriptsActiveScanner = new ScriptsActiveScanner();
scriptsActiveScanner.init(message, parent);
given(extensionScript.<ActiveScript>createScriptsCache(any())).willAnswer(e -> {
Configuration<ActiveScript> configuration = e.getArgument(0);
configuration.getInterfaceProvider().getInterface(scriptWrapper, ActiveScript.class);
return null;
});
// When
scriptsActiveScanner.scan();
// Then
verify(extensionScript).handleFailedScriptInterface(eq(scriptWrapper), any());
}
Aggregations