mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
58 lines
2.2 KiB
Python
Executable File
58 lines
2.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# This script updates the JavaScript test data used by the endpoint CodeQL tests.
|
|
|
|
import git
|
|
import logging
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
# Get relevant paths
|
|
script_path = Path(__file__).absolute()
|
|
git_repo = git.Repo(__file__, search_parent_directories=True)
|
|
git_root = Path(git_repo.git.rev_parse('--show-toplevel'))
|
|
autogenerated_dest_path = script_path.parent.joinpath('endpoint_large_scale',
|
|
'autogenerated')
|
|
|
|
# File extensions that should be copied to the endpoint tests. This should include source code files
|
|
# e.g. .js, but not the tests themselves e.g. .expected, .ql, .qlref, etc.
|
|
file_extensions_to_copy = ['.js', '.ts']
|
|
|
|
# Maps each security query to the test root path for that security query. Each test root path is the
|
|
# path of that test relative to a checkout of github/codeql.
|
|
test_root_relative_paths = {
|
|
'NosqlAndSqlInjection':
|
|
'javascript/ql/test/query-tests/Security/CWE-089',
|
|
'TaintedPath':
|
|
'javascript/ql/test/query-tests/Security/CWE-022/TaintedPath',
|
|
'Xss':
|
|
'javascript/ql/test/query-tests/Security/CWE-079',
|
|
'XssThroughDom':
|
|
'javascript/ql/test/query-tests/Security/CWE-116',
|
|
'ShellCommandInjectionFromEnvironment':
|
|
'javascript/ql/test/query-tests/Security/CWE-078',
|
|
}
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
if autogenerated_dest_path.exists():
|
|
logging.info(f'Deleting existing autogenerated test files...')
|
|
shutil.rmtree(autogenerated_dest_path)
|
|
|
|
for key, rel_path in test_root_relative_paths.items():
|
|
test_files_path = git_root.joinpath(rel_path)
|
|
logging.info(f'Copying test files for {key}...')
|
|
counter = 0
|
|
for file in Path(test_files_path).glob('**/*'):
|
|
if file.is_dir() or '.test_proj' in str(file):
|
|
continue
|
|
if file.suffix in file_extensions_to_copy:
|
|
autogenerated_dest_path.joinpath(key, )
|
|
dest_path = autogenerated_dest_path.joinpath(
|
|
key, file.relative_to(test_files_path))
|
|
logging.debug(f'Copying {file} to {dest_path}')
|
|
dest_path.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copyfile(file, dest_path)
|
|
counter += 1
|
|
logging.info(f'copied {counter} files')
|