Search in sources :

Example 41 with ZapXmlConfiguration

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

the class APIUnitTest method shouldDenyHostnameNotSet.

@Test
public void shouldDenyHostnameNotSet() throws Exception {
    // Given
    API api = new API();
    OptionsParamApi apiOptions = new OptionsParamApi();
    apiOptions.load(new ZapXmlConfiguration());
    apiOptions.setPermittedAddresses(createPermittedAddresses("127.0.0.1", "localhost"));
    api.setOptionsParamApi(apiOptions);
    TestApiImplementor apiImplementor = new TestApiImplementor();
    String requestUri = api.getCallBackUrl(apiImplementor, "http://example.com");
    // When
    boolean requestHandled = api.handleApiRequest(createApiRequest(new byte[] { 127, 0, 0, 1 }, "example.com", requestUri), createMockedHttpInputStream(), createMockedHttpOutputStream());
    // Then
    assertThat(requestHandled, is(equalTo(true)));
    assertThat(apiImplementor.wasUsed(), is(equalTo(false)));
}
Also used : ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) Test(org.junit.Test)

Example 42 with ZapXmlConfiguration

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

the class DriverConfiguration method write.

public void write() {
    if (file == null) {
        fireStateChanged();
        return;
    }
    ZapXmlConfiguration configuration = new ZapXmlConfiguration();
    configuration.setRootElementName("driverConfiguration");
    for (int i = 0; i < names.size(); i++) {
        String baseKey = "driver(" + i + ").";
        configuration.setProperty(baseKey + "name", names.get(i));
        configuration.setProperty(baseKey + "path", paths.get(i));
        configuration.setProperty(baseKey + "slot", slots.get(i).toString());
        configuration.setProperty(baseKey + "slotListIndex", slotListIndexes.get(i).toString());
    }
    try {
        configuration.save(file);
    } catch (ConfigurationException e) {
        logger.error("Failed to save driver configuration to " + file, e);
    }
    fireStateChanged();
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration)

Example 43 with ZapXmlConfiguration

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

the class DriverConfiguration method load.

private void load() {
    names = new Vector<>();
    paths = new Vector<>();
    slots = new Vector<>();
    slotListIndexes = new Vector<>();
    try {
        ZapXmlConfiguration configuration = file != null ? new ZapXmlConfiguration(file) : new ZapXmlConfiguration(url);
        List<HierarchicalConfiguration> drivers = configuration.configurationsAt("driver");
        for (HierarchicalConfiguration driver : drivers) {
            names.add(driver.getString("name", ""));
            paths.add(driver.getString("path", ""));
            slots.add(getInt(driver.getString("slot")));
            slotListIndexes.add(getInt(driver.getString("slotListIndex")));
        }
    } catch (ConfigurationException e) {
        logger.error("Failed to read the configuration from " + (file != null ? file : url), e);
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 44 with ZapXmlConfiguration

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

the class Constant method upgradeFrom1_2_0.

private void upgradeFrom1_2_0(XMLConfiguration config) throws ConfigurationException {
    // Upgrade the regexs
    // ZAP: Changed to use ZapXmlConfiguration, to enforce the same character encoding when
    // reading/writing configurations.
    XMLConfiguration newConfig = new ZapXmlConfiguration(getUrlDefaultConfigFile());
    newConfig.setAutoSave(false);
    copyProperty(newConfig, config, "view.brkPanelView");
    copyProperty(newConfig, config, "view.showMainToolbar");
}
Also used : XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration)

Example 45 with ZapXmlConfiguration

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

the class PolicyManager method savePolicy.

public void savePolicy(ScanPolicy policy, String previousName) throws ConfigurationException {
    logger.debug("Save policy " + policy.getName());
    File file = new File(Constant.getPoliciesDir(), policy.getName() + POLICY_EXTENSION);
    ZapXmlConfiguration conf = new ZapXmlConfiguration();
    conf.setProperty("policy", policy.getName());
    conf.setProperty("scanner.level", policy.getDefaultThreshold().name());
    conf.setProperty("scanner.strength", policy.getDefaultStrength().name());
    policy.getPluginFactory().saveTo(conf);
    conf.save(file);
    if (previousName != null && previousName.length() > 0) {
        allPolicyNames.remove(previousName);
    }
    if (!allPolicyNames.contains(policy.getName())) {
        allPolicyNames.add(policy.getName());
        Collections.sort(allPolicyNames);
    }
}
Also used : ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) File(java.io.File)

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