Skip to content

Commit 904a4bd

Browse files
committed
fix script updating endpoint_large_scale test data
1 parent b2856c1 commit 904a4bd

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# autogenerated folder
2+
3+
This folder contains test data for the ATM endpoint CodeQL tests that has been autogenerated from the standard JS CodeQL libraries.
4+
5+
It is helpful, but not required, to periodically update this test data to incorporate new test data introduced in the standard JS CodeQL libraries.
6+
7+
To update this test data, run `python /path/to/codeql-lib/ql/javascript/test/update_endpoint_test_files.py`.
8+
9+
For more information view the source code of [`update_endpoint_test_files.py`](../../update_endpoint_test_files.py).

javascript/ql/experimental/adaptivethreatmodeling/test/update_endpoint_test_files.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22

33
# This script updates the JavaScript test data used by the endpoint CodeQL tests.
44

5-
import glob
5+
import git
66
import logging
7-
import os
87
import shutil
8+
from pathlib import Path
9+
10+
# Get relevant paths
11+
script_path = Path(__file__).absolute()
12+
git_repo = git.Repo(__file__, search_parent_directories=True)
13+
git_root = Path(git_repo.git.rev_parse('--show-toplevel'))
14+
autogenerated_dest_path = script_path.parent.joinpath('endpoint_large_scale',
15+
'autogenerated')
916

1017
# File extensions that should be copied to the endpoint tests. This should include source code files
1118
# e.g. .js, but not the tests themselves e.g. .expected, .ql, .qlref, etc.
@@ -15,35 +22,31 @@
1522
# path of that test relative to a checkout of github/codeql.
1623
test_root_relative_paths = {
1724
'NosqlAndSqlInjection': 'javascript/ql/test/query-tests/Security/CWE-089',
18-
'TaintedPath': 'javascript/ql/test/query-tests/Security/CWE-022/TaintedPath',
25+
'TaintedPath':
26+
'javascript/ql/test/query-tests/Security/CWE-022/TaintedPath',
1927
'Xss': 'javascript/ql/test/query-tests/Security/CWE-079',
28+
'XssThroughDom': 'javascript/ql/test/query-tests/Security/CWE-116'
2029
}
21-
# The path of the endpoint tests, relative to a checkout of github/codeql
22-
test_path = 'javascript/ql/experimental/adaptivethreatmodeling/test/endpoint_large_scale'
2330

2431
logging.basicConfig(level=logging.INFO)
2532

26-
codeql_lib_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))))
27-
28-
autogenerated_dest_path = os.path.join(codeql_lib_path, test_path, 'autogenerated')
29-
if os.path.exists(autogenerated_dest_path):
33+
if autogenerated_dest_path.exists():
3034
logging.info(f'Deleting existing autogenerated test files...')
3135
shutil.rmtree(autogenerated_dest_path)
3236

3337
for key, rel_path in test_root_relative_paths.items():
34-
test_files_path = os.path.join(codeql_lib_path, rel_path)
38+
test_files_path = git_root.joinpath(rel_path)
3539
logging.info(f'Copying test files for {key}...')
36-
37-
for file in glob.glob(test_files_path + '/**', recursive=True):
38-
# Ignore .testproj directories
39-
if '.testproj' in file:
40+
counter = 0
41+
for file in Path(test_files_path).glob('**/*'):
42+
if file.is_dir() or '.test_proj' in str(file):
4043
continue
41-
42-
file_extension = os.path.splitext(file)[1]
43-
if file_extension in file_extensions_to_copy:
44-
dest_path = os.path.normpath(
45-
os.path.join(autogenerated_dest_path, key, os.path.relpath(file, test_files_path))
46-
)
44+
if file.suffix in file_extensions_to_copy:
45+
autogenerated_dest_path.joinpath(key, )
46+
dest_path = autogenerated_dest_path.joinpath(
47+
key, file.relative_to(test_files_path))
4748
logging.debug(f'Copying {file} to {dest_path}')
48-
os.makedirs(os.path.dirname(dest_path), exist_ok=True)
49+
dest_path.parent.mkdir(parents=True, exist_ok=True)
4950
shutil.copyfile(file, dest_path)
51+
counter += 1
52+
logging.info(f'copied {counter} files')

0 commit comments

Comments
 (0)