Search in sources :

Example 1 with Configuration

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())));
}
Also used : InterfaceErrorMessageProvider(org.zaproxy.zap.extension.script.ScriptsCache.InterfaceErrorMessageProvider) Configuration(org.zaproxy.zap.extension.script.ScriptsCache.Configuration) ScriptWrapper(org.zaproxy.zap.extension.script.ScriptWrapper) PassiveScript(org.zaproxy.zap.extension.pscan.PassiveScript) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Example 2 with Configuration

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())));
}
Also used : InterfaceErrorMessageProvider(org.zaproxy.zap.extension.script.ScriptsCache.InterfaceErrorMessageProvider) Configuration(org.zaproxy.zap.extension.script.ScriptsCache.Configuration) Test(org.junit.jupiter.api.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Example 3 with Configuration

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()));
}
Also used : Configuration(org.zaproxy.zap.extension.script.ScriptsCache.Configuration) ScriptWrapper(org.zaproxy.zap.extension.script.ScriptWrapper) Test(org.junit.jupiter.api.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Example 4 with Configuration

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())));
}
Also used : InterfaceErrorMessageProvider(org.zaproxy.zap.extension.script.ScriptsCache.InterfaceErrorMessageProvider) Configuration(org.zaproxy.zap.extension.script.ScriptsCache.Configuration) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) VariantScript(org.parosproxy.paros.core.scanner.VariantScript) Test(org.junit.jupiter.api.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with Configuration

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();
}
Also used : Category(org.parosproxy.paros.core.scanner.Category) Configuration(org.zaproxy.zap.extension.script.ScriptsCache.Configuration) Iterator(java.util.Iterator) AbstractAppParamPlugin(org.parosproxy.paros.core.scanner.AbstractAppParamPlugin) Set(java.util.Set) IOException(java.io.IOException) Control(org.parosproxy.paros.control.Control) AlertBuilder(org.parosproxy.paros.core.scanner.AbstractPlugin.AlertBuilder) HashSet(java.util.HashSet) CachedScript(org.zaproxy.zap.extension.script.ScriptsCache.CachedScript) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Alert(org.parosproxy.paros.core.scanner.Alert) ExtensionScript(org.zaproxy.zap.extension.script.ExtensionScript) ScriptsCache(org.zaproxy.zap.extension.script.ScriptsCache) HttpException(org.apache.commons.httpclient.HttpException) Constant(org.parosproxy.paros.Constant) InterfaceProvider(org.zaproxy.zap.extension.script.ScriptsCache.InterfaceProvider) HttpMessage(org.parosproxy.paros.network.HttpMessage) LogManager(org.apache.logging.log4j.LogManager) ScriptWrapper(org.zaproxy.zap.extension.script.ScriptWrapper) ScriptWrapper(org.zaproxy.zap.extension.script.ScriptWrapper) HttpMessage(org.parosproxy.paros.network.HttpMessage) IOException(java.io.IOException) HttpException(org.apache.commons.httpclient.HttpException)

Aggregations

Configuration (org.zaproxy.zap.extension.script.ScriptsCache.Configuration)6 Test (org.junit.jupiter.api.Test)5 WithConfigsTest (org.zaproxy.zap.WithConfigsTest)5 InterfaceErrorMessageProvider (org.zaproxy.zap.extension.script.ScriptsCache.InterfaceErrorMessageProvider)4 ScriptWrapper (org.zaproxy.zap.extension.script.ScriptWrapper)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 HttpException (org.apache.commons.httpclient.HttpException)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Constant (org.parosproxy.paros.Constant)1 Control (org.parosproxy.paros.control.Control)1 AbstractAppParamPlugin (org.parosproxy.paros.core.scanner.AbstractAppParamPlugin)1 AlertBuilder (org.parosproxy.paros.core.scanner.AbstractPlugin.AlertBuilder)1 Alert (org.parosproxy.paros.core.scanner.Alert)1 Category (org.parosproxy.paros.core.scanner.Category)1