Skip to content

Commit fe3eaa8

Browse files
redsun82Copilot
andcommitted
Use inline expectations for Actions test
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent bdf8710 commit fe3eaa8

5 files changed

Lines changed: 41 additions & 4 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @kind test-postprocess
3+
*/
4+
5+
private import actions
6+
private import codeql.Locations
7+
private import codeql.files.FileSystem
8+
private import codeql.util.test.InlineExpectationsTest as T
9+
private import codeql.actions.test.internal.InlineExpectationsTestImpl
10+
import T::TestPostProcessing
11+
import T::TestPostProcessing::Make<Impl, Input>
12+
13+
private module Input implements T::TestPostProcessing::InputSig<Impl> {
14+
string getRelativeUrl(Location location) {
15+
exists(File f, int startline, int startcolumn, int endline, int endcolumn |
16+
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
17+
f = location.getFile()
18+
|
19+
result =
20+
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
21+
)
22+
}
23+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
private import codeql.Locations as L
2+
private import codeql.actions.ast.internal.Yaml
3+
private import codeql.util.test.InlineExpectationsTest
4+
5+
module Impl implements InlineExpectationsTestSig {
6+
class ExpectationComment extends YamlNode {
7+
ExpectationComment() { this.toString().matches("%$ %") }
8+
9+
string getContents() { result = "$ " + this.toString().regexpCapture(".*\\$ (.*)", 1) }
10+
}
11+
12+
class Location = L::Location;
13+
}

actions/ql/test/query-tests/Security/CWE-829-untrusted-owner/.github/workflows/unpinned_first_party.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ jobs:
66
steps:
77
# `actions` is distrusted via `!actions`, and this action is not immutable,
88
# so this unpinned tag is reported.
9-
- uses: actions/first-interaction@v1
9+
- uses: actions/first-interaction@v1 # $ Alert
1010
# `github` remains trusted, so this unpinned tag is not reported.
1111
- uses: github/issue-labeler@v3.0
1212
# Third-party owner is always reported.
13-
- uses: foo/bar@v1
13+
- uses: foo/bar@v1 # $ Alert
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
| .github/workflows/unpinned_first_party.yml:9:15:9:42 | actions/first-interaction@v1 | Unpinned 3rd party Action 'Unpinned first-party actions' step $@ uses 'actions/first-interaction' with ref 'v1', not a pinned commit hash | .github/workflows/unpinned_first_party.yml:9:9:11:6 | Uses Step | Uses Step |
2-
| .github/workflows/unpinned_first_party.yml:13:15:13:24 | foo/bar@v1 | Unpinned 3rd party Action 'Unpinned first-party actions' step $@ uses 'foo/bar' with ref 'v1', not a pinned commit hash | .github/workflows/unpinned_first_party.yml:13:9:13:25 | Uses Step | Uses Step |
2+
| .github/workflows/unpinned_first_party.yml:13:15:13:24 | foo/bar@v1 | Unpinned 3rd party Action 'Unpinned first-party actions' step $@ uses 'foo/bar' with ref 'v1', not a pinned commit hash | .github/workflows/unpinned_first_party.yml:13:9:13:35 | Uses Step | Uses Step |
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Security/CWE-829/UnpinnedActionsTag.ql
1+
query: Security/CWE-829/UnpinnedActionsTag.ql
2+
postprocess: codeql/actions/test/InlineExpectationsTestQuery.ql

0 commit comments

Comments
 (0)