Skip to content

Commit a72717b

Browse files
webapp: add ofg validity api (#2133)
* webapp: make get-all-tests faster Signed-off-by: David Korczynski <[email protected]> * add new validity ofg endpoint Signed-off-by: David Korczynski <[email protected]> * nit Signed-off-by: David Korczynski <[email protected]> * nit Signed-off-by: David Korczynski <[email protected]> * nit Signed-off-by: David Korczynski <[email protected]> * nit Signed-off-by: David Korczynski <[email protected]> * nit Signed-off-by: David Korczynski <[email protected]> * nit Signed-off-by: David Korczynski <[email protected]> * nit Signed-off-by: David Korczynski <[email protected]> --------- Signed-off-by: David Korczynski <[email protected]>
1 parent cf2252c commit a72717b

File tree

1 file changed

+57
-5
lines changed
  • tools/web-fuzzing-introspection/app/webapp

1 file changed

+57
-5
lines changed

tools/web-fuzzing-introspection/app/webapp/routes.py

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,11 @@ def harness_source_and_executable(args):
11741174
if project_name is None:
11751175
return {'result': 'error', 'msg': 'Please provide project name'}
11761176

1177+
return _get_harness_source_and_executable(project_name)
1178+
1179+
1180+
def _get_harness_source_and_executable(project_name):
1181+
"""Get the binary-to-source pairs of a project."""
11771182
target_project = get_project_with_name(project_name)
11781183
if target_project is None:
11791184
return {'result': 'error', 'msg': 'Project not in the database'}
@@ -1218,7 +1223,7 @@ def harness_source_and_executable(args):
12181223
harness_executable
12191224
})
12201225

1221-
# Ensure the files are present in the soruce code
1226+
# Ensure the files are present in the source code
12221227
with open(all_file_json, 'r') as f:
12231228
all_files_list = json.loads(f.read())
12241229

@@ -2404,9 +2409,44 @@ def should_ignore_testpath(test_path: str) -> bool:
24042409
return False
24052410

24062411

2412+
@api_blueprint.route('/api/ofg-validity-check')
2413+
def ofg_validity_check():
2414+
"""Returns OFG validity check for all projects."""
2415+
2416+
results = []
2417+
for project in data_storage.get_projects():
2418+
harness_mapping = _get_harness_source_and_executable(project.name)
2419+
2420+
mapping_success = True
2421+
pairs = harness_mapping.get('pairs', [])
2422+
for pair in pairs:
2423+
if not isinstance(pair, dict):
2424+
continue
2425+
if '/' in pair.get('executable', ''):
2426+
mapping_success = False
2427+
2428+
# Verify fuzz introspector context retrieval
2429+
fi_context_analysis = _get_fi_context_validity(project.name)
2430+
results.append({
2431+
'project': project.name,
2432+
'mapping_source': mapping_success,
2433+
'context_status': fi_context_analysis
2434+
})
2435+
return {'result': 'success', 'data': results}
2436+
2437+
2438+
def _get_fi_context_validity(project_name):
2439+
"""Get context validity for a project."""
2440+
xref_dict = get_cross_reference_dict_from_project(project_name)
2441+
total_ref_count = 0
2442+
for dst, ref_count in xref_dict.items():
2443+
total_ref_count += ref_count
2444+
return {'cross-reference-counts': total_ref_count}
2445+
2446+
24072447
def extract_project_tests(project_name,
24082448
refine: bool = True,
2409-
try_ignore_irrelevant=True) -> List[str]:
2449+
try_ignore_irrelevant=True) -> List[Optional[str]]:
24102450
"""Extracts the tests in terms of file paths of a given project"""
24112451
tests_file = os.path.join(
24122452
os.path.dirname(__file__),
@@ -2432,6 +2472,8 @@ def extract_project_tests(project_name,
24322472
target_project,
24332473
project_name)
24342474

2475+
if not isinstance(tests_file_list, list):
2476+
return []
24352477
return tests_file_list
24362478

24372479

@@ -2459,7 +2501,10 @@ def _light_project_tests(project_name, try_ignore_irrelevant=True):
24592501
return returner_list
24602502

24612503

2462-
def _ignore_irrelevant_tests(tests_file_list, project, project_name):
2504+
def _ignore_irrelevant_tests(tests_file_list,
2505+
project,
2506+
project_name,
2507+
enable_jvm=False):
24632508
"""Helper function to ignore irrelevant tests"""
24642509
repo_match = []
24652510

@@ -2470,7 +2515,9 @@ def _ignore_irrelevant_tests(tests_file_list, project, project_name):
24702515
# Extra filtering for Java project
24712516
# This is to filter irrelevant java test/example sources that does
24722517
# not call any public classes of the project
2473-
if project and project.language == 'java':
2518+
# We need to set enable_jvm here because takes a huge amount of
2519+
# processing time. Must exclude in most cases.
2520+
if project and project.language == 'java' and enable_jvm:
24742521
result_list = []
24752522

24762523
# Determine a list of relevant import statements
@@ -2488,7 +2535,7 @@ def _ignore_irrelevant_tests(tests_file_list, project, project_name):
24882535
project_name):
24892536
result_list.append(test_file)
24902537

2491-
return result_list
2538+
return
24922539

24932540
return repo_match
24942541

@@ -2570,6 +2617,11 @@ def project_tests(args):
25702617

25712618
light_tests = _light_project_tests(project)
25722619
test_file_list = extract_project_tests(project)
2620+
if light_tests is None:
2621+
light_tests = []
2622+
if test_file_list is None:
2623+
test_file_list = []
2624+
25732625
combined = list(set(test_file_list + light_tests))
25742626
if not combined:
25752627
return {

0 commit comments

Comments
 (0)