CookiesUtil.java

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

Mutations

24

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

25

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

26

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

30

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

37

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

39

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

42

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

43

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

44

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

46

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

54

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

60

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

62

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

64

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

65

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

78

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