use of org.zaproxy.zap.extension.script.ScriptsCache.Configuration in project zaproxy by zaproxy.
the class ScriptsPassiveScannerUnitTest method shouldCreateScriptsCacheWithExpectedConfiguration.
@Test
@SuppressWarnings("unchecked")
void shouldCreateScriptsCacheWithExpectedConfiguration() {
// Given / When
new ScriptsPassiveScanner();
// Then
ArgumentCaptor<Configuration<PassiveScript>> argumentCaptor = ArgumentCaptor.forClass(Configuration.class);
verify(extensionScript).createScriptsCache(argumentCaptor.capture());
Configuration<PassiveScript> configuration = argumentCaptor.getValue();
assertThat(configuration.getScriptType(), is(equalTo(SCRIPT_TYPE)));
assertThat(configuration.getTargetInterface(), is(equalTo(TARGET_INTERFACE)));
InterfaceErrorMessageProvider errorMessageProvider = configuration.getInterfaceErrorMessageProvider();
assertThat(errorMessageProvider, is(not(nullValue())));
ScriptWrapper scriptWrapper = mock(ScriptWrapper.class);
given(scriptWrapper.getName()).willReturn("Name");
assertThat(errorMessageProvider.getErrorMessage(scriptWrapper), is(not(nullValue())));
}
use of org.zaproxy.zap.extension.script.ScriptsCache.Configuration in project zaproxy by zaproxy.
the class HttpSenderScriptListenerUnitTest method shouldCreateScriptsCacheWithExpectedConfiguration.
@Test
@SuppressWarnings("unchecked")
void shouldCreateScriptsCacheWithExpectedConfiguration() {
// Given / When
new HttpSenderScriptListener(extensionScript);
// Then
ArgumentCaptor<Configuration<HttpSenderScript>> argumentCaptor = ArgumentCaptor.forClass(Configuration.class);
verify(extensionScript).createScriptsCache(argumentCaptor.capture());
Configuration<HttpSenderScript> configuration = argumentCaptor.getValue();
assertThat(configuration.getScriptType(), is(equalTo(SCRIPT_TYPE)));
assertThat(configuration.getTargetInterface(), is(equalTo(TARGET_INTERFACE)));
InterfaceErrorMessageProvider errorMessageProvider = configuration.getInterfaceErrorMessageProvider();
assertThat(errorMessageProvider, is(not(nullValue())));
assertThat(errorMessageProvider.getErrorMessage(null), is(not(nullValue())));
}
use of org.zaproxy.zap.extension.script.ScriptsCache.Configuration 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.ScriptsCache.Configuration in project zaproxy by zaproxy.
the class VariantFactoryUnitTest method shouldCreateScriptsCacheWithExpectedConfiguration.
@Test
@SuppressWarnings("unchecked")
void shouldCreateScriptsCacheWithExpectedConfiguration() {
// Given / When
factory.createSiteModifyingVariants();
// Then
ArgumentCaptor<Configuration<VariantScript>> argumentCaptor = ArgumentCaptor.forClass(Configuration.class);
verify(extensionScript).createScriptsCache(argumentCaptor.capture());
Configuration<VariantScript> configuration = argumentCaptor.getValue();
assertThat(configuration.getScriptType(), is(equalTo(SCRIPT_TYPE)));
assertThat(configuration.getTargetInterface(), is(equalTo(TARGET_INTERFACE)));
InterfaceErrorMessageProvider errorMessageProvider = configuration.getInterfaceErrorMessageProvider();
assertThat(errorMessageProvider, is(not(nullValue())));
assertThat(errorMessageProvider.getErrorMessage(mock(ScriptWrapper.class)), is(not(nullValue())));
}
use of org.zaproxy.zap.extension.script.ScriptsCache.Configuration in project zaproxy by zaproxy.
the class ScriptsActiveScanner method scan.
@Override
public void scan() {
List<ScriptWrapper> scripts = this.getActiveScripts();
for (Iterator<ScriptWrapper> it = scripts.iterator(); it.hasNext() && !isStop(); ) {
ScriptWrapper script = it.next();
try {
if (script.isEnabled()) {
ActiveScript2 s = extension.getInterface(script, ActiveScript2.class);
if (s != null) {
HttpMessage msg = this.getNewMsg();
logger.debug("Calling script " + script.getName() + " scanNode for " + msg.getRequestHeader().getURI());
s.scanNode(this, msg);
} else {
scriptsNoInterface.add(script);
}
}
} catch (Exception e) {
extension.handleScriptException(script, e);
}
}
if (!isStop()) {
InterfaceProvider<ActiveScript> interfaceProvider = (scriptWrapper, targetInterface) -> {
ActiveScript s = extension.getInterface(scriptWrapper, targetInterface);
if (s != null) {
return s;
}
if (scriptsNoInterface.contains(scriptWrapper)) {
extension.handleFailedScriptInterface(scriptWrapper, Constant.messages.getString("ascan.scripts.interface.active.error", scriptWrapper.getName()));
}
return null;
};
cachedScripts = getExtension().createScriptsCache(Configuration.<ActiveScript>builder().setScriptType(ExtensionActiveScan.SCRIPT_TYPE_ACTIVE).setTargetInterface(ActiveScript.class).setInterfaceProvider(interfaceProvider).build());
super.scan();
}
scriptsNoInterface.clear();
}
Aggregations