-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathparser.test.js
More file actions
147 lines (142 loc) · 5.16 KB
/
parser.test.js
File metadata and controls
147 lines (142 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// SPDX-FileCopyrightText: the secureCodeBox authors
//
// SPDX-License-Identifier: Apache-2.0
import { readFile } from "node:fs/promises";
import { validateParser } from "@securecodebox/parser-sdk-nodejs/parser-utils";
import { parse } from "./parser";
test("should properly parse file from inline semgrep usage", async () => {
const fileContent = await readFile(
__dirname + "/__testFiles__/minimal-metadata.json",
{
encoding: "utf8",
},
);
const findings = await parse(fileContent);
// validate findings
expect(validateParser(findings)).toBeUndefined();
expect(findings).toMatchInlineSnapshot(`
[
{
"attributes": {
"cwe": null,
"owasp_category": null,
"references": null,
"rule_source": null,
},
"category": "semgrep-result",
"description": "actual := TruncateName(test.in)",
"location": "truncatedname_test.go:44-44",
"name": "-",
"severity": "HIGH",
},
]
`);
});
test("should properly parse file with a single result", async () => {
const fileContent = await readFile(
__dirname + "/__testFiles__/python-injection.json",
{
encoding: "utf8",
},
);
const findings = await parse(fileContent);
// validate findings
expect(validateParser(findings)).toBeUndefined();
expect(findings).toMatchInlineSnapshot(`
[
{
"attributes": {
"cwe": "CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')",
"owasp_category": "A1: Injection",
"references": [
{
"type": "URL",
"value": "https://owasp.org/www-community/attacks/Command_Injection",
},
{
"type": "CWE",
"value": "CWE-78",
},
{
"type": "URL",
"value": "https://cwe.mitre.org/data/definitions/78.html",
},
],
"rule_source": "https://semgrep.dev/r/python.django.security.injection.command.command-injection-os-system.command-injection-os-system",
},
"category": "security",
"description": "Request data detected in os.system. This could be vulnerable to a command injection and should be avoided. If this must be done, use the 'subprocess' module instead and pass the arguments as a list. See https://owasp.org/www-community/attacks/Command_Injection for more information.",
"location": "test.py:4-5",
"name": "python.django.security.injection.command.command-injection-os-system.command-injection-os-system",
"severity": "MEDIUM",
},
]
`);
});
test("should properly parse file with multiple results", async () => {
const fileContent = await readFile(
__dirname + "/__testFiles__/python-injection-multiresult.json",
{
encoding: "utf8",
},
);
const findings = await parse(fileContent);
// validate findings
expect(validateParser(findings)).toBeUndefined();
expect(findings).toMatchInlineSnapshot(`
[
{
"attributes": {
"cwe": "CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')",
"owasp_category": "A1: Injection",
"references": [
{
"type": "URL",
"value": "https://owasp.org/www-community/attacks/Command_Injection",
},
{
"type": "CWE",
"value": "CWE-78",
},
{
"type": "URL",
"value": "https://cwe.mitre.org/data/definitions/78.html",
},
],
"rule_source": "https://semgrep.dev/r/python.django.security.injection.command.command-injection-os-system.command-injection-os-system",
},
"category": "security",
"description": "Request data detected in os.system. This could be vulnerable to a command injection and should be avoided. If this must be done, use the 'subprocess' module instead and pass the arguments as a list. See https://owasp.org/www-community/attacks/Command_Injection for more information.",
"location": "test.py:5-6",
"name": "python.django.security.injection.command.command-injection-os-system.command-injection-os-system",
"severity": "MEDIUM",
},
{
"attributes": {
"cwe": "CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')",
"owasp_category": "A1: Injection",
"references": [
{
"type": "URL",
"value": "https://owasp.org/www-community/attacks/Command_Injection",
},
{
"type": "CWE",
"value": "CWE-78",
},
{
"type": "URL",
"value": "https://cwe.mitre.org/data/definitions/78.html",
},
],
"rule_source": "https://semgrep.dev/r/python.django.security.injection.command.command-injection-os-system.command-injection-os-system",
},
"category": "security",
"description": "Request data detected in os.system. This could be vulnerable to a command injection and should be avoided. If this must be done, use the 'subprocess' module instead and pass the arguments as a list. See https://owasp.org/www-community/attacks/Command_Injection for more information.",
"location": "test.py:10-11",
"name": "python.django.security.injection.command.command-injection-os-system.command-injection-os-system",
"severity": "MEDIUM",
},
]
`);
});