Skip to content

Commit 224d7a7

Browse files
authored
Merge pull request #7801 from github/henrymercer/js-atm-migrate-tests
JS: Migrate CodeQL tests for ML-powered queries
2 parents 3c9b332 + 2c17437 commit 224d7a7

File tree

131 files changed

+132932
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+132932
-2
lines changed

.gitattributes

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,9 @@
5050
*.pdb -text
5151

5252
java/ql/test/stubs/**/*.java linguist-generated=true
53-
java/ql/test/experimental/stubs/**/*.java linguist-generated=true
53+
java/ql/test/experimental/stubs/**/*.java linguist-generated=true
54+
55+
# Generated test files - these are synced from the standard JavaScript libraries using
56+
# `javascript/ql/experimental/adaptivethreatmodeling/test/update_endpoint_test_files.py`.
57+
javascript/ql/experimental/adaptivethreatmodeling/test/endpoint_large_scale/autogenerated/**/*.js linguist-generated=true -merge
58+
javascript/ql/experimental/adaptivethreatmodeling/test/endpoint_large_scale/autogenerated/**/*.ts linguist-generated=true -merge

.github/workflows/js-ml-tests.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: JS ML-powered queries tests
2+
3+
on:
4+
push:
5+
paths:
6+
- "javascript/ql/experimental/adaptivethreatmodeling/**"
7+
- .github/workflows/js-ml-tests.yml
8+
branches:
9+
- main
10+
- "rc/*"
11+
pull_request:
12+
paths:
13+
- "javascript/ql/experimental/adaptivethreatmodeling/**"
14+
- .github/workflows/js-ml-tests.yml
15+
16+
defaults:
17+
run:
18+
working-directory: javascript/ql/experimental/adaptivethreatmodeling
19+
20+
jobs:
21+
qlformat:
22+
name: Check QL formatting
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v2
26+
27+
- uses: ./.github/actions/fetch-codeql
28+
29+
- name: Check QL formatting
30+
run: |
31+
find . "(" -name "*.ql" -or -name "*.qll" ")" -print0 | \
32+
xargs -0 codeql query format --check-only
33+
34+
qlcompile:
35+
name: Check QL compilation
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v2
39+
40+
- uses: ./.github/actions/fetch-codeql
41+
42+
- name: Check QL compilation
43+
run: |
44+
codeql query compile \
45+
--check-only \
46+
--ram 5120 \
47+
--additional-packs "${{ github.workspace }}" \
48+
--threads=0 \
49+
-- \
50+
lib modelbuilding src
51+
52+
qltest:
53+
name: Run QL tests
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v2
57+
58+
- uses: ./.github/actions/fetch-codeql
59+
60+
- name: Run QL tests
61+
run: |
62+
codeql test run \
63+
--threads=0 \
64+
--ram 5120 \
65+
--additional-packs "${{ github.workspace }}" \
66+
-- \
67+
test

javascript/ql/experimental/adaptivethreatmodeling/modelbuilding/extraction/ExtractEndpointLabelEncoding.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* @name Endpoint types
33
* @description Maps endpoint type encodings to human-readable descriptions.
44
* @kind table
5+
* @id js/ml-powered/model-building/endpoint-type-encodings
56
*/
67

78
import experimental.adaptivethreatmodeling.EndpointTypes

javascript/ql/experimental/adaptivethreatmodeling/modelbuilding/qlpack.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: codeql/javascript-experimental-atm-model-building
2-
version: 0.0.0
32
extractor: javascript
43
library: false
54
groups:

javascript/ql/experimental/adaptivethreatmodeling/test/endpoint_large_scale/EndpointFeatures.expected

Lines changed: 16711 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* EndpointFeatures.ql
3+
*
4+
* This tests generic token-based featurization of all endpoint candidates for all of the security
5+
* queries we support. This is in comparison to the `ExtractEndpointData.qlref` test, which tests
6+
* just the endpoints we extract in the training data.
7+
*/
8+
9+
import javascript
10+
import experimental.adaptivethreatmodeling.NosqlInjectionATM as NosqlInjectionATM
11+
import experimental.adaptivethreatmodeling.SqlInjectionATM as SqlInjectionATM
12+
import experimental.adaptivethreatmodeling.TaintedPathATM as TaintedPathATM
13+
import experimental.adaptivethreatmodeling.XssATM as XssATM
14+
import experimental.adaptivethreatmodeling.EndpointFeatures as EndpointFeatures
15+
import experimental.adaptivethreatmodeling.StandardEndpointFilters as StandardEndpointFilters
16+
import extraction.NoFeaturizationRestrictionsConfig
17+
18+
query predicate tokenFeatures(DataFlow::Node endpoint, string featureName, string featureValue) {
19+
(
20+
not exists(NosqlInjectionATM::SinkEndpointFilter::getAReasonSinkExcluded(endpoint)) or
21+
not exists(SqlInjectionATM::SinkEndpointFilter::getAReasonSinkExcluded(endpoint)) or
22+
not exists(TaintedPathATM::SinkEndpointFilter::getAReasonSinkExcluded(endpoint)) or
23+
not exists(XssATM::SinkEndpointFilter::getAReasonSinkExcluded(endpoint)) or
24+
StandardEndpointFilters::isArgumentToModeledFunction(endpoint)
25+
) and
26+
EndpointFeatures::tokenFeatures(endpoint, featureName, featureValue)
27+
}
28+
29+
query predicate invalidTokenFeatures(
30+
DataFlow::Node endpoint, string featureName, string featureValue
31+
) {
32+
strictcount(string value | EndpointFeatures::tokenFeatures(endpoint, featureName, value)) > 1 and
33+
EndpointFeatures::tokenFeatures(endpoint, featureName, featureValue)
34+
}

javascript/ql/experimental/adaptivethreatmodeling/test/endpoint_large_scale/ExtractEndpointData.expected

Lines changed: 47858 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extraction/ExtractEndpointData.ql

0 commit comments

Comments
 (0)