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)));
}
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;
}
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);
}
}
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")));
}
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())));
}
Aggregations