Skip to content

Commit 83af84a

Browse files
authored
Merge pull request diffblue#515 from diffblue/jd/feature/AEPD_unit_tests
[SEC-553] AEPD unit tests
2 parents 83b1948 + 88ba519 commit 83af84a

25 files changed

+463
-27
lines changed

driver/mkbench.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,17 @@ def collect_java_binaries(cmdline):
157157
method_data = ep_data["method"]
158158

159159
# We don't add the descriptor here as it's not recognized (and makes folder names too long).
160-
fully_qualified_method = ep_data["className"] + "." + method_data["name"]
160+
friendly_method_name = ep_data["className"] + "." + method_data["name"]
161+
raw_method_name = ep_data["className"] + "." + method_data["signature"]
161162

162163
# Try to make sure the folder name isn't invalid.
163-
folder_name = fully_qualified_method.replace(os.path.sep, '.')
164+
folder_name = friendly_method_name.replace(os.path.sep, '.')
164165
output_folder = os.path.join(cmdline.results_dir, folder_name)
165166

166167
# If our folder exists then just add (#number) to it and try creation again.
167168
incrementor = 1
168169
while os.path.exists(output_folder):
169-
folder_name = fully_qualified_method.replace(os.path.sep, '.') + " (" + str(incrementor) + ")"
170+
folder_name = friendly_method_name.replace(os.path.sep, '.') + " (" + str(incrementor) + ")"
170171
output_folder = os.path.join(cmdline.results_dir, folder_name)
171172
incrementor += 1
172173

@@ -180,7 +181,7 @@ def collect_java_binaries(cmdline):
180181
# The file should not exist yet. Here we only record the prefered/desired location
181182
# of the file on disk. Analyser will create it, if it does not exist (in the first run)
182183
"gbf": os.path.join(generated_temp_folder, "input_program.gbf"),
183-
"entry-point": fully_qualified_method
184+
"entry-point": raw_method_name
184185
}
185186

186187
program_file = os.path.join(output_folder, "program.json")
@@ -191,11 +192,11 @@ def collect_java_binaries(cmdline):
191192

192193
# Update our copied commandline with accurate / new values.
193194
copied_command_line.update({
194-
"name": "[" + cmdline.name + "] " + fully_qualified_method,
195+
"name": "[" + cmdline.name + "] " + friendly_method_name,
195196
"output-dir": output_folder,
196197
"results-dir": output_folder,
197198
"temp-dir": generated_temp_folder,
198-
"entry-point": fully_qualified_method
199+
"entry-point": raw_method_name
199200
})
200201

201202
# Save the commandline file.

driver/run.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,19 @@ def prepare_scan(cmdline):
212212
configuration = json.load(config_file)
213213
file_name = os.path.basename(config_file.name)
214214

215-
if not configuration["detectedEntryPointsPath"]:
215+
if not configuration.get("detectedEntryPointsPath", None):
216216
configuration["detectedEntryPointsPath"] = \
217217
os.path.join(cmdline.common_dir, "detected_entry_points.json")
218218

219-
if not configuration["diConfigurationPath"]:
219+
if not configuration.get("diConfigurationPath", None):
220220
configuration["diConfigurationPath"] = \
221221
os.path.join(cmdline.common_dir, "di_configuration.json")
222222

223-
if not configuration["collectedClassesPath"]:
223+
if not configuration.get("collectedClassesPath", None):
224224
configuration["collectedClassesPath"] = \
225225
os.path.join(cmdline.common_dir, "collected_classes.json")
226226

227-
if not configuration["collectedClassesInfoPath"]:
227+
if not configuration.get("collectedClassesInfoPath", None):
228228
configuration["collectedClassesInfoPath"] = \
229229
os.path.join(cmdline.common_dir, "collected_classes_info.json")
230230

regression/end_to_end/driver.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __exit__(self, exc_type, exc_value, traceback):
7272
print("Failure may relate to command: ", self.cmdline, file=sys.stderr)
7373

7474

75-
def quote_pathnames_in_command_line(cmdline):
75+
def pretty_print_commandline(cmdline):
7676
assert isinstance(cmdline, list) and len(cmdline) > 0
7777
result = cmdline[:1]
7878
for idx in range(1, len(cmdline)):
@@ -81,7 +81,26 @@ def quote_pathnames_in_command_line(cmdline):
8181
result.append("'" + cmdline[idx] + "'")
8282
else:
8383
result.append(cmdline[idx])
84-
return result
84+
85+
return " ".join(result)
86+
87+
88+
def run_security_driver_script(
89+
extra_commandline):
90+
91+
file_path = os.path.dirname(os.path.realpath(__file__))
92+
pipeline_driver_path = \
93+
os.path.realpath(os.path.join(file_path, "..", "..", "driver", "run.py"))
94+
95+
cmdline = ["python3", pipeline_driver_path]
96+
cmdline.extend(extra_commandline)
97+
98+
executable_runner = ExecutableRunner(cmdline)
99+
(stdout, stderr, ret) = executable_runner.run()
100+
if ret != 0:
101+
raise Exception(
102+
"Failed running \"%s\":\nstdout:\n\n%s\nstderr\n\n%s" % \
103+
(pretty_print_commandline(cmdline), stdout, stderr))
85104

86105

87106
def run_security_analyser_pipeline(
@@ -95,12 +114,9 @@ def run_security_analyser_pipeline(
95114
if extra_args is None:
96115
extra_args = []
97116

98-
regression_tests_path = os.getcwd()
99117
analyzer_home = utils.get_security_analyzer_home()
100118
if analyzer_home is None:
101119
raise Exception("Set SECURITY_SCANNER_HOME to a path containing the 'security-analyzer' binary")
102-
pipeline_driver_path = \
103-
os.path.realpath(os.path.join(regression_tests_path, "..", "driver", "run.py"))
104120
absolute_binary_path = \
105121
os.path.join(base_path, relative_binary_path)
106122
absolute_rules_path = \
@@ -113,8 +129,7 @@ def run_security_analyser_pipeline(
113129
common_dir = os.path.join(os.environ["SECURITY_ANALYSER_END_TO_END_TESTS_KEEP_RESULTS"], "TEMP") \
114130
if "SECURITY_ANALYSER_END_TO_END_TESTS_KEEP_RESULTS" in os.environ else tempfile.mkdtemp()
115131

116-
cmdline = ["python3", pipeline_driver_path,
117-
"-C", absolute_rules_path,
132+
cmdline = ["-C", absolute_rules_path,
118133
"-I", absolute_binary_path,
119134
"-R", results_dir,
120135
"-T", temporary_dir,
@@ -132,19 +147,12 @@ def run_security_analyser_pipeline(
132147
# optimisation matches:
133148
cmdline.append("--verify-csvsa-sparse-domains")
134149

135-
pretty_cmdline = " ".join(quote_pathnames_in_command_line(cmdline))
136-
137150
with utils.working_dir(analyzer_home), \
138151
utils.temp_dir_deleter(results_dir), \
139152
utils.temp_dir_deleter(temporary_dir), \
140153
utils.temp_dir_deleter(common_dir):
141154

142-
executable_runner = ExecutableRunner(cmdline)
143-
(stdout, stderr, ret) = executable_runner.run()
144-
if ret != 0:
145-
raise Exception(
146-
"Failed running \"%s\":\nstdout:\n\n%s\nstderr\n\n%s" % \
147-
(pretty_cmdline, stdout, stderr))
155+
run_security_driver_script(cmdline)
148156

149157
trace_list = \
150158
os.path.join(
@@ -163,6 +171,7 @@ def run_security_analyser_pipeline(
163171
trace_json = json.load(trace_file)
164172
inline_traces.append(trace_json)
165173

174+
pretty_cmdline = pretty_print_commandline(cmdline)
166175
if "SECURITY_ANALYSER_END_TO_END_TESTS_KEEP_RESULTS" in os.environ:
167176
print("Test \"%s\" kept results (%s) and temporary directory (%s)" %
168177
(pretty_cmdline, results_dir, temporary_dir))
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"collectedClassesInfoPath": "",
3+
"collectedClassesPath": "",
4+
"detectedEntryPointsPath": "",
5+
"patternGroup": [
6+
{
7+
"id": "General",
8+
"patterns": [
9+
{
10+
"classPattern": {
11+
"annotations": [
12+
"test.something.whatever.Annotation"
13+
]
14+
}
15+
}
16+
]
17+
}
18+
]
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"collectedClassesInfoPath": "",
3+
"collectedClassesPath": "",
4+
"detectedEntryPointsPath": "",
5+
"patternGroup": [
6+
{
7+
"id": "General",
8+
"patterns": [
9+
{
10+
"classPattern": {
11+
"annotations": [
12+
"test.something.whatever.Annotation"
13+
]
14+
},
15+
"methodPattern": {
16+
"annotations": [
17+
"test.something.whatever.Annotation"
18+
]
19+
}
20+
}
21+
]
22+
}
23+
]
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"collectedClassesInfoPath": "",
3+
"collectedClassesPath": "",
4+
"detectedEntryPointsPath": "",
5+
"patternGroup": [
6+
{
7+
"id": "General",
8+
"patterns": [
9+
{
10+
"classPattern": {
11+
"extends": [
12+
"test.something.whatever.MoreClasses"
13+
]
14+
}
15+
}
16+
]
17+
}
18+
]
19+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"collectedClassesInfoPath": "",
3+
"collectedClassesPath": "",
4+
"detectedEntryPointsPath": "",
5+
"patternGroup": [
6+
{
7+
"id": "General",
8+
"patterns": [
9+
{
10+
"classPattern": {
11+
"annotations": [
12+
"test.something.whatever.Annotation"
13+
],
14+
"extends": [
15+
"test.something.whatever.MoreClasses"
16+
],
17+
"implements": [
18+
"test.something.whatever.Interface"
19+
]
20+
}
21+
}
22+
]
23+
}
24+
]
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"collectedClassesInfoPath": "",
3+
"collectedClassesPath": "",
4+
"detectedEntryPointsPath": "",
5+
"patternGroup": [
6+
{
7+
"id": "General",
8+
"patterns": [
9+
{
10+
"classPattern": {
11+
"implements": [
12+
"test.something.whatever.Interface"
13+
]
14+
}
15+
}
16+
]
17+
}
18+
]
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"collectedClassesInfoPath": "",
3+
"collectedClassesPath": "",
4+
"detectedEntryPointsPath": "",
5+
"patternGroup": [
6+
{
7+
"id": "General",
8+
"patterns": [
9+
{
10+
"classPattern": {
11+
"annotations": [
12+
"test.something.whatever.Annotation"
13+
]
14+
}
15+
}
16+
]
17+
}
18+
]
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"collectedClassesInfoPath": "",
3+
"collectedClassesPath": "",
4+
"detectedEntryPointsPath": "",
5+
"patternGroup": [
6+
{
7+
"id": "General",
8+
"patterns": [
9+
{
10+
"methodPattern": {
11+
"annotations": [
12+
"test.something.whatever.Annotation"
13+
]
14+
}
15+
}
16+
]
17+
}
18+
]
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"collectedClassesInfoPath": "",
3+
"collectedClassesPath": "",
4+
"detectedEntryPointsPath": "",
5+
"patternGroup": [
6+
{
7+
"id": "General",
8+
"patterns": [
9+
{
10+
"methodPattern": {
11+
"arguments": [
12+
"java.lang.String"
13+
]
14+
}
15+
}
16+
]
17+
}
18+
]
19+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"collectedClassesInfoPath": "",
3+
"collectedClassesPath": "",
4+
"detectedEntryPointsPath": "",
5+
"patternGroup": [
6+
{
7+
"id": "General",
8+
"patterns": [
9+
{
10+
"methodPattern": {
11+
"names": [
12+
"Testing"
13+
],
14+
"annotations": [
15+
"test.something.whatever.Annotation"
16+
],
17+
"arguments": [
18+
"java.lang.String",
19+
"test.something.whatever.Interface"
20+
],
21+
"returns": [
22+
"test.something.whatever.Classes"
23+
]
24+
}
25+
}
26+
]
27+
}
28+
]
29+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"collectedClassesInfoPath": "",
3+
"collectedClassesPath": "",
4+
"detectedEntryPointsPath": "",
5+
"patternGroup": [
6+
{
7+
"id": "General",
8+
"patterns": [
9+
{
10+
"methodPattern": {
11+
"names": [
12+
"Fake"
13+
]
14+
}
15+
}
16+
]
17+
}
18+
]
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"collectedClassesInfoPath": "",
3+
"collectedClassesPath": "",
4+
"detectedEntryPointsPath": "",
5+
"patternGroup": [
6+
{
7+
"id": "General",
8+
"patterns": [
9+
{
10+
"methodPattern": {
11+
"returns": [
12+
"test.something.whatever.Classes"
13+
]
14+
}
15+
}
16+
]
17+
}
18+
]
19+
}

0 commit comments

Comments
 (0)