Skip to content

Commit 1521a46

Browse files
committed
update test scripts
1 parent 37c8068 commit 1521a46

35 files changed

+439
-5
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Ignore ast-grep snapshots
2-
tests/__snapshots__/*
3-
41
# Other package managers
52
bun.lockb
63

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
"description": "ast-grep essential security rules",
55
"main": "index.js",
66
"scripts": {
7-
"test": "ast-grep test --skip-snapshot-tests -c ./sgconfig.yml",
8-
"update-tests": "ast-grep test -U -c ./sgconfig.yml"
7+
"test-wip": "ast-grep test --skip-snapshot-tests -c ./sgconfig.yml",
8+
"test-ci": "ast-grep test -c ./sgconfig.yml",
9+
"test": "ast-grep test --interactive -c ./sgconfig.yml",
10+
"test-update-all": "ast-grep test --update-all -c ./sgconfig.yml"
911
},
1012
"author": "",
1113
"license": "ISC",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
id: bad-tmp-go
2+
snapshots:
3+
ioutil.WriteFile("/tmp/demo2", "tmp"):
4+
labels:
5+
- source: ioutil.WriteFile("/tmp/demo2", "tmp")
6+
style: primary
7+
start: 0
8+
end: 37
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
id: binary-formatter
2+
snapshots:
3+
BinaryFormatter binaryFormatter = new BinaryFormatter();:
4+
labels:
5+
- source: new BinaryFormatter()
6+
style: primary
7+
start: 34
8+
end: 55
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
id: command-injection-formatted-runtime-call
2+
snapshots:
3+
? |
4+
val r: Runtime = Runtime.getRuntime()
5+
r.exec("/bin/sh -c tool_command" + input)
6+
: labels:
7+
- source: r.exec("/bin/sh -c tool_command" + input)
8+
style: primary
9+
start: 38
10+
end: 79
11+
? |-
12+
val r: Runtime = Runtime.getRuntime()
13+
r.loadLibrary(String.format("%s.dll", input))
14+
: labels:
15+
- source: r.loadLibrary(String.format("%s.dll", input))
16+
style: primary
17+
start: 38
18+
end: 83
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
id: data-contract-resolver
2+
snapshots:
3+
? |-
4+
namespace DCR
5+
{
6+
class CustomDCR : DataContractResolver
7+
{
8+
}
9+
}
10+
: labels:
11+
- source: |-
12+
class CustomDCR : DataContractResolver
13+
{
14+
}
15+
style: primary
16+
start: 20
17+
end: 70
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
id: detect-replaceall-sanitization
2+
snapshots:
3+
? |
4+
"<strong>Hello World</strong>".replace('<', '&lt;').replace('>', '&gt;')
5+
: labels:
6+
- source: '"<strong>Hello World</strong>".replace(''<'', ''&lt;'').replace(''>'', ''&gt;'')'
7+
style: primary
8+
start: 0
9+
end: 72
10+
? |
11+
"<strong>Hello World</strong>".replaceAll('"', '&quot;').replaceAll("'", '&apos;').replaceAll('&', '&amp;')
12+
: labels:
13+
- source: '"<strong>Hello World</strong>".replaceAll(''"'', ''&quot;'').replaceAll("''", ''&apos;'').replaceAll(''&'', ''&amp;'')'
14+
style: primary
15+
start: 0
16+
end: 107
17+
? |
18+
"<strong>Hello World</strong>".replaceAll('<', '&lt;').replaceAll('>', '&gt;')
19+
: labels:
20+
- source: '"<strong>Hello World</strong>".replaceAll(''<'', ''&lt;'').replaceAll(''>'', ''&gt;'')'
21+
style: primary
22+
start: 0
23+
end: 78
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
id: empty-aes-key
2+
snapshots:
3+
cipher = AES.new("", AES.MODE_CFB, iv):
4+
labels:
5+
- source: AES.new("", AES.MODE_CFB, iv)
6+
style: primary
7+
start: 9
8+
end: 38
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
id: go-template-insecure-types
2+
snapshots:
3+
? |
4+
var b template.CSS = "a { text-decoration: underline; } "
5+
: labels:
6+
- source: 'var b template.CSS = "a { text-decoration: underline; } "'
7+
style: primary
8+
start: 0
9+
end: 57
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
id: grpc-client-insecure-connection
2+
snapshots:
3+
? |
4+
grpc.Dial("example.com", grpc.WithInsecure())
5+
: labels:
6+
- source: grpc.Dial("example.com", grpc.WithInsecure())
7+
style: primary
8+
start: 0
9+
end: 45
10+
? |
11+
grpc.Dial("example.com", grpc.WithInsecure(), grpc.WithBlock())
12+
: labels:
13+
- source: grpc.Dial("example.com", grpc.WithInsecure(), grpc.WithBlock())
14+
style: primary
15+
start: 0
16+
end: 63
17+
? |
18+
grpc.Dial("example.com", grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(5*time.Second))
19+
: labels:
20+
- source: grpc.Dial("example.com", grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(5*time.Second))
21+
style: primary
22+
start: 0
23+
end: 96
24+
? |
25+
grpc.Dial("example.com", grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(5*time.Second), grpc.WithUserAgent("example"))
26+
: labels:
27+
- source: grpc.Dial("example.com", grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(5*time.Second), grpc.WithUserAgent("example"))
28+
style: primary
29+
start: 0
30+
end: 127
31+
? |
32+
grpc.Dial("example.com", grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(5*time.Second), grpc.WithUserAgent("example"), grpc.WithAuthority("example.com"))
33+
: labels:
34+
- source: grpc.Dial("example.com", grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(5*time.Second), grpc.WithUserAgent("example"), grpc.WithAuthority("example.com"))
35+
style: primary
36+
start: 0
37+
end: 162
38+
? grpc.Dial("example.com", grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(5*time.Second), grpc.WithUserAgent("example"), grpc.WithAuthority("example.com"), grpc.WithDial)
39+
: labels:
40+
- source: grpc.Dial("example.com", grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(5*time.Second), grpc.WithUserAgent("example"), grpc.WithAuthority("example.com"), grpc.WithDial)
41+
style: primary
42+
start: 0
43+
end: 177

0 commit comments

Comments
 (0)