<commit_before>/*
 * Zed Attack Proxy (ZAP) and its related class files.
 *
 * ZAP is an HTTP/HTTPS proxy for assessing web application security.
 *
 * Copyright 2021 The ZAP Development Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.zaproxy.addon.automation;

import java.io.File;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.parosproxy.paros.Constant;
import org.parosproxy.paros.control.Control;
import org.zaproxy.addon.automation.jobs.JobUtils;
import org.zaproxy.zap.extension.script.ScriptWrapper;
import org.zaproxy.zap.extension.sessions.ExtensionSessionManagement;
import org.zaproxy.zap.model.Context;
import org.zaproxy.zap.session.CookieBasedSessionManagementMethodType.CookieBasedSessionManagementMethod;
import org.zaproxy.zap.session.HttpAuthSessionManagementMethodType.HttpAuthSessionManagementMethod;
import org.zaproxy.zap.session.ScriptBasedSessionManagementMethodType;
import org.zaproxy.zap.session.ScriptBasedSessionManagementMethodType.ScriptBasedSessionManagementMethod;
import org.zaproxy.zap.session.SessionManagementMethod;
import org.zaproxy.zap.session.SessionManagementMethodType;
import org.zaproxy.zap.utils.ZapXmlConfiguration;

public class SessionManagementData extends AutomationData {

    public static final String METHOD_COOKIE = "cookie";
    public static final String METHOD_HTTP = "http";
    public static final String METHOD_SCRIPT = "script";

    public static final String PARAM_SCRIPT = "script";
    public static final String PARAM_SCRIPT_ENGINE = "scriptEngine";

    private static List<String> validMethods =
            Arrays.asList(METHOD_COOKIE, METHOD_HTTP, METHOD_SCRIPT);

    private static final String SCRIPT_SESSION_MANAGEMENT_SCRIPT_FIELD = "script";
    private static final String SCRIPT_SESSION_MANAGEMENT_PARAM_VALUES_FIELD = "paramValues";

    private String method;
    private Map<String, String> parameters = new LinkedHashMap<>();

    private static final Logger LOG = LogManager.getLogger(SessionManagementData.class);

    public SessionManagementData() {}

    @SuppressWarnings("unchecked")
    public SessionManagementData(Context context) {
        SessionManagementMethod contextMethod = context.getSessionManagementMethod();
        if (contextMethod != null) {
            if (contextMethod instanceof CookieBasedSessionManagementMethod) {
                setMethod(SessionManagementData.METHOD_COOKIE);
            } else if (contextMethod instanceof HttpAuthSessionManagementMethod) {
                setMethod(SessionManagementData.METHOD_HTTP);
            } else if (contextMethod instanceof ScriptBasedSessionManagementMethod) {
                setMethod(SessionManagementData.METHOD_SCRIPT);
                ScriptWrapper wrapper =
                        (ScriptWrapper)
                                JobUtils.getPrivateField(
                                        contextMethod, SCRIPT_SESSION_MANAGEMENT_SCRIPT_FIELD);
                if (wrapper != null) {
                    Object paramValues =
                            JobUtils.getPrivateField(
                                    contextMethod, SCRIPT_SESSION_MANAGEMENT_PARAM_VALUES_FIELD);
                    if (paramValues instanceof Map<?, ?>) {
                        setParameters((Map<String, String>) paramValues);
                    }
                    getParameters().put(METHOD_SCRIPT, wrapper.getFile().getAbsolutePath());
                    getParameters().put(PARAM_SCRIPT_ENGINE, wrapper.getFile().getAbsolutePath());
                }
            }
        }
    }

    public SessionManagementData(Object data, AutomationProgress progress) {<commit_msg>Automation: fix silly error<commit_after>/*
 * Zed Attack Proxy (ZAP) and its related class files.
 *
 * ZAP is an HTTP/HTTPS proxy for assessing web application security.
 *
 * Copyright 2021 The ZAP Development Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.zaproxy.addon.automation;

import java.io.File;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.parosproxy.paros.Constant;
import org.parosproxy.paros.control.Control;
import org.zaproxy.addon.automation.jobs.JobUtils;
import org.zaproxy.zap.extension.script.ScriptWrapper;
import org.zaproxy.zap.extension.sessions.ExtensionSessionManagement;
import org.zaproxy.zap.model.Context;
import org.zaproxy.zap.session.CookieBasedSessionManagementMethodType.CookieBasedSessionManagementMethod;
import org.zaproxy.zap.session.HttpAuthSessionManagementMethodType.HttpAuthSessionManagementMethod;
import org.zaproxy.zap.session.ScriptBasedSessionManagementMethodType;
import org.zaproxy.zap.session.ScriptBasedSessionManagementMethodType.ScriptBasedSessionManagementMethod;
import org.zaproxy.zap.session.SessionManagementMethod;
import org.zaproxy.zap.session.SessionManagementMethodType;
import org.zaproxy.zap.utils.ZapXmlConfiguration;

public class SessionManagementData extends AutomationData {

    public static final String METHOD_COOKIE = "cookie";
    public static final String METHOD_HTTP = "http";
    public static final String METHOD_SCRIPT = "script";

    public static final String PARAM_SCRIPT = "script";
    public static final String PARAM_SCRIPT_ENGINE = "scriptEngine";

    private static List<String> validMethods =
            Arrays.asList(METHOD_COOKIE, METHOD_HTTP, METHOD_SCRIPT);

    private static final String SCRIPT_SESSION_MANAGEMENT_SCRIPT_FIELD = "script";
    private static final String SCRIPT_SESSION_MANAGEMENT_PARAM_VALUES_FIELD = "paramValues";

    private String method;
    private Map<String, String> parameters = new LinkedHashMap<>();

    private static final Logger LOG = LogManager.getLogger(SessionManagementData.class);

    public SessionManagementData() {}

    @SuppressWarnings("unchecked")
    public SessionManagementData(Context context) {
        SessionManagementMethod contextMethod = context.getSessionManagementMethod();
        if (contextMethod != null) {
            if (contextMethod instanceof CookieBasedSessionManagementMethod) {
                setMethod(SessionManagementData.METHOD_COOKIE);
            } else if (contextMethod instanceof HttpAuthSessionManagementMethod) {
                setMethod(SessionManagementData.METHOD_HTTP);
            } else if (contextMethod instanceof ScriptBasedSessionManagementMethod) {
                setMethod(SessionManagementData.METHOD_SCRIPT);
                ScriptWrapper wrapper =
                        (ScriptWrapper)
                                JobUtils.getPrivateField(
                                        contextMethod, SCRIPT_SESSION_MANAGEMENT_SCRIPT_FIELD);
                if (wrapper != null) {
                    Object paramValues =
                            JobUtils.getPrivateField(
                                    contextMethod, SCRIPT_SESSION_MANAGEMENT_PARAM_VALUES_FIELD);
                    if (paramValues instanceof Map<?, ?>) {
                        setParameters((Map<String, String>) paramValues);
                    }
                    getParameters().put(METHOD_SCRIPT, wrapper.getFile().getAbsolutePath());
                    getParameters().put(PARAM_SCRIPT_ENGINE, wrapper.getEngineName());
                }
            }
        }
    }

    public SessionManagementData(Object data, AutomationProgress progress) {
{'fraction_non_alphanumeric': 0.0749113475177305, 'fraction_numerical': 0.0024379432624113476, 'mean_word_length': 3.4305351006381932, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4158278', 'n_tokens_mistral': 2381, 'n_tokens_neox': 2274, 'n_words': 567}