<commit_before>/*******************************************************************************
 * BDD-Security, application security testing framework
 * <p/>
 * Copyright (C) `2014 <NAME>`
 * <p/>
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * <p/>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * <p/>
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see `<http://www.gnu.org/licenses/>`.
 ******************************************************************************/
package net.continuumsecurity.steps;

import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import net.continuumsecurity.Config;
import net.continuumsecurity.UnexpectedContentException;
import net.continuumsecurity.ZAPFalsePositive;
import net.continuumsecurity.behaviour.INavigable;
import net.continuumsecurity.proxy.ContextModifier;
import net.continuumsecurity.proxy.Spider;
import net.continuumsecurity.proxy.ZAProxyScanner;
import net.continuumsecurity.web.Application;
import org.apache.log4j.Logger;
import org.zaproxy.clientapi.core.Alert;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

public class AppScanningSteps {
    Logger log = Logger.getLogger(AppScanningSteps.class);
    private ZAProxyScanner scanner;
    Application app;
    List<Alert> alerts = new ArrayList<Alert>();
    String scannerIds = null;
    private final static String ZAP_CONTEXT_NAME= "Default Context";

    public AppScanningSteps() {
        app = Config.getInstance().createApp();
    }

    @Given("the passive scanner has already run during the app navigation")
    public void runPassiveScanner() {
        //Do nothing, it has already run during navigation
    }

    @Given("a new scanning session")
    public void createNewScanSession() {
        app.enableHttpLoggingClient();
    }

    @Given("all existing alerts are deleted")
    public void deleteAlerts() {
        getScanner().deleteAlerts();
        alerts.clear();
    }

    @Given("a scanner with all policies disabled")
    public void disableAllScanners() {
        getScanner().disableAllScanners();
    }

    public ZAProxyScanner getScanner() {
        if (scanner == null) {
            scanner = new ZAProxyScanner(Config.getInstance().getProxyHost(), Config.getInstance().getProxyPort(), Config.getInstance().getProxyApi());
            scanner.setAttackMode();
        }
        return scanner;
    }

    public Spider getSpider() {
        return (Spider) getScanner();
    }

    public ContextModifier getContext() {
        return (ContextModifier) getScanner();
    }

    @When("the XML report is written to the file (.*)")
    public void writeXmlReport(String path) throws IOException {
        byte[] xmlReport = scanner.getXmlReport();
        Path pathToFile = Paths.get(path);
        Files.createDirectories(pathToFile.getParent());
        Files.write(pathToFile, xmlReport);
    }

    @Given("a scanner with all policies enabled")
    public void enableAllScanners() {
        getScanner().enableAllScanners();<commit_msg>Update AppScanningSteps.java<commit_after>/*******************************************************************************
 * BDD-Security, application security testing framework
 * <p/>
 * Copyright (C) `2014 <NAME>`
 * <p/>
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * <p/>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * <p/>
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see `<http://www.gnu.org/licenses/>`.
 ******************************************************************************/
package net.continuumsecurity.steps;

import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import net.continuumsecurity.Config;
import net.continuumsecurity.UnexpectedContentException;
import net.continuumsecurity.ZAPFalsePositive;
import net.continuumsecurity.behaviour.INavigable;
import net.continuumsecurity.proxy.ContextModifier;
import net.continuumsecurity.proxy.Spider;
import net.continuumsecurity.proxy.ZAProxyScanner;
import net.continuumsecurity.web.Application;
import org.apache.log4j.Logger;
import org.zaproxy.clientapi.core.Alert;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

public class AppScanningSteps {
    Logger log = Logger.getLogger(AppScanningSteps.class);
    private ZAProxyScanner scanner;
    Application app;
    List<Alert> alerts = new ArrayList<Alert>();
    String scannerIds = null;
    private final static String ZAP_CONTEXT_NAME= "Default Context";

    public AppScanningSteps() {
        app = Config.getInstance().createApp();
    }

    @Given("the passive scanner has already run during the app navigation")
    public void runPassiveScanner() {
        //Do nothing, it has already run during navigation
    }

    @Given("a new scanning session")
    public void createNewScanSession() {
        app.enableHttpLoggingClient();
    }

    @Given("all existing alerts are deleted")
    public void deleteAlerts() {
        getScanner().deleteAlerts();
        alerts.clear();
    }

    @Given("a scanner with all policies disabled")
    public void disableAllScanners() {
        getScanner().disableAllScanners();
    }

    public ZAProxyScanner getScanner() {
        if (scanner == null) {
            scanner = new ZAProxyScanner(Config.getInstance().getProxyHost(), Config.getInstance().getProxyPort(), Config.getInstance().getProxyApi());
            scanner.setAttackMode();
        }
        return scanner;
    }

    public Spider getSpider() {
        return (Spider) getScanner();
    }

    public ContextModifier getContext() {
        return (ContextModifier) getScanner();
    }

    @When("the XML report is written to the file (.*)")
    public void writeXmlReport(String path) throws IOException {
        byte[] xmlReport = scanner.getXmlReport();
        Path pathToFile = Paths.get(path);
        Files.createDirectories(pathToFile.getParent());
        Files.write(pathToFile, xmlReport);
    }

    @Then("the HTML report is written to the file (.*)")
    public void writeHtmlReport(String path) throws IOException {
        byte[] htmlReport = scanner.getHtmlReport();
        Path pathToFile = Paths.get(path);
        Files.createDirectories(pathToFile.getParent());
        Files.write(pathToFile, htmlReport);
    }

    @Given("a scanner with all policies enabled")
    public void enableAllScanners() {
        getScanner().enableAllScanners();
{'fraction_non_alphanumeric': 0.13558461343150946, 'fraction_numerical': 0.001523422622825949, 'mean_word_length': 3.875, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3019250', 'n_tokens_mistral': 2181, 'n_tokens_neox': 2091, 'n_words': 625}