Skip to content

Commit eec34d5

Browse files
committed
Add integration tests for query filters
1 parent 06e27d3 commit eec34d5

File tree

5 files changed

+163
-2
lines changed

5 files changed

+163
-2
lines changed

.github/workflows/expected-queries-runs.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
name: Expected queries runs
2-
env:
3-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42

53
on:
64
push:

.github/workflows/query-filters.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Query filters tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- releases/v1
8+
- releases/v2
9+
pull_request:
10+
types:
11+
- opened
12+
- synchronize
13+
- reopened
14+
- ready_for_review
15+
workflow_dispatch: {}
16+
17+
jobs:
18+
expected-queries:
19+
timeout-minutes: 45
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Check out repository
23+
uses: actions/checkout@v3
24+
- name: Prepare test
25+
id: prepare-test
26+
uses: ./.github/prepare-test
27+
with:
28+
version: latest
29+
30+
# Test 1
31+
- uses: ./../action/init
32+
with:
33+
languages: javascript
34+
config-file: ./.github/codeql/codeql-config-query-filters1.yml
35+
tools: ${{ steps.prepare-test.outputs.tools-url }}
36+
db-location: ${{ runner.temp }}/test1
37+
- uses: ./../action/analyze
38+
with:
39+
output: ${{ runner.temp }}/results
40+
upload-database: false
41+
upload: false
42+
env:
43+
TEST_MODE: true
44+
- name: Check Sarif
45+
uses: ./../action/.github/check-sarif
46+
with:
47+
sarif-file: ${{ runner.temp }}/results/javascript.sarif
48+
queries-run: js/zipslip
49+
queries-not-run: js/path-injection
50+
- name: Cleanup after test
51+
run: rm -rf "$RUNNER_TEMP/results"
52+
53+
# Test 2
54+
- uses: ./../action/init
55+
with:
56+
languages: javascript
57+
config-file: ./.github/codeql/codeql-config-query-filters2.yml
58+
tools: ${{ steps.prepare-test.outputs.tools-url }}
59+
db-location: ${{ runner.temp }}/test2
60+
- uses: ./../action/analyze
61+
with:
62+
output: ${{ runner.temp }}/results
63+
upload-database: false
64+
upload: false
65+
env:
66+
TEST_MODE: true
67+
- name: Check Sarif
68+
uses: ./../action/.github/check-sarif
69+
with:
70+
sarif-file: ${{ runner.temp }}/results/javascript.sarif
71+
queries-run: js/zipslip,javascript/example/empty-or-one-block
72+
queries-not-run: js/path-injection
73+
- name: Cleanup after test
74+
run: rm -rf "$RUNNER_TEMP/results"
75+
76+
# Test 3
77+
- uses: ./../action/init
78+
with:
79+
languages: javascript
80+
config-file: ./.github/codeql/codeql-config-query-filters3.yml
81+
tools: ${{ steps.prepare-test.outputs.tools-url }}
82+
db-location: ${{ runner.temp }}/test3
83+
- uses: ./../action/analyze
84+
with:
85+
output: ${{ runner.temp }}/results
86+
upload-database: false
87+
upload: false
88+
env:
89+
TEST_MODE: true
90+
- name: Check Sarif
91+
uses: ./../action/.github/check-sarif
92+
with:
93+
sarif-file: ${{ runner.temp }}/results/javascript.sarif
94+
queries-run: js/zipslip,javascript/example/empty-or-one-block,inrepo-javascript-querypack/show-ifs
95+
queries-not-run: js/path-injection,complex-python-querypack/show-ifs,complex-python-querypack/foo/bar/show-ifs
96+
- name: Cleanup after test
97+
run: rm -rf "$RUNNER_TEMP/results"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: "CodeQL config 1"
2+
3+
query-filters:
4+
# This should run js/path-injection and js/zipslip
5+
- include:
6+
tags contain: external/cwe/cwe-022
7+
8+
# Removes out js/path-injection
9+
- exclude:
10+
id: js/path-injection
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: "CodeQL config 2"
2+
3+
disable-default-queries: true
4+
5+
packs:
6+
javascript:
7+
- codeql/javascript-queries
8+
- dsp-testing/[email protected]
9+
10+
query-filters:
11+
# This should run js/path-injection and js/zipslip
12+
- include:
13+
tags contain: external/cwe/cwe-022
14+
15+
# Removes out js/path-injection
16+
- exclude:
17+
id: js/path-injection
18+
19+
# Query from extra pack
20+
- include:
21+
id: javascript/example/empty-or-one-block
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: "CodeQL config 3"
2+
3+
disable-default-queries: true
4+
5+
queries:
6+
# Local query
7+
- name: Run an extra local query
8+
uses: ./codeql-qlpacks/javascript-qlpack/show_ifs.ql
9+
10+
# These queries are ignored
11+
- name: Ignored queries
12+
uses: ./codeql-qlpacks/complex-python-qlpack/rootAndBar.qls
13+
14+
15+
packs:
16+
javascript:
17+
- codeql/javascript-queries
18+
- dsp-testing/[email protected]
19+
20+
query-filters:
21+
# This should run js/path-injection and js/zipslip
22+
- include:
23+
tags contain: external/cwe/cwe-022
24+
25+
# Removes out js/path-injection
26+
- exclude:
27+
id: js/path-injection
28+
29+
# Query from extra pack
30+
- include:
31+
id: javascript/example/empty-or-one-block
32+
33+
# Local query
34+
- include:
35+
id: inrepo-javascript-querypack/show-ifs

0 commit comments

Comments
 (0)