Skip to content

Commit e8a667f

Browse files
author
Alvaro Muñoz
committed
Add new tests
1 parent 4fc9e3f commit e8a667f

File tree

6 files changed

+178
-0
lines changed

6 files changed

+178
-0
lines changed

ql/test/query-tests/Security/CWE-094/.github/actions/action5/action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ outputs:
99
result:
1010
description: "result"
1111
value: ${{ steps.step.outputs.result }}
12+
result2:
13+
description: "result"
14+
value: ${{ steps.step2.outputs.result2 }}
1215
runs:
1316
using: 'composite'
1417
steps:
@@ -20,6 +23,11 @@ runs:
2023
FOO: ${{ inputs.taint }}
2124
shell: bash
2225
run: echo "result=$(echo $FOO)" >> $GITHUB_OUTPUT
26+
- id: step2
27+
env:
28+
FOO2: ${{ github.event.pull_request.body }}
29+
shell: bash
30+
run: echo "result2=$(echo $FOO2)" >> $GITHUB_OUTPUT
2331
- name: Sink
2432
id: sink
2533
shell: bash
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Clone repository
2+
description: Clone repository
3+
inputs:
4+
title:
5+
description: Title
6+
required: true
7+
forked-pr:
8+
description: Whether the event is operating from a forked PR
9+
required: true
10+
fetch-depth:
11+
description: Fetch depth for actions/checkout
12+
default: "1"
13+
outputs:
14+
result:
15+
description: "result"
16+
value: ${{ steps.out.outputs.replaced }}
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- shell: bash
22+
run: echo "${{ inputs.title }}"
23+
- uses: frabert/[email protected]
24+
id: out
25+
with:
26+
pattern: "\""
27+
string: ${{ inputs.title }}
28+
replace-with: 'foo'
29+
flags: g
30+
- id: out2
31+
env:
32+
FOO: ${{ inputs.title }}
33+
shell: bash
34+
run: echo "result=$(echo $FOO)" >> $GITHUB_OUTPUT
35+
- name: Clone branch
36+
if: "!fromJSON(inputs.forked-pr)"
37+
uses: actions/checkout@v3
38+
with:
39+
fetch-depth: ${{ inputs.fetch-depth }}
40+
- name: Clone forked PR
41+
if: fromJSON(inputs.forked-pr)
42+
uses: actions/checkout@v3
43+
with:
44+
ref: refs/pull/${{ github.event.number }}/merge
45+
fetch-depth: ${{ inputs.fetch-depth }}
46+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: changelog
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
taint:
7+
description: taint
8+
type: string
9+
required: true
10+
default: ""
11+
12+
jobs:
13+
changelog:
14+
runs-on: ubuntu-latest
15+
env:
16+
file: CHANGELOG.md
17+
steps:
18+
- uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 0
21+
- name: Check ${{ env.file }}
22+
run: |
23+
if [[ $(git diff --name-only origin/master HEAD -- ${{ env.file }} | grep '^${{ env.file }}$' -c) -eq 0 ]]; then
24+
echo "Expected '${{ env.file }}' to be modified"
25+
exit 1
26+
fi
27+
update:
28+
runs-on: ubuntu-latest
29+
needs: changelog
30+
continue-on-error: true
31+
env:
32+
file: CHANGELOG.md
33+
next_version: next
34+
link: '[#${{ github.event.number }}](https://github.com/fabricjs/fabric.js/pull/${{ github.event.number }})'
35+
steps:
36+
- run: echo "${{ inputs.taint }}"
37+
- uses: actions/checkout@v3
38+
with:
39+
ref: ${{ github.event.pull_request.head.ref }}
40+
- name: Update ${{ env.file }} from PR title
41+
id: update
42+
uses: actions/github-script@v6
43+
env:
44+
log: '- ${{ github.event.pull_request.title }} ${{ env.link }}\n'
45+
prev_log: '- ${{ github.event.changes.title.from }} ${{ env.link }}\n'
46+
with:
47+
result-encoding: string
48+
script: |
49+
const fs = require('fs');
50+
const file = './${{ env.file }}';
51+
let content = fs.readFileSync(file).toString();
52+
const title = '[${{ env.next_version }}]';
53+
const log = '${{ env.log }}';
54+
let exists = ${{ needs.changelog.result == 'success' }};
55+
56+
if (!content.includes(title)) {
57+
const insertAt = content.indexOf('\n') + 1;
58+
content =
59+
content.slice(0, insertAt) +
60+
`\n## ${title}\n\n\n` +
61+
content.slice(insertAt);
62+
}
63+
64+
const insertAt = content.indexOf('\n', content.indexOf(title) + title.length + 1) + 1;
65+
if (exists && ${{ github.event.action == 'edited' }}) {
66+
const prevLog = '${{ env.prev_log }}';
67+
const index = content.indexOf(prevLog, insertAt);
68+
if (index > -1) {
69+
content = content.slice(0, index) + content.slice(index + prevLog.length);
70+
exists = false;
71+
}
72+
}
73+
74+
if (!exists) {
75+
content = content.slice(0, insertAt) + log + content.slice(insertAt);
76+
fs.writeFileSync(file, content);
77+
return true;
78+
}
79+
80+
return false;
81+
- name: Setup node
82+
if: fromJson(steps.update.outputs.result)
83+
uses: actions/setup-node@v3
84+
with:
85+
node-version: 18.x
86+
- name: Commit & Push
87+
if: fromJson(steps.update.outputs.result)
88+
run: |
89+
npm ci
90+
npx prettier --write ${{ env.file }}
91+
git config user.name github-actions[bot]
92+
git config user.email github-actions[bot]@users.noreply.github.com
93+
git add ${{ env.file }}
94+
git commit -m "update ${{ env.file }}"
95+
git push

ql/test/query-tests/Security/CWE-094/.github/workflows/composite-action-caller-3.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ jobs:
1111
with:
1212
taint: ${{ github.event.comment.body }}
1313
- run: echo "${{ steps.foo.outputs.result }}"
14+
- run: echo "${{ steps.foo.outputs.result2 }}"
1415

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
name: Issue Workflow
3+
on:
4+
pull_request_target:
5+
jobs:
6+
test:
7+
name: Test
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Clone branch
11+
id: clone
12+
uses: TestOrg/TestRepo/.github/actions/clone-repo@main
13+
with:
14+
title: ${{ github.event.pull_request.title }}
15+
forked-pr: true
16+
fetch-depth: 2
17+
- run: echo "${{ steps.clone.outputs.result }}"
18+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Caller
2+
3+
on:
4+
pull_request_target:
5+
6+
jobs:
7+
test:
8+
uses: TestOrg/TestRepo/.github/workflows/reusable-workflow.yml@main
9+
with:
10+
taint: ${{ github.event.pull_request.title }}

0 commit comments

Comments
 (0)