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