StrategyError.java

1
package com.jsql.model.injection.strategy;
2
3
import com.jsql.model.InjectionModel;
4
import com.jsql.model.accessible.DataAccess;
5
import com.jsql.view.subscriber.Seal;
6
import com.jsql.model.injection.engine.model.EngineYaml;
7
import com.jsql.model.injection.engine.model.yaml.Method;
8
import com.jsql.model.suspendable.AbstractSuspendable;
9
import com.jsql.util.I18nUtil;
10
import com.jsql.util.LogLevelUtil;
11
import com.jsql.util.StringUtil;
12
import org.apache.logging.log4j.LogManager;
13
import org.apache.logging.log4j.Logger;
14
15
import java.util.regex.Matcher;
16
import java.util.regex.Pattern;
17
18
public class StrategyError extends AbstractStrategy {
19
    
20
    private static final Logger LOGGER = LogManager.getRootLogger();
21
    
22
    private String[] tabCapacityMethod;
23
    
24
    private int indexErrorStrategy = 0;
25
26
    public StrategyError(InjectionModel injectionModel) {
27
        super(injectionModel);
28
    }
29
30
    @Override
31
    public void checkApplicability() {
32
        // Reset applicability of new engine
33
        this.isApplicable = false;
34
        
35
        var strategyYaml = this.injectionModel.getMediatorEngine().getEngine().instance().getModelYaml().getStrategy();
36
37 1 1. checkApplicability : negated conditional → NO_COVERAGE
        if (this.injectionModel.getMediatorUtils().preferencesUtil().isStrategyErrorDisabled()) {
38
            LOGGER.log(LogLevelUtil.CONSOLE_INFORM, AbstractStrategy.FORMAT_SKIP_STRATEGY_DISABLED, this.getName());
39
            return;
40 1 1. checkApplicability : negated conditional → NO_COVERAGE
        } else if (strategyYaml.getError().getMethod().isEmpty()) {
41
            LOGGER.log(
42
                LogLevelUtil.CONSOLE_INFORM,
43
                AbstractStrategy.FORMAT_STRATEGY_NOT_IMPLEMENTED,
44
                this.getName(),
45
                this.injectionModel.getMediatorEngine().getEngine()
46
            );
47
            return;
48
        }
49
50 1 1. checkApplicability : removed call to com/jsql/model/injection/strategy/StrategyError::logChecking → NO_COVERAGE
        this.logChecking();
51
52
        this.tabCapacityMethod = new String[strategyYaml.getError().getMethod().size()];
53
        var indexErrorMethod = 0;
54
        var errorCapacity = 0;
55
        
56
        for (Method errorMethod: strategyYaml.getError().getMethod()) {
57
            boolean methodIsApplicable = this.isApplicable(errorMethod);
58 1 1. checkApplicability : negated conditional → NO_COVERAGE
            if (methodIsApplicable) {
59
                Matcher regexSearch = this.getPerformance(errorMethod);
60 1 1. checkApplicability : negated conditional → NO_COVERAGE
                if (regexSearch.find()) {
61
                    errorCapacity = this.getCapacity(indexErrorMethod, errorCapacity, errorMethod, regexSearch);
62
                } else {
63
                    LOGGER.log(
64
                        LogLevelUtil.CONSOLE_ERROR,
65
                        "{} {} but injectable size is incorrect",
66 1 1. lambda$checkApplicability$0 : replaced return value with null for com/jsql/model/injection/strategy/StrategyError::lambda$checkApplicability$0 → NO_COVERAGE
                        () -> I18nUtil.valueByKey(AbstractStrategy.KEY_LOG_VULNERABLE),
67
                        errorMethod::getName
68
                    );
69
                    methodIsApplicable = false;
70
                }
71
            }
72
            
73 1 1. checkApplicability : negated conditional → NO_COVERAGE
            if (methodIsApplicable) {
74 1 1. checkApplicability : removed call to com/jsql/model/injection/strategy/StrategyError::allow → NO_COVERAGE
                this.allow(indexErrorMethod);
75
            } else {
76 1 1. checkApplicability : removed call to com/jsql/model/injection/strategy/StrategyError::unallow → NO_COVERAGE
                this.unallow(indexErrorMethod);
77
            }
78 1 1. checkApplicability : Changed increment from 1 to -1 → NO_COVERAGE
            indexErrorMethod++;
79
        }
80
    }
81
82
    private boolean isApplicable(Method errorMethod) {
83
        var methodIsApplicable = false;
84
85
        String performanceSourcePage = this.injectionModel.injectWithoutIndex(
86
            this.injectionModel.getMediatorEngine().getEngine().instance().sqlErrorIndice(errorMethod),
87
            "error#confirm"
88
        );
89
90
        var indexZeroToFind = "0";
91
        String regexIndexZero = String.format(EngineYaml.FORMAT_INDEX, indexZeroToFind);
92 1 1. isApplicable : negated conditional → NO_COVERAGE
        if (performanceSourcePage.matches("(?s).*"+ regexIndexZero +".*")) {
93
            methodIsApplicable = true;
94
            this.isApplicable = true;
95
        }
96 2 1. isApplicable : replaced boolean return with true for com/jsql/model/injection/strategy/StrategyError::isApplicable → NO_COVERAGE
2. isApplicable : replaced boolean return with false for com/jsql/model/injection/strategy/StrategyError::isApplicable → NO_COVERAGE
        return methodIsApplicable;
97
    }
98
99
    private Matcher getPerformance(Method errorMethod) {
100
        String performanceErrorSourcePage = this.injectionModel.injectWithoutIndex(
101
            this.injectionModel.getMediatorEngine().getEngine().instance().sqlErrorCalibrator(errorMethod),
102
            "error#size"
103
        );
104 1 1. getPerformance : replaced return value with null for com/jsql/model/injection/strategy/StrategyError::getPerformance → NO_COVERAGE
        return Pattern.compile("(?s)"+ DataAccess.LEAD +"("+ EngineYaml.CALIBRATOR_SQL +"+)").matcher(performanceErrorSourcePage);
105
    }
106
107
    private int getCapacity(int indexErrorMethod, int errorCapacityDefault, Method errorMethod, Matcher regexSearch) {
108
        int errorCapacityImproved = errorCapacityDefault;
109
        
110
        regexSearch.reset();
111 1 1. getCapacity : negated conditional → NO_COVERAGE
        while (regexSearch.find()) {
112 2 1. getCapacity : changed conditional boundary → NO_COVERAGE
2. getCapacity : negated conditional → NO_COVERAGE
            if (errorCapacityImproved < regexSearch.group(1).length()) {
113
                this.indexErrorStrategy = indexErrorMethod;
114
            }
115
            errorCapacityImproved = regexSearch.group(1).length();
116
            this.tabCapacityMethod[indexErrorMethod] = Integer.toString(errorCapacityImproved);
117
        }
118
        
119
        int logErrorCapacityImproved = errorCapacityImproved;
120
        LOGGER.log(
121
            LogLevelUtil.CONSOLE_SUCCESS,
122
            "{} [Error {}] showing [{}] characters",
123 1 1. lambda$getCapacity$1 : replaced return value with null for com/jsql/model/injection/strategy/StrategyError::lambda$getCapacity$1 → NO_COVERAGE
            () -> I18nUtil.valueByKey(AbstractStrategy.KEY_LOG_VULNERABLE),
124
            errorMethod::getName,
125 1 1. lambda$getCapacity$2 : replaced return value with null for com/jsql/model/injection/strategy/StrategyError::lambda$getCapacity$2 → NO_COVERAGE
            () -> Integer.toString(logErrorCapacityImproved)
126
        );
127
        
128 1 1. getCapacity : replaced int return with 0 for com/jsql/model/injection/strategy/StrategyError::getCapacity → NO_COVERAGE
        return errorCapacityImproved;
129
    }
130
131
    @Override
132
    public void allow(int... indexError) {
133 1 1. allow : removed call to com/jsql/model/InjectionModel::appendAnalysisReport → NO_COVERAGE
        this.injectionModel.appendAnalysisReport(
134
            StringUtil.formatReport(
135
                LogLevelUtil.COLOR_BLU,
136
                "### Strategy: "+ this.getName() +":"+ this.injectionModel.getMediatorEngine().getEngine().instance()
137
                .getModelYaml()
138
                .getStrategy()
139
                .getError()
140
                .getMethod()
141
                .get(indexError[0])
142
                .getName()
143
            )
144
            + this.injectionModel.getReportWithoutIndex(
145
                this.injectionModel.getMediatorEngine().getEngine().instance().sqlError(
146
                    StringUtil.formatReport(LogLevelUtil.COLOR_GREEN, "&lt;query&gt;"),
147
                    "0",
148
                    indexError[0],
149
                    true
150
                ),
151
                "metadataInjectionProcess"
152
            )
153
        );
154 1 1. allow : removed call to com/jsql/model/InjectionModel::sendToViews → NO_COVERAGE
        this.injectionModel.sendToViews(new Seal.MarkStrategyVulnerable(indexError[0], this));
155
    }
156
157
    @Override
158
    public void unallow(int... indexError) {
159 1 1. unallow : removed call to com/jsql/model/InjectionModel::sendToViews → NO_COVERAGE
        this.injectionModel.sendToViews(new Seal.MarkStrategyInvulnerable(indexError[0], this));
160
    }
161
162
    @Override
163
    public String inject(String sqlQuery, String startPosition, AbstractSuspendable stoppable, String metadataInjectionProcess) {
164 1 1. inject : replaced return value with "" for com/jsql/model/injection/strategy/StrategyError::inject → NO_COVERAGE
        return this.injectionModel.injectWithoutIndex(
165
            this.injectionModel.getMediatorEngine().getEngine().instance().sqlError(sqlQuery, startPosition, this.indexErrorStrategy, false),
166
            metadataInjectionProcess
167
        );
168
    }
169
170
    @Override
171
    public void activateWhenApplicable() {
172 2 1. activateWhenApplicable : negated conditional → NO_COVERAGE
2. activateWhenApplicable : negated conditional → NO_COVERAGE
        if (this.injectionModel.getMediatorStrategy().getStrategy() == null && this.isApplicable()) {
173
            LOGGER.log(
174
                LogLevelUtil.CONSOLE_INFORM,
175
                "{} [{} {}]",
176 1 1. lambda$activateWhenApplicable$3 : replaced return value with null for com/jsql/model/injection/strategy/StrategyError::lambda$activateWhenApplicable$3 → NO_COVERAGE
                () -> I18nUtil.valueByKey("LOG_USING_STRATEGY"),
177
                this::getName,
178
                () -> this.injectionModel.getMediatorEngine().getEngine().instance().getModelYaml().getStrategy()
179 1 1. lambda$activateWhenApplicable$4 : replaced return value with null for com/jsql/model/injection/strategy/StrategyError::lambda$activateWhenApplicable$4 → NO_COVERAGE
                .getError().getMethod().get(this.indexErrorStrategy).getName()
180
            );
181 1 1. activateWhenApplicable : removed call to com/jsql/model/injection/strategy/MediatorStrategy::setStrategy → NO_COVERAGE
            this.injectionModel.getMediatorStrategy().setStrategy(this);
182 1 1. activateWhenApplicable : removed call to com/jsql/model/InjectionModel::sendToViews → NO_COVERAGE
            this.injectionModel.sendToViews(new Seal.ActivateStrategy(this));
183
        }
184
    }
185
    
186
    @Override
187
    public String getPerformanceLength() {
188 1 1. getPerformanceLength : replaced return value with "" for com/jsql/model/injection/strategy/StrategyError::getPerformanceLength → NO_COVERAGE
        return this.tabCapacityMethod[this.indexErrorStrategy];
189
    }
190
    
191
    @Override
192
    public String getName() {
193 1 1. getName : replaced return value with "" for com/jsql/model/injection/strategy/StrategyError::getName → NO_COVERAGE
        return "Error";
194
    }
195
    
196
    public Integer getIndexErrorStrategy() {
197 1 1. getIndexErrorStrategy : replaced Integer return value with 0 for com/jsql/model/injection/strategy/StrategyError::getIndexErrorStrategy → NO_COVERAGE
        return this.indexErrorStrategy;
198
    }
199
    
200
    public void setIndexErrorStrategy(int indexErrorStrategy) {
201
        this.indexErrorStrategy = indexErrorStrategy;
202
    }
203
}

Mutations

37

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

40

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

50

1.1
Location : checkApplicability
Killed by : none
removed call to com/jsql/model/injection/strategy/StrategyError::logChecking → NO_COVERAGE

58

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

60

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

66

1.1
Location : lambda$checkApplicability$0
Killed by : none
replaced return value with null for com/jsql/model/injection/strategy/StrategyError::lambda$checkApplicability$0 → NO_COVERAGE

73

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

74

1.1
Location : checkApplicability
Killed by : none
removed call to com/jsql/model/injection/strategy/StrategyError::allow → NO_COVERAGE

76

1.1
Location : checkApplicability
Killed by : none
removed call to com/jsql/model/injection/strategy/StrategyError::unallow → NO_COVERAGE

78

1.1
Location : checkApplicability
Killed by : none
Changed increment from 1 to -1 → NO_COVERAGE

92

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

96

1.1
Location : isApplicable
Killed by : none
replaced boolean return with true for com/jsql/model/injection/strategy/StrategyError::isApplicable → NO_COVERAGE

2.2
Location : isApplicable
Killed by : none
replaced boolean return with false for com/jsql/model/injection/strategy/StrategyError::isApplicable → NO_COVERAGE

104

1.1
Location : getPerformance
Killed by : none
replaced return value with null for com/jsql/model/injection/strategy/StrategyError::getPerformance → NO_COVERAGE

111

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

112

1.1
Location : getCapacity
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : getCapacity
Killed by : none
negated conditional → NO_COVERAGE

123

1.1
Location : lambda$getCapacity$1
Killed by : none
replaced return value with null for com/jsql/model/injection/strategy/StrategyError::lambda$getCapacity$1 → NO_COVERAGE

125

1.1
Location : lambda$getCapacity$2
Killed by : none
replaced return value with null for com/jsql/model/injection/strategy/StrategyError::lambda$getCapacity$2 → NO_COVERAGE

128

1.1
Location : getCapacity
Killed by : none
replaced int return with 0 for com/jsql/model/injection/strategy/StrategyError::getCapacity → NO_COVERAGE

133

1.1
Location : allow
Killed by : none
removed call to com/jsql/model/InjectionModel::appendAnalysisReport → NO_COVERAGE

154

1.1
Location : allow
Killed by : none
removed call to com/jsql/model/InjectionModel::sendToViews → NO_COVERAGE

159

1.1
Location : unallow
Killed by : none
removed call to com/jsql/model/InjectionModel::sendToViews → NO_COVERAGE

164

1.1
Location : inject
Killed by : none
replaced return value with "" for com/jsql/model/injection/strategy/StrategyError::inject → NO_COVERAGE

172

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

2.2
Location : activateWhenApplicable
Killed by : none
negated conditional → NO_COVERAGE

176

1.1
Location : lambda$activateWhenApplicable$3
Killed by : none
replaced return value with null for com/jsql/model/injection/strategy/StrategyError::lambda$activateWhenApplicable$3 → NO_COVERAGE

179

1.1
Location : lambda$activateWhenApplicable$4
Killed by : none
replaced return value with null for com/jsql/model/injection/strategy/StrategyError::lambda$activateWhenApplicable$4 → NO_COVERAGE

181

1.1
Location : activateWhenApplicable
Killed by : none
removed call to com/jsql/model/injection/strategy/MediatorStrategy::setStrategy → NO_COVERAGE

182

1.1
Location : activateWhenApplicable
Killed by : none
removed call to com/jsql/model/InjectionModel::sendToViews → NO_COVERAGE

188

1.1
Location : getPerformanceLength
Killed by : none
replaced return value with "" for com/jsql/model/injection/strategy/StrategyError::getPerformanceLength → NO_COVERAGE

193

1.1
Location : getName
Killed by : none
replaced return value with "" for com/jsql/model/injection/strategy/StrategyError::getName → NO_COVERAGE

197

1.1
Location : getIndexErrorStrategy
Killed by : none
replaced Integer return value with 0 for com/jsql/model/injection/strategy/StrategyError::getIndexErrorStrategy → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.22.1