Search in sources :

Example 61 with ZapXmlConfiguration

use of org.zaproxy.zap.utils.ZapXmlConfiguration in project zaproxy by zaproxy.

the class ScanPolicyUnitTest method shouldUseMediumIfInvalidDefaultScannerLevelFromConfig.

@Test
void shouldUseMediumIfInvalidDefaultScannerLevelFromConfig() throws Exception {
    // Given
    ZapXmlConfiguration conf = new ZapXmlConfiguration();
    conf.setProperty(DEFAULT_SCANNER_LEVEL_KEY, "NotValid");
    // When
    ScanPolicy scanPolicy = new ScanPolicy(conf);
    // Then
    assertThat(scanPolicy.getDefaultThreshold(), is(equalTo(Plugin.AlertThreshold.MEDIUM)));
}
Also used : ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) Test(org.junit.jupiter.api.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Example 62 with ZapXmlConfiguration

use of org.zaproxy.zap.utils.ZapXmlConfiguration in project zaproxy by zaproxy.

the class ExtensionProxies method startProxyServer.

private org.parosproxy.paros.core.proxy.ProxyServer startProxyServer(ProxiesParamProxy param) {
    String address = param.getAddress();
    int port = param.getPort();
    String key = createProxyKey(address, port);
    log.info("Starting alt proxy server: " + key);
    org.parosproxy.paros.core.proxy.ProxyServer proxyServer = new org.parosproxy.paros.core.proxy.ProxyServer(ZAP_PROXY_THREAD_PREFIX + key) {

        @Override
        public boolean excludeUrl(URI uri) {
            String uriString = uri.toString();
            for (String excludePattern : getModel().getOptionsParam().getGlobalExcludeURLParam().getTokensNames()) {
                if (uriString.matches(excludePattern)) {
                    return true;
                }
            }
            for (String excludePattern : getModel().getSession().getExcludeFromProxyRegexs()) {
                if (uriString.matches(excludePattern)) {
                    return true;
                }
            }
            return false;
        }
    };
    proxyServer.getProxyParam().load(new ZapXmlConfiguration());
    applyProxyOptions(param, proxyServer);
    proxyServer.setConnectionParam(getModel().getOptionsParam().getConnectionParam());
    // Note that if this is _not_ set then the proxy will go into a nasty loop if you point a
    // browser at it
    proxyServer.setEnableApi(true);
    Control.getSingleton().getExtensionLoader().addProxyServer(proxyServer);
    proxyServer.startServer(address, port, false);
    return proxyServer;
}
Also used : ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) URI(org.apache.commons.httpclient.URI)

Example 63 with ZapXmlConfiguration

use of org.zaproxy.zap.utils.ZapXmlConfiguration in project zaproxy by zaproxy.

the class ConstantUnitTest method defaultConfigContents.

private static String defaultConfigContents() throws IOException {
    try (InputStream is = Constant.class.getResourceAsStream("/org/zaproxy/zap/resources/config.xml")) {
        ZapXmlConfiguration configuration = new ZapXmlConfiguration(is);
        configuration.setProperty("version", Constant.VERSION_TAG);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        configuration.save(os);
        return os.toString(StandardCharsets.UTF_8.name());
    } catch (ConfigurationException e) {
        throw new IOException(e);
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) InputStream(java.io.InputStream) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 64 with ZapXmlConfiguration

use of org.zaproxy.zap.utils.ZapXmlConfiguration in project zaproxy by zaproxy.

the class ConstantUnitTest method shouldUpgradeFrom2_9_0.

@Test
void shouldUpgradeFrom2_9_0() {
    // Given
    List<String> keyPrefixes = Arrays.asList("a.", "a.b.", "c.");
    ZapXmlConfiguration configuration = new ZapXmlConfiguration();
    for (String keyPrefix : keyPrefixes) {
        configuration.setProperty(keyPrefix + "markocurrences", "true");
    }
    String unrelatedKey = "a.markocurrences.y";
    configuration.setProperty(unrelatedKey, "abc");
    // When
    Constant.upgradeFrom2_9_0(configuration);
    // Then
    for (String keyPrefix : keyPrefixes) {
        assertThat(keyPrefix, configuration.containsKey(keyPrefix + "markocurrences"), is(equalTo(false)));
        assertThat(keyPrefix, configuration.getProperty(keyPrefix + "markoccurrences"), is(equalTo("true")));
    }
    assertThat(configuration.getProperty(unrelatedKey), is(equalTo("abc")));
}
Also used : ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Test(org.junit.jupiter.api.Test)

Example 65 with ZapXmlConfiguration

use of org.zaproxy.zap.utils.ZapXmlConfiguration in project zaproxy by zaproxy.

the class AbstractPluginUnitTest method shouldSaveToConfig.

@Test
void shouldSaveToConfig() {
    // Given
    AbstractPlugin plugin = createAbstractPluginWithConfig(10);
    plugin.setAlertThreshold(Plugin.AlertThreshold.HIGH);
    plugin.setAttackStrength(Plugin.AttackStrength.INSANE);
    Configuration config = new ZapXmlConfiguration();
    String basePropertyKey = "plugins.p" + plugin.getId() + ".";
    // When
    plugin.saveTo(config);
    // Then
    assertThat(config.getString(basePropertyKey + "enabled"), is(equalTo("true")));
    assertThat(config.getString(basePropertyKey + "level"), is(equalTo(Plugin.AlertThreshold.HIGH.name())));
    assertThat(config.getString(basePropertyKey + "strength"), is(equalTo(Plugin.AttackStrength.INSANE.name())));
}
Also used : Configuration(org.apache.commons.configuration.Configuration) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)82 Test (org.junit.jupiter.api.Test)37 Configuration (org.apache.commons.configuration.Configuration)19 WithConfigsTest (org.zaproxy.zap.WithConfigsTest)18 Context (org.zaproxy.zap.model.Context)17 ConfigurationException (org.apache.commons.configuration.ConfigurationException)15 File (java.io.File)11 IOException (java.io.IOException)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ConversionException (org.apache.commons.configuration.ConversionException)6 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)5 InvalidParameterException (java.security.InvalidParameterException)4 HttpMessage (org.parosproxy.paros.network.HttpMessage)4 MalformedURLException (java.net.MalformedURLException)3 Path (java.nio.file.Path)3 ParseException (java.text.ParseException)3 ArrayList (java.util.ArrayList)3 Locale (java.util.Locale)3 NoSuchElementException (java.util.NoSuchElementException)3 URI (org.apache.commons.httpclient.URI)3