1 | package com.jsql.model.accessible; | |
2 | ||
3 | import com.jsql.model.InjectionModel; | |
4 | import com.jsql.model.bean.database.AbstractElementDatabase; | |
5 | import com.jsql.model.exception.InjectionFailureException; | |
6 | import com.jsql.model.exception.StoppedByUserSlidingException; | |
7 | import com.jsql.model.suspendable.SuspendableGetRows; | |
8 | import com.jsql.util.LogLevelUtil; | |
9 | import org.apache.commons.lang3.StringUtils; | |
10 | import org.apache.logging.log4j.LogManager; | |
11 | import org.apache.logging.log4j.Logger; | |
12 | ||
13 | import java.util.concurrent.Callable; | |
14 | ||
15 | /** | |
16 | * Thread unit to read source of a file by SQL injection. | |
17 | * User can interrupt the process and get a partial result of the file content. | |
18 | */ | |
19 | public class CallableFile implements Callable<CallableFile> { | |
20 | | |
21 | /** | |
22 | * Log4j logger sent to view. | |
23 | */ | |
24 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
25 | | |
26 | /** | |
27 | * Path to the file to read. | |
28 | */ | |
29 | private final String pathFile; | |
30 | ||
31 | /** | |
32 | * Source of file. | |
33 | */ | |
34 | private String sourceFile = StringUtils.EMPTY; | |
35 | | |
36 | /** | |
37 | * Suspendable task that reads lines of the file by injection. | |
38 | */ | |
39 | private final SuspendableGetRows suspendableReadFile; | |
40 | ||
41 | private final InjectionModel injectionModel; | |
42 | | |
43 | /** | |
44 | * Create Callable to read a file. | |
45 | * @param pathFile | |
46 | */ | |
47 | public CallableFile(String pathFile, InjectionModel injectionModel) { | |
48 | | |
49 | this.pathFile = pathFile; | |
50 | this.injectionModel= injectionModel; | |
51 | this.suspendableReadFile = new SuspendableGetRows(injectionModel); | |
52 | } | |
53 | | |
54 | /** | |
55 | * Read a file on the server using SQL injection. | |
56 | * Get partial result if user interrupts the process. | |
57 | */ | |
58 | @Override | |
59 | public CallableFile call() throws Exception { | |
60 | | |
61 | var sourcePage = new String[]{ StringUtils.EMPTY }; | |
62 | ||
63 | String resultToParse = StringUtils.EMPTY; | |
64 | try { | |
65 | resultToParse = this.suspendableReadFile.run( | |
66 | this.injectionModel.getMediatorVendor().getVendor().instance().sqlFileRead(this.pathFile), | |
67 | sourcePage, | |
68 | false, | |
69 | 1, | |
70 | AbstractElementDatabase.MOCK, | |
71 | "file" | |
72 | ); | |
73 | } catch (InjectionFailureException e) { | |
74 | // Usually thrown if File does not exist | |
75 | LOGGER.log(LogLevelUtil.IGNORE, e); | |
76 | } catch (StoppedByUserSlidingException e) { | |
77 | | |
78 | // Get partial source | |
79 |
1
1. call : negated conditional → NO_COVERAGE |
if (StringUtils.isNotEmpty(e.getSlidingWindowAllRows())) { |
80 | resultToParse = e.getSlidingWindowAllRows(); | |
81 |
1
1. call : negated conditional → NO_COVERAGE |
} else if (StringUtils.isNotEmpty(e.getSlidingWindowCurrentRows())) { |
82 | resultToParse = e.getSlidingWindowCurrentRows(); | |
83 | } | |
84 | | |
85 | LOGGER.log(LogLevelUtil.IGNORE, e); | |
86 | } | |
87 | | |
88 | this.sourceFile = resultToParse; | |
89 | | |
90 |
1
1. call : replaced return value with null for com/jsql/model/accessible/CallableFile::call → NO_COVERAGE |
return this; |
91 | } | |
92 | | |
93 | | |
94 | // Getters | |
95 | | |
96 | public String getPathFile() { | |
97 |
1
1. getPathFile : replaced return value with "" for com/jsql/model/accessible/CallableFile::getPathFile → NO_COVERAGE |
return this.pathFile; |
98 | } | |
99 | ||
100 | public String getSourceFile() { | |
101 |
1
1. getSourceFile : replaced return value with "" for com/jsql/model/accessible/CallableFile::getSourceFile → NO_COVERAGE |
return this.sourceFile; |
102 | } | |
103 | ||
104 | public SuspendableGetRows getSuspendableReadFile() { | |
105 |
1
1. getSuspendableReadFile : replaced return value with null for com/jsql/model/accessible/CallableFile::getSuspendableReadFile → NO_COVERAGE |
return this.suspendableReadFile; |
106 | } | |
107 | } | |
Mutations | ||
79 |
1.1 |
|
81 |
1.1 |
|
90 |
1.1 |
|
97 |
1.1 |
|
101 |
1.1 |
|
105 |
1.1 |