CookiesUtil.java

1
package com.jsql.util;
2
3
import com.jsql.model.InjectionModel;
4
import com.jsql.model.exception.JSqlException;
5
import com.jsql.model.injection.method.AbstractMethodInjection;
6
import org.apache.commons.lang3.StringUtils;
7
import org.apache.logging.log4j.LogManager;
8
import org.apache.logging.log4j.Logger;
9
10
import java.util.AbstractMap;
11
import java.util.List;
12
import java.util.stream.Stream;
13
14
public class CookiesUtil {
15
16
    private static final Logger LOGGER = LogManager.getRootLogger();
17
    public static final String COOKIE = "Cookie";
18
19
    private final InjectionModel injectionModel;
20
21
    public CookiesUtil(InjectionModel injectionModel) {
22
        this.injectionModel = injectionModel;
23
    }
24
25
    public boolean testParameters(boolean hasFoundInjection) {
26 1 1. testParameters : negated conditional → NO_COVERAGE
        if (!hasFoundInjection) {
27 1 1. testParameters : negated conditional → NO_COVERAGE
            if (!this.injectionModel.getMediatorUtils().preferencesUtil().isCheckingAllCookieParam()) {
28 1 1. testParameters : replaced boolean return with true for com/jsql/util/CookiesUtil::testParameters → NO_COVERAGE
                return false;
29
            }
30
            LOGGER.log(
31
                LogLevelUtil.CONSOLE_DEFAULT,
32
                "{} cookies...",
33 1 1. lambda$testParameters$0 : replaced return value with null for com/jsql/util/CookiesUtil::lambda$testParameters$0 → NO_COVERAGE
                () -> I18nUtil.valueByKey(AbstractMethodInjection.LOG_CHECKING)
34
            );
35
        } else {
36 1 1. testParameters : replaced boolean return with false for com/jsql/util/CookiesUtil::testParameters → NO_COVERAGE
            return true;
37
        }
38
39
        String rawHeader = this.injectionModel.getMediatorUtils().parameterUtil().getRawHeader();
40
41
        List<AbstractMap.SimpleEntry<String, String>> cookies = this.injectionModel.getMediatorUtils().parameterUtil().getListHeader()
42
            .stream()
43 2 1. lambda$testParameters$1 : replaced boolean return with false for com/jsql/util/CookiesUtil::lambda$testParameters$1 → NO_COVERAGE
2. lambda$testParameters$1 : replaced boolean return with true for com/jsql/util/CookiesUtil::lambda$testParameters$1 → NO_COVERAGE
            .filter(entry -> CookiesUtil.COOKIE.equalsIgnoreCase(entry.getKey()))
44
            .findFirst()
45 1 1. lambda$testParameters$2 : replaced return value with null for com/jsql/util/CookiesUtil::lambda$testParameters$2 → NO_COVERAGE
            .map(cookieHeader -> cookieHeader.getValue().split(";"))
46
            .stream()
47
            .flatMap(Stream::of)
48 3 1. lambda$testParameters$3 : negated conditional → NO_COVERAGE
2. lambda$testParameters$3 : negated conditional → NO_COVERAGE
3. lambda$testParameters$3 : replaced boolean return with true for com/jsql/util/CookiesUtil::lambda$testParameters$3 → NO_COVERAGE
            .filter(cookie -> cookie != null && cookie.contains("="))
49 1 1. lambda$testParameters$4 : replaced return value with null for com/jsql/util/CookiesUtil::lambda$testParameters$4 → NO_COVERAGE
            .map(cookie -> cookie.split("=", 2))
50 1 1. lambda$testParameters$5 : replaced return value with null for com/jsql/util/CookiesUtil::lambda$testParameters$5 → NO_COVERAGE
            .map(arrayEntry -> new AbstractMap.SimpleEntry<>(
51
                arrayEntry[0].trim(),
52 1 1. lambda$testParameters$5 : negated conditional → NO_COVERAGE
                arrayEntry[1] == null ? StringUtils.EMPTY : arrayEntry[1].trim()
53
            ))
54
            .toList();
55
56
        for (AbstractMap.SimpleEntry<String, String> cookie: cookies) {
57
            String keyValue = cookie.getKey() + "=" + cookie.getValue();
58
            String headerCookieWithStar = rawHeader.replace(keyValue, keyValue + InjectionModel.STAR);
59
60 1 1. testParameters : removed call to com/jsql/util/ParameterUtil::initHeader → NO_COVERAGE
            this.injectionModel.getMediatorUtils().parameterUtil().initHeader(headerCookieWithStar);
61
62
            try {
63
                LOGGER.log(
64
                    LogLevelUtil.CONSOLE_DEFAULT,
65
                    "{} cookie [key:{}, value:{}]",
66 1 1. lambda$testParameters$6 : replaced return value with null for com/jsql/util/CookiesUtil::lambda$testParameters$6 → NO_COVERAGE
                    () -> I18nUtil.valueByKey(AbstractMethodInjection.LOG_CHECKING),
67
                    cookie::getKey,
68 1 1. lambda$testParameters$7 : replaced return value with null for com/jsql/util/CookiesUtil::lambda$testParameters$7 → NO_COVERAGE
                    () -> cookie.getValue().replace(InjectionModel.STAR, StringUtils.EMPTY)
69
                );
70 1 1. testParameters : negated conditional → NO_COVERAGE
                if (this.injectionModel.getMediatorMethod().getHeader().testParameters()) {
71 1 1. testParameters : replaced boolean return with false for com/jsql/util/CookiesUtil::testParameters → NO_COVERAGE
                    return true;
72
                }
73
            } catch (JSqlException e) {
74
                LOGGER.log(
75
                    LogLevelUtil.CONSOLE_ERROR,
76
                    String.format(
77
                        "No Cookie injection for %s=%s",
78
                        cookie.getKey(),
79
                        cookie.getValue().replace(InjectionModel.STAR, StringUtils.EMPTY)
80
                    )
81
                );
82
            }
83
        }
84 1 1. testParameters : replaced boolean return with true for com/jsql/util/CookiesUtil::testParameters → NO_COVERAGE
        return false;
85
    }
86
}

Mutations

26

1.1
Location : testParameters
Killed by : none
negated conditional → NO_COVERAGE

27

1.1
Location : testParameters
Killed by : none
negated conditional → NO_COVERAGE

28

1.1
Location : testParameters
Killed by : none
replaced boolean return with true for com/jsql/util/CookiesUtil::testParameters → NO_COVERAGE

33

1.1
Location : lambda$testParameters$0
Killed by : none
replaced return value with null for com/jsql/util/CookiesUtil::lambda$testParameters$0 → NO_COVERAGE

36

1.1
Location : testParameters
Killed by : none
replaced boolean return with false for com/jsql/util/CookiesUtil::testParameters → NO_COVERAGE

43

1.1
Location : lambda$testParameters$1
Killed by : none
replaced boolean return with false for com/jsql/util/CookiesUtil::lambda$testParameters$1 → NO_COVERAGE

2.2
Location : lambda$testParameters$1
Killed by : none
replaced boolean return with true for com/jsql/util/CookiesUtil::lambda$testParameters$1 → NO_COVERAGE

45

1.1
Location : lambda$testParameters$2
Killed by : none
replaced return value with null for com/jsql/util/CookiesUtil::lambda$testParameters$2 → NO_COVERAGE

48

1.1
Location : lambda$testParameters$3
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : lambda$testParameters$3
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : lambda$testParameters$3
Killed by : none
replaced boolean return with true for com/jsql/util/CookiesUtil::lambda$testParameters$3 → NO_COVERAGE

49

1.1
Location : lambda$testParameters$4
Killed by : none
replaced return value with null for com/jsql/util/CookiesUtil::lambda$testParameters$4 → NO_COVERAGE

50

1.1
Location : lambda$testParameters$5
Killed by : none
replaced return value with null for com/jsql/util/CookiesUtil::lambda$testParameters$5 → NO_COVERAGE

52

1.1
Location : lambda$testParameters$5
Killed by : none
negated conditional → NO_COVERAGE

60

1.1
Location : testParameters
Killed by : none
removed call to com/jsql/util/ParameterUtil::initHeader → NO_COVERAGE

66

1.1
Location : lambda$testParameters$6
Killed by : none
replaced return value with null for com/jsql/util/CookiesUtil::lambda$testParameters$6 → NO_COVERAGE

68

1.1
Location : lambda$testParameters$7
Killed by : none
replaced return value with null for com/jsql/util/CookiesUtil::lambda$testParameters$7 → NO_COVERAGE

70

1.1
Location : testParameters
Killed by : none
negated conditional → NO_COVERAGE

71

1.1
Location : testParameters
Killed by : none
replaced boolean return with false for com/jsql/util/CookiesUtil::testParameters → NO_COVERAGE

84

1.1
Location : testParameters
Killed by : none
replaced boolean return with true for com/jsql/util/CookiesUtil::testParameters → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.22.1