StrategyInjectionError.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.model.bean.util.Interaction;
6
import com.jsql.model.bean.util.Request;
7
import com.jsql.model.injection.vendor.model.VendorYaml;
8
import com.jsql.model.injection.vendor.model.yaml.Method;
9
import com.jsql.model.suspendable.AbstractSuspendable;
10
import com.jsql.util.I18nUtil;
11
import com.jsql.util.LogLevelUtil;
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 StrategyInjectionError extends AbstractStrategy {
19
    
20
    /**
21
     * Log4j logger sent to view.
22
     */
23
    private static final Logger LOGGER = LogManager.getRootLogger();
24
    
25
    private String[] tabCapacityMethod;
26
    
27
    private int indexErrorStrategy = 0;
28
29
    public StrategyInjectionError(InjectionModel injectionModel) {
30
        super(injectionModel);
31
    }
32
33
    @Override
34
    public void checkApplicability() {
35
        
36
        // Reset applicability of new Vendor
37
        this.isApplicable = false;
38
        
39
        var strategyYaml = this.injectionModel.getMediatorVendor().getVendor().instance().getModelYaml().getStrategy();
40
41 1 1. checkApplicability : negated conditional → NO_COVERAGE
        if (this.injectionModel.getMediatorUtils().getPreferencesUtil().isStrategyErrorDisabled()) {
42
43
            LOGGER.log(LogLevelUtil.CONSOLE_INFORM, AbstractStrategy.FORMAT_SKIP_STRATEGY_DISABLED, getName());
44
            return;
45
46 1 1. checkApplicability : negated conditional → NO_COVERAGE
        } else if (strategyYaml.getError().getMethod().isEmpty()) {
47
48
            LOGGER.log(
49
                LogLevelUtil.CONSOLE_ERROR,
50
                AbstractStrategy.FORMAT_STRATEGY_NOT_IMPLEMENTED,
51
                getName(),
52
                this.injectionModel.getMediatorVendor().getVendor()
53
            );
54
            return;
55
        }
56
57
        LOGGER.log(
58
            LogLevelUtil.CONSOLE_DEFAULT,
59
            AbstractStrategy.FORMAT_CHECKING_STRATEGY,
60 1 1. lambda$checkApplicability$0 : replaced return value with null for com/jsql/model/injection/strategy/StrategyInjectionError::lambda$checkApplicability$0 → NO_COVERAGE
            () -> I18nUtil.valueByKey("LOG_CHECKING_STRATEGY"),
61
            this::getName
62
        );
63
        
64
        this.tabCapacityMethod = new String[strategyYaml.getError().getMethod().size()];
65
        var indexErrorMethod = 0;
66
        var errorCapacity = 0;
67
        
68
        for (Method errorMethod: strategyYaml.getError().getMethod()) {
69
            
70
            boolean methodIsApplicable = this.isApplicable(errorMethod);
71
            
72 1 1. checkApplicability : negated conditional → NO_COVERAGE
            if (methodIsApplicable) {
73
                
74
                Matcher regexSearch = this.getPerformance(errorMethod);
75
                
76 1 1. checkApplicability : negated conditional → NO_COVERAGE
                if (regexSearch.find()) {
77
                    errorCapacity = this.getCapacity(indexErrorMethod, errorCapacity, errorMethod, regexSearch);
78
                } else {
79
                    
80
                    LOGGER.log(
81
                        LogLevelUtil.CONSOLE_ERROR,
82
                        "{} {} but injectable size is incorrect",
83 1 1. lambda$checkApplicability$1 : replaced return value with null for com/jsql/model/injection/strategy/StrategyInjectionError::lambda$checkApplicability$1 → NO_COVERAGE
                        () -> I18nUtil.valueByKey("LOG_VULNERABLE"),
84
                        errorMethod::getName
85
                    );
86
                    
87
                    methodIsApplicable = false;
88
                }
89
            }
90
            
91 1 1. checkApplicability : negated conditional → NO_COVERAGE
            if (methodIsApplicable) {
92 1 1. checkApplicability : removed call to com/jsql/model/injection/strategy/StrategyInjectionError::allow → NO_COVERAGE
                this.allow(indexErrorMethod);
93
            } else {
94 1 1. checkApplicability : removed call to com/jsql/model/injection/strategy/StrategyInjectionError::unallow → NO_COVERAGE
                this.unallow(indexErrorMethod);
95
            }
96
            
97 1 1. checkApplicability : Changed increment from 1 to -1 → NO_COVERAGE
            indexErrorMethod++;
98
        }
99
    }
100
101
    private boolean isApplicable(Method errorMethod) {
102
        
103
        var methodIsApplicable = false;
104
105
        String performanceSourcePage = this.injectionModel.injectWithoutIndex(
106
            this.injectionModel.getMediatorVendor().getVendor().instance().sqlErrorIndice(errorMethod),
107
            "error#confirm"
108
        );
109
110
        var indexZeroToFind = "0";
111
        String regexIndexZero = String.format(VendorYaml.FORMAT_INDEX, indexZeroToFind);
112 1 1. isApplicable : negated conditional → NO_COVERAGE
        if (performanceSourcePage.matches("(?s).*"+ regexIndexZero +".*")) {
113
            methodIsApplicable = true;
114
            this.isApplicable = true;
115
        }
116
        
117 2 1. isApplicable : replaced boolean return with true for com/jsql/model/injection/strategy/StrategyInjectionError::isApplicable → NO_COVERAGE
2. isApplicable : replaced boolean return with false for com/jsql/model/injection/strategy/StrategyInjectionError::isApplicable → NO_COVERAGE
        return methodIsApplicable;
118
    }
119
120
    private Matcher getPerformance(Method errorMethod) {
121
        
122
        String performanceErrorSourcePage = this.injectionModel.injectWithoutIndex(
123
            this.injectionModel.getMediatorVendor().getVendor().instance().sqlErrorCalibrator(errorMethod),
124
            "error#size"
125
        );
126
        
127 1 1. getPerformance : replaced return value with null for com/jsql/model/injection/strategy/StrategyInjectionError::getPerformance → NO_COVERAGE
        return Pattern.compile("(?s)"+ DataAccess.LEAD +"(#+)").matcher(performanceErrorSourcePage);
128
    }
129
130
    private int getCapacity(int indexErrorMethod, int errorCapacityDefault, Method errorMethod, Matcher regexSearch) {
131
        
132
        int errorCapacityImproved = errorCapacityDefault;
133
        
134
        regexSearch.reset();
135
        
136 1 1. getCapacity : negated conditional → NO_COVERAGE
        while (regexSearch.find()) {
137
            
138 2 1. getCapacity : changed conditional boundary → NO_COVERAGE
2. getCapacity : negated conditional → NO_COVERAGE
            if (errorCapacityImproved < regexSearch.group(1).length()) {
139
                this.indexErrorStrategy = indexErrorMethod;
140
            }
141
            
142
            errorCapacityImproved = regexSearch.group(1).length();
143
            this.tabCapacityMethod[indexErrorMethod] = Integer.toString(errorCapacityImproved);
144
        }
145
        
146
        int logErrorCapacityImproved = errorCapacityImproved;
147
        LOGGER.log(
148
            LogLevelUtil.CONSOLE_SUCCESS,
149
            "{} [Error {}] using [{}] characters",
150 1 1. lambda$getCapacity$2 : replaced return value with null for com/jsql/model/injection/strategy/StrategyInjectionError::lambda$getCapacity$2 → NO_COVERAGE
            () -> I18nUtil.valueByKey("LOG_VULNERABLE"),
151
            errorMethod::getName,
152 1 1. lambda$getCapacity$3 : replaced return value with null for com/jsql/model/injection/strategy/StrategyInjectionError::lambda$getCapacity$3 → NO_COVERAGE
            () -> Integer.toString(logErrorCapacityImproved)
153
        );
154
        
155 1 1. getCapacity : replaced int return with 0 for com/jsql/model/injection/strategy/StrategyInjectionError::getCapacity → NO_COVERAGE
        return errorCapacityImproved;
156
    }
157
158
    @Override
159
    public void allow(int... indexError) {
160
161 1 1. allow : removed call to com/jsql/model/InjectionModel::appendAnalysisReport → NO_COVERAGE
        this.injectionModel.appendAnalysisReport(
162
            "<span style=color:rgb(0,0,255)>### Strategy: " + getName() + ":" + this.injectionModel.getMediatorVendor().getVendor().instance()
163
            .getModelYaml()
164
            .getStrategy()
165
            .getError()
166
            .getMethod()
167
            .get(indexError[0])
168
            .getName()
169
            + "</span>"+ this.injectionModel.getReportWithoutIndex(
170
                this.injectionModel.getMediatorVendor().getVendor().instance().sqlError("<span style=color:rgb(0,128,0)>&lt;query&gt;</span>", "0", indexError[0], true),
171
                "metadataInjectionProcess"
172
            )
173
        );
174 1 1. allow : removed call to com/jsql/model/injection/strategy/StrategyInjectionError::markVulnerability → NO_COVERAGE
        this.markVulnerability(Interaction.MARK_ERROR_VULNERABLE, indexError[0]);
175
    }
176
177
    @Override
178
    public void unallow(int... indexError) {
179 1 1. unallow : removed call to com/jsql/model/injection/strategy/StrategyInjectionError::markVulnerability → NO_COVERAGE
        this.markVulnerability(Interaction.MARK_ERROR_INVULNERABLE, indexError[0]);
180
    }
181
182
    @Override
183
    public String inject(String sqlQuery, String startPosition, AbstractSuspendable stoppable, String metadataInjectionProcess) {
184 1 1. inject : replaced return value with "" for com/jsql/model/injection/strategy/StrategyInjectionError::inject → NO_COVERAGE
        return this.injectionModel.injectWithoutIndex(
185
            this.injectionModel.getMediatorVendor().getVendor().instance().sqlError(sqlQuery, startPosition, this.indexErrorStrategy, false),
186
            metadataInjectionProcess
187
        );
188
    }
189
190
    @Override
191
    public void activateWhenApplicable() {
192 2 1. activateWhenApplicable : negated conditional → NO_COVERAGE
2. activateWhenApplicable : negated conditional → NO_COVERAGE
        if (this.injectionModel.getMediatorStrategy().getStrategy() == null && this.isApplicable()) {
193
194
            LOGGER.log(
195
                LogLevelUtil.CONSOLE_INFORM,
196
                "{} [{} {}]",
197 1 1. lambda$activateWhenApplicable$4 : replaced return value with null for com/jsql/model/injection/strategy/StrategyInjectionError::lambda$activateWhenApplicable$4 → NO_COVERAGE
                () -> I18nUtil.valueByKey("LOG_USING_STRATEGY"),
198
                this::getName,
199
                () -> this.injectionModel.getMediatorVendor().getVendor().instance()
200
                .getModelYaml()
201
                .getStrategy()
202
                .getError()
203
                .getMethod()
204 1 1. lambda$activateWhenApplicable$5 : replaced return value with null for com/jsql/model/injection/strategy/StrategyInjectionError::lambda$activateWhenApplicable$5 → NO_COVERAGE
                .get(this.indexErrorStrategy)
205
                .getName()
206
            );
207 1 1. activateWhenApplicable : removed call to com/jsql/model/injection/strategy/MediatorStrategy::setStrategy → NO_COVERAGE
            this.injectionModel.getMediatorStrategy().setStrategy(this.injectionModel.getMediatorStrategy().getError());
208
209
            var request = new Request();
210 1 1. activateWhenApplicable : removed call to com/jsql/model/bean/util/Request::setMessage → NO_COVERAGE
            request.setMessage(Interaction.MARK_ERROR_STRATEGY);
211 1 1. activateWhenApplicable : removed call to com/jsql/model/InjectionModel::sendToViews → NO_COVERAGE
            this.injectionModel.sendToViews(request);
212
        }
213
    }
214
    
215
    @Override
216
    public String getPerformanceLength() {
217 1 1. getPerformanceLength : replaced return value with "" for com/jsql/model/injection/strategy/StrategyInjectionError::getPerformanceLength → NO_COVERAGE
        return this.tabCapacityMethod[this.indexErrorStrategy];
218
    }
219
    
220
    @Override
221
    public String getName() {
222 1 1. getName : replaced return value with "" for com/jsql/model/injection/strategy/StrategyInjectionError::getName → NO_COVERAGE
        return "Error";
223
    }
224
    
225
    public Integer getIndexErrorStrategy() {
226 1 1. getIndexErrorStrategy : replaced Integer return value with 0 for com/jsql/model/injection/strategy/StrategyInjectionError::getIndexErrorStrategy → NO_COVERAGE
        return this.indexErrorStrategy;
227
    }
228
    
229
    public void setIndexErrorStrategy(int indexErrorStrategy) {
230
        this.indexErrorStrategy = indexErrorStrategy;
231
    }
232
}

Mutations

41

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

46

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

60

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

72

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

76

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

83

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

91

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

92

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

94

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

97

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

112

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

117

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

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

127

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

136

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

138

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

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

150

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

152

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

155

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

161

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

174

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

179

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

184

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

192

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

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

197

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

204

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

207

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

210

1.1
Location : activateWhenApplicable
Killed by : none
removed call to com/jsql/model/bean/util/Request::setMessage → NO_COVERAGE

211

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

217

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

222

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

226

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

Active mutators

Tests examined


Report generated by PIT 1.16.1