Search in sources :

Example 36 with ZapXmlConfiguration

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

the class ScanPolicyUnitTest method shouldUseValidDefaultScannerStrengthFromConfig.

@Test
void shouldUseValidDefaultScannerStrengthFromConfig() throws Exception {
    // Given
    ZapXmlConfiguration conf = new ZapXmlConfiguration();
    conf.setProperty(DEFAULT_SCANNER_STRENGTH_KEY, Plugin.AttackStrength.LOW.name());
    // When
    ScanPolicy scanPolicy = new ScanPolicy(conf);
    // Then
    assertThat(scanPolicy.getDefaultStrength(), is(equalTo(Plugin.AttackStrength.LOW)));
}
Also used : ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) Test(org.junit.jupiter.api.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Example 37 with ZapXmlConfiguration

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

the class ScanPolicyUnitTest method shouldUseMediumIfInvalidDefaultScannerStrengthFromConfig.

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

Example 38 with ZapXmlConfiguration

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

the class ScanPolicyUnitTest method shouldUseValidDefaultScannerLevelFromConfig.

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

Example 39 with ZapXmlConfiguration

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

the class ExtensionParamUnitTest method createMalformedTestConfig.

private static FileConfiguration createMalformedTestConfig() {
    ZapXmlConfiguration config = new ZapXmlConfiguration();
    for (int i = 0; i < 3; ++i) {
        String elementBaseKey = "extensions.extension(" + i + ").";
        config.setProperty(elementBaseKey, null);
        config.setProperty(elementBaseKey + "enabled", "X");
    }
    return config;
}
Also used : ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration)

Example 40 with ZapXmlConfiguration

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

the class VulnerabilitiesLoader method loadVulnerabilitiesFile.

private List<Vulnerability> loadVulnerabilitiesFile(Path file) {
    ZapXmlConfiguration config;
    try {
        config = new ZapXmlConfiguration(file.toFile());
    } catch (ConfigurationException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
    String[] test;
    try {
        test = config.getStringArray("vuln_items");
    } catch (ConversionException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
    final int numberOfVulns = test.length;
    List<Vulnerability> tempVulns = new ArrayList<>(numberOfVulns);
    String name;
    List<String> references;
    for (String item : test) {
        name = "vuln_item_" + item;
        try {
            references = new ArrayList<>(Arrays.asList(config.getStringArray(name + ".reference")));
        } catch (ConversionException e) {
            logger.error(e.getMessage(), e);
            references = new ArrayList<>(0);
        }
        Vulnerability v = new Vulnerability(item, config.getString(name + ".alert"), config.getString(name + ".desc"), config.getString(name + ".solution"), references);
        tempVulns.add(v);
    }
    return tempVulns;
}
Also used : ConversionException(org.apache.commons.configuration.ConversionException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ArrayList(java.util.ArrayList) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration)

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