| 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.regex.Matcher; | |
| 11 | import java.util.regex.Pattern; | |
| 12 | ||
| 13 | public class MultipartUtil { | |
| 14 | ||
| 15 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
| 16 | ||
| 17 | private final InjectionModel injectionModel; | |
| 18 | ||
| 19 | public MultipartUtil(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 | LOGGER.log( | |
| 26 | LogLevelUtil.CONSOLE_DEFAULT, | |
| 27 | "{} [multipart] params...", | |
| 28 |
1
1. lambda$testParameters$0 : replaced return value with null for com/jsql/util/MultipartUtil::lambda$testParameters$0 → NO_COVERAGE |
() -> I18nUtil.valueByKey(AbstractMethodInjection.LOG_CHECKING) |
| 29 | ); | |
| 30 | } else { | |
| 31 |
1
1. testParameters : replaced boolean return with false for com/jsql/util/MultipartUtil::testParameters → NO_COVERAGE |
return true; |
| 32 | } | |
| 33 | | |
| 34 | String rawHeader = this.injectionModel.getMediatorUtils().parameterUtil().getRawHeader(); | |
| 35 | String rawRequest = this.injectionModel.getMediatorUtils().parameterUtil().getRawRequest(); | |
| 36 | ||
| 37 | Matcher matcherBoundary = Pattern.compile("boundary=([^;]*)").matcher(rawHeader); | |
| 38 |
1
1. testParameters : negated conditional → NO_COVERAGE |
if (!matcherBoundary.find()) { |
| 39 |
1
1. testParameters : replaced boolean return with true for com/jsql/util/MultipartUtil::testParameters → NO_COVERAGE |
return false; |
| 40 | } | |
| 41 | | |
| 42 | String boundary = matcherBoundary.group(1); | |
| 43 | ||
| 44 | Matcher matcherFormDataParameters = Pattern | |
| 45 | .compile("Content-Disposition\\s*:\\s*form-data\\s*;\\s*name\\s*=\"(.*?)\"(.*?)--" + boundary, Pattern.DOTALL) | |
| 46 | .matcher(rawRequest); | |
| 47 | ||
| 48 |
1
1. testParameters : negated conditional → NO_COVERAGE |
while (matcherFormDataParameters.find()) { |
| 49 |
1
1. testParameters : negated conditional → NO_COVERAGE |
if (this.isBoundaryInjectable(rawRequest, boundary, matcherFormDataParameters)) { |
| 50 |
1
1. testParameters : replaced boolean return with false for com/jsql/util/MultipartUtil::testParameters → NO_COVERAGE |
return true; |
| 51 | } | |
| 52 | } | |
| 53 |
1
1. testParameters : replaced boolean return with true for com/jsql/util/MultipartUtil::testParameters → NO_COVERAGE |
return false; |
| 54 | } | |
| 55 | ||
| 56 | private boolean isBoundaryInjectable(String rawRequest, String boundary, Matcher matcherFormDataParameters) { | |
| 57 | String nameParameter = matcherFormDataParameters.group(1); | |
| 58 | String valueParameter = matcherFormDataParameters.group(2); | |
| 59 | ||
| 60 | String rawRequestWithStar = rawRequest.replaceAll( | |
| 61 | "(?i)(Content-Disposition\\s*:\\s*form-data\\s*;\\s*name\\s*=\\s*\"" + nameParameter + "\".*?)([\\\\r\\\\n]*--" + boundary + ")", | |
| 62 | "$1" + InjectionModel.STAR + "$2" | |
| 63 | ); | |
| 64 | ||
| 65 |
1
1. isBoundaryInjectable : removed call to com/jsql/util/ParameterUtil::initRequest → NO_COVERAGE |
this.injectionModel.getMediatorUtils().parameterUtil().initRequest(rawRequestWithStar); |
| 66 | ||
| 67 | try { | |
| 68 | LOGGER.log( | |
| 69 | LogLevelUtil.CONSOLE_INFORM, | |
| 70 | "{} multipart boundary {}={}", | |
| 71 |
1
1. lambda$isBoundaryInjectable$1 : replaced return value with null for com/jsql/util/MultipartUtil::lambda$isBoundaryInjectable$1 → NO_COVERAGE |
() -> I18nUtil.valueByKey(AbstractMethodInjection.LOG_CHECKING), |
| 72 |
1
1. lambda$isBoundaryInjectable$2 : replaced return value with null for com/jsql/util/MultipartUtil::lambda$isBoundaryInjectable$2 → NO_COVERAGE |
() -> nameParameter, |
| 73 |
1
1. lambda$isBoundaryInjectable$3 : replaced return value with null for com/jsql/util/MultipartUtil::lambda$isBoundaryInjectable$3 → NO_COVERAGE |
() -> valueParameter.replace(InjectionModel.STAR, StringUtils.EMPTY) |
| 74 | ); | |
| 75 |
2
1. isBoundaryInjectable : replaced boolean return with false for com/jsql/util/MultipartUtil::isBoundaryInjectable → NO_COVERAGE 2. isBoundaryInjectable : replaced boolean return with true for com/jsql/util/MultipartUtil::isBoundaryInjectable → NO_COVERAGE |
return this.injectionModel.getMediatorMethod().getRequest().testParameters(); |
| 76 | } catch (JSqlException e) { | |
| 77 | LOGGER.log( | |
| 78 | LogLevelUtil.CONSOLE_ERROR, | |
| 79 | String.format( | |
| 80 | "No Multipart boundary injection for %s=%s", | |
| 81 | nameParameter, | |
| 82 | valueParameter.replace(InjectionModel.STAR, StringUtils.EMPTY) | |
| 83 | ) | |
| 84 | ); | |
| 85 | } | |
| 86 |
1
1. isBoundaryInjectable : replaced boolean return with true for com/jsql/util/MultipartUtil::isBoundaryInjectable → NO_COVERAGE |
return false; |
| 87 | } | |
| 88 | } | |
Mutations | ||
| 24 |
1.1 |
|
| 28 |
1.1 |
|
| 31 |
1.1 |
|
| 38 |
1.1 |
|
| 39 |
1.1 |
|
| 48 |
1.1 |
|
| 49 |
1.1 |
|
| 50 |
1.1 |
|
| 53 |
1.1 |
|
| 65 |
1.1 |
|
| 71 |
1.1 |
|
| 72 |
1.1 |
|
| 73 |
1.1 |
|
| 75 |
1.1 2.2 |
|
| 86 |
1.1 |