@vltpkg/query 1.0.0-rc.32 → 1.0.0-rc.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +10 -6
- package/dist/parser.js +2 -1
- package/dist/pseudo/hostname.js +3 -1
- package/dist/pseudo/malware.d.ts +3 -16
- package/dist/pseudo/malware.js +11 -171
- package/dist/pseudo/scripts.js +1 -1
- package/dist/pseudo/vuln.d.ts +22 -0
- package/dist/pseudo/vuln.js +220 -0
- package/dist/pseudo.js +3 -3
- package/dist/types.d.ts +3 -2
- package/package.json +19 -10
- package/skills/dss-query/REFERENCE.md +123 -0
- package/skills/dss-query/SKILL.md +190 -0
- package/skills/dss-query/evals/README.md +79 -0
- package/skills/dss-query/evals/evals.json +89 -0
- package/skills/dss-query/evals/grade.mjs +480 -0
- package/src/attribute.ts +186 -0
- package/src/combinator.ts +132 -0
- package/src/id.ts +46 -0
- package/src/index.ts +620 -0
- package/src/parser.ts +122 -0
- package/src/pseudo/abandoned.ts +9 -0
- package/src/pseudo/attr.ts +92 -0
- package/src/pseudo/built.ts +19 -0
- package/src/pseudo/confused.ts +29 -0
- package/src/pseudo/cve.ts +93 -0
- package/src/pseudo/cwe.ts +97 -0
- package/src/pseudo/debug.ts +9 -0
- package/src/pseudo/deprecated.ts +9 -0
- package/src/pseudo/dev.ts +18 -0
- package/src/pseudo/diff.ts +90 -0
- package/src/pseudo/dist.ts +144 -0
- package/src/pseudo/dynamic.ts +9 -0
- package/src/pseudo/empty.ts +15 -0
- package/src/pseudo/entropic.ts +9 -0
- package/src/pseudo/env.ts +6 -0
- package/src/pseudo/eval.ts +9 -0
- package/src/pseudo/fs.ts +9 -0
- package/src/pseudo/helpers.ts +106 -0
- package/src/pseudo/host.ts +111 -0
- package/src/pseudo/hostname.ts +156 -0
- package/src/pseudo/license.ts +134 -0
- package/src/pseudo/link.ts +30 -0
- package/src/pseudo/malware.ts +41 -0
- package/src/pseudo/minified.ts +9 -0
- package/src/pseudo/missing.ts +16 -0
- package/src/pseudo/native.ts +9 -0
- package/src/pseudo/network.ts +9 -0
- package/src/pseudo/obfuscated.ts +9 -0
- package/src/pseudo/optional.ts +18 -0
- package/src/pseudo/outdated.ts +305 -0
- package/src/pseudo/overridden.ts +20 -0
- package/src/pseudo/path.ts +146 -0
- package/src/pseudo/peer.ts +18 -0
- package/src/pseudo/prerelease.ts +47 -0
- package/src/pseudo/private.ts +19 -0
- package/src/pseudo/prod.ts +18 -0
- package/src/pseudo/published.ts +248 -0
- package/src/pseudo/registry.ts +29 -0
- package/src/pseudo/root.ts +19 -0
- package/src/pseudo/scanned.ts +20 -0
- package/src/pseudo/score.ts +186 -0
- package/src/pseudo/scripts.ts +54 -0
- package/src/pseudo/semver.ts +320 -0
- package/src/pseudo/severity.ts +231 -0
- package/src/pseudo/shell.ts +9 -0
- package/src/pseudo/shrinkwrap.ts +9 -0
- package/src/pseudo/spec.ts +131 -0
- package/src/pseudo/squat.ts +225 -0
- package/src/pseudo/suspicious.ts +9 -0
- package/src/pseudo/tracker.ts +9 -0
- package/src/pseudo/trivial.ts +9 -0
- package/src/pseudo/type.ts +26 -0
- package/src/pseudo/undesirable.ts +9 -0
- package/src/pseudo/unknown.ts +9 -0
- package/src/pseudo/unmaintained.ts +9 -0
- package/src/pseudo/unpopular.ts +9 -0
- package/src/pseudo/unstable.ts +9 -0
- package/src/pseudo/vuln.ts +273 -0
- package/src/pseudo/workspace.ts +22 -0
- package/src/pseudo.ts +413 -0
- package/src/types.ts +165 -0
- package/tap-snapshots/test/attribute.ts.test.cjs +304 -0
- package/tap-snapshots/test/combinator.ts.test.cjs +333 -0
- package/tap-snapshots/test/id.ts.test.cjs +118 -0
- package/tap-snapshots/test/parser.ts.test.cjs +344 -0
- package/tap-snapshots/test/pseudo/abandoned.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/attr.ts.test.cjs +161 -0
- package/tap-snapshots/test/pseudo/built.ts.test.cjs +70 -0
- package/tap-snapshots/test/pseudo/confused.ts.test.cjs +32 -0
- package/tap-snapshots/test/pseudo/cve.ts.test.cjs +49 -0
- package/tap-snapshots/test/pseudo/cwe.ts.test.cjs +49 -0
- package/tap-snapshots/test/pseudo/debug.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/deprecated.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/dist.ts.test.cjs +30 -0
- package/tap-snapshots/test/pseudo/dynamic.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/empty.ts.test.cjs +50 -0
- package/tap-snapshots/test/pseudo/entropic.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/env.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/eval.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/fs.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/helpers.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/hostname.ts.test.cjs +148 -0
- package/tap-snapshots/test/pseudo/license.ts.test.cjs +41 -0
- package/tap-snapshots/test/pseudo/link.ts.test.cjs +36 -0
- package/tap-snapshots/test/pseudo/malware.ts.test.cjs +22 -0
- package/tap-snapshots/test/pseudo/minified.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/missing.ts.test.cjs +30 -0
- package/tap-snapshots/test/pseudo/native.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/network.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/obfuscated.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/outdated.ts.test.cjs +130 -0
- package/tap-snapshots/test/pseudo/overridden.ts.test.cjs +75 -0
- package/tap-snapshots/test/pseudo/prerelease.ts.test.cjs +101 -0
- package/tap-snapshots/test/pseudo/private.ts.test.cjs +38 -0
- package/tap-snapshots/test/pseudo/published.ts.test.cjs +171 -0
- package/tap-snapshots/test/pseudo/registry.ts.test.cjs +68 -0
- package/tap-snapshots/test/pseudo/root.ts.test.cjs +24 -0
- package/tap-snapshots/test/pseudo/scanned.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/score.ts.test.cjs +239 -0
- package/tap-snapshots/test/pseudo/scripts.ts.test.cjs +61 -0
- package/tap-snapshots/test/pseudo/semver.ts.test.cjs +575 -0
- package/tap-snapshots/test/pseudo/severity.ts.test.cjs +95 -0
- package/tap-snapshots/test/pseudo/shell.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/shrinkwrap.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/spec.ts.test.cjs +148 -0
- package/tap-snapshots/test/pseudo/squat.ts.test.cjs +129 -0
- package/tap-snapshots/test/pseudo/suspicious.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/tracker.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/trivial.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/type.ts.test.cjs +51 -0
- package/tap-snapshots/test/pseudo/undesirable.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/unknown.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/unmaintained.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/unpopular.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/unstable.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/vuln.ts.test.cjs +208 -0
- package/tap-snapshots/test/pseudo/vulnerable.ts.test.cjs +20 -0
- package/tap-snapshots/test/pseudo/workspace.ts.test.cjs +19 -0
- package/tap-snapshots/test/pseudo.ts.test.cjs +1247 -0
- package/test/attribute.ts +266 -0
- package/test/combinator.ts +168 -0
- package/test/fixtures/graph.ts +999 -0
- package/test/fixtures/selector.ts +103 -0
- package/test/fixtures/types.ts +7 -0
- package/test/id.ts +102 -0
- package/test/index.ts +1000 -0
- package/test/parser.ts +117 -0
- package/test/pseudo/abandoned.ts +98 -0
- package/test/pseudo/attr.ts +298 -0
- package/test/pseudo/built.ts +214 -0
- package/test/pseudo/confused.ts +160 -0
- package/test/pseudo/cve.ts +249 -0
- package/test/pseudo/cwe.ts +255 -0
- package/test/pseudo/debug.ts +98 -0
- package/test/pseudo/deprecated.ts +98 -0
- package/test/pseudo/dev.ts +61 -0
- package/test/pseudo/diff.ts +417 -0
- package/test/pseudo/dist.ts +215 -0
- package/test/pseudo/dynamic.ts +98 -0
- package/test/pseudo/empty.ts +108 -0
- package/test/pseudo/entropic.ts +101 -0
- package/test/pseudo/env.ts +98 -0
- package/test/pseudo/eval.ts +98 -0
- package/test/pseudo/fs.ts +98 -0
- package/test/pseudo/helpers.ts +370 -0
- package/test/pseudo/host-context.ts +276 -0
- package/test/pseudo/hostname.ts +314 -0
- package/test/pseudo/license.ts +265 -0
- package/test/pseudo/link.ts +94 -0
- package/test/pseudo/malware.ts +184 -0
- package/test/pseudo/minified.ts +98 -0
- package/test/pseudo/missing.ts +111 -0
- package/test/pseudo/native.ts +98 -0
- package/test/pseudo/network.ts +98 -0
- package/test/pseudo/obfuscated.ts +98 -0
- package/test/pseudo/optional.ts +73 -0
- package/test/pseudo/outdated.ts +331 -0
- package/test/pseudo/overridden.ts +317 -0
- package/test/pseudo/path.ts +680 -0
- package/test/pseudo/peer.ts +101 -0
- package/test/pseudo/prerelease.ts +279 -0
- package/test/pseudo/private.ts +108 -0
- package/test/pseudo/prod.ts +61 -0
- package/test/pseudo/published.ts +557 -0
- package/test/pseudo/registry.ts +122 -0
- package/test/pseudo/root.ts +66 -0
- package/test/pseudo/scanned.ts +78 -0
- package/test/pseudo/score.ts +591 -0
- package/test/pseudo/scripts.ts +294 -0
- package/test/pseudo/semver.ts +822 -0
- package/test/pseudo/severity.ts +310 -0
- package/test/pseudo/shell.ts +98 -0
- package/test/pseudo/shrinkwrap.ts +98 -0
- package/test/pseudo/spec.ts +525 -0
- package/test/pseudo/squat.ts +565 -0
- package/test/pseudo/suspicious.ts +98 -0
- package/test/pseudo/tracker.ts +98 -0
- package/test/pseudo/trivial.ts +98 -0
- package/test/pseudo/type.ts +105 -0
- package/test/pseudo/undesirable.ts +98 -0
- package/test/pseudo/unknown.ts +98 -0
- package/test/pseudo/unmaintained.ts +98 -0
- package/test/pseudo/unpopular.ts +98 -0
- package/test/pseudo/unstable.ts +98 -0
- package/test/pseudo/vuln.ts +625 -0
- package/test/pseudo/vulnerable.ts +137 -0
- package/test/pseudo/workspace.ts +111 -0
- package/test/pseudo.ts +558 -0
- package/tsconfig.json +3 -0
- package/tsconfig.publish.json +19 -0
- package/tsconfig.publish.tsbuildinfo +1 -0
- package/typedoc.mjs +2 -0
- package/dist/pseudo/vulnerable.d.ts +0 -8
- package/dist/pseudo/vulnerable.js +0 -17
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
import t from 'tap'
|
|
2
|
+
import { joinDepIDTuple } from '@vltpkg/dep-id'
|
|
3
|
+
import { asPostcssNodeWithChildren } from '@vltpkg/dss-parser'
|
|
4
|
+
import { parse } from '../../src/parser.ts'
|
|
5
|
+
import { asSecurityArchiveLike } from '@vltpkg/security-archive'
|
|
6
|
+
import { getSimpleGraph } from '../fixtures/graph.ts'
|
|
7
|
+
import {
|
|
8
|
+
vuln,
|
|
9
|
+
isVulnKind,
|
|
10
|
+
asVulnKind,
|
|
11
|
+
parseInternals,
|
|
12
|
+
} from '../../src/pseudo/vuln.ts'
|
|
13
|
+
import type { ParserState } from '../../src/types.ts'
|
|
14
|
+
|
|
15
|
+
t.test('selects packages with vulnerability alerts', async t => {
|
|
16
|
+
const getState = (query: string, graph = getSimpleGraph()) => {
|
|
17
|
+
const ast = parse(query)
|
|
18
|
+
const current = ast.first.first
|
|
19
|
+
const state: ParserState = {
|
|
20
|
+
comment: '',
|
|
21
|
+
current,
|
|
22
|
+
initial: {
|
|
23
|
+
edges: new Set(graph.edges.values()),
|
|
24
|
+
nodes: new Set(graph.nodes.values()),
|
|
25
|
+
},
|
|
26
|
+
partial: {
|
|
27
|
+
edges: new Set(graph.edges.values()),
|
|
28
|
+
nodes: new Set(graph.nodes.values()),
|
|
29
|
+
},
|
|
30
|
+
collect: {
|
|
31
|
+
edges: new Set(),
|
|
32
|
+
nodes: new Set(),
|
|
33
|
+
},
|
|
34
|
+
cancellable: async () => {},
|
|
35
|
+
walk: async i => i,
|
|
36
|
+
securityArchive: asSecurityArchiveLike(
|
|
37
|
+
new Map([
|
|
38
|
+
[
|
|
39
|
+
joinDepIDTuple(['registry', '', 'a@1.0.0']),
|
|
40
|
+
{
|
|
41
|
+
id: joinDepIDTuple(['registry', '', 'a@1.0.0']),
|
|
42
|
+
alerts: [{ type: 'criticalCVE' }],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
joinDepIDTuple(['registry', '', 'b@1.0.0']),
|
|
47
|
+
{
|
|
48
|
+
id: joinDepIDTuple(['registry', '', 'b@1.0.0']),
|
|
49
|
+
alerts: [{ type: 'cve' }],
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
joinDepIDTuple(['registry', '', 'c@1.0.0']),
|
|
54
|
+
{
|
|
55
|
+
id: joinDepIDTuple(['registry', '', 'c@1.0.0']),
|
|
56
|
+
alerts: [{ type: 'potentialVulnerability' }],
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
[
|
|
60
|
+
joinDepIDTuple(['registry', '', 'd@1.0.0']),
|
|
61
|
+
{
|
|
62
|
+
id: joinDepIDTuple(['registry', '', 'd@1.0.0']),
|
|
63
|
+
alerts: [{ type: 'mildCVE' }],
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
[
|
|
67
|
+
joinDepIDTuple(['registry', '', 'e@1.0.0']),
|
|
68
|
+
{
|
|
69
|
+
id: joinDepIDTuple(['registry', '', 'e@1.0.0']),
|
|
70
|
+
alerts: [{ type: 'gptSecurity' }],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
[
|
|
74
|
+
joinDepIDTuple(['registry', '', 'f@1.0.0']),
|
|
75
|
+
{
|
|
76
|
+
id: joinDepIDTuple(['registry', '', 'f@1.0.0']),
|
|
77
|
+
alerts: [{ type: 'gptAnomaly' }],
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
[
|
|
81
|
+
joinDepIDTuple(['file', 'y']),
|
|
82
|
+
{
|
|
83
|
+
id: joinDepIDTuple(['file', 'y']),
|
|
84
|
+
alerts: [
|
|
85
|
+
{
|
|
86
|
+
type: 'deprecated',
|
|
87
|
+
severity: 'medium' as const,
|
|
88
|
+
category: 'maintenance',
|
|
89
|
+
key: 'deprecated',
|
|
90
|
+
props: { lastPublish: '2020-01-01' },
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
]),
|
|
96
|
+
),
|
|
97
|
+
importers: new Set(graph.importers),
|
|
98
|
+
retries: 0,
|
|
99
|
+
signal: new AbortController().signal,
|
|
100
|
+
specificity: { idCounter: 0, commonCounter: 0 },
|
|
101
|
+
}
|
|
102
|
+
return state
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
await t.test(
|
|
106
|
+
'filter out any node that does not have the vuln alert',
|
|
107
|
+
async t => {
|
|
108
|
+
const res = await vuln(getState(':vuln("critical")'))
|
|
109
|
+
t.strictSame(
|
|
110
|
+
[...res.partial.nodes].map(n => n.name),
|
|
111
|
+
['a'],
|
|
112
|
+
'should select only packages with the specified vuln alert',
|
|
113
|
+
)
|
|
114
|
+
t.matchSnapshot({
|
|
115
|
+
nodes: [...res.partial.nodes].map(n => n.name),
|
|
116
|
+
edges: [...res.partial.edges].map(e => e.name),
|
|
117
|
+
})
|
|
118
|
+
},
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
await t.test('filter using numbered param', async t => {
|
|
122
|
+
const res = await vuln(getState(':vuln(0)'))
|
|
123
|
+
t.strictSame(
|
|
124
|
+
[...res.partial.nodes].map(n => n.name),
|
|
125
|
+
['a'],
|
|
126
|
+
'should select only packages with the specified vuln alert',
|
|
127
|
+
)
|
|
128
|
+
t.matchSnapshot({
|
|
129
|
+
nodes: [...res.partial.nodes].map(n => n.name),
|
|
130
|
+
edges: [...res.partial.edges].map(e => e.name),
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
await t.test('filter out using unquoted param', async t => {
|
|
135
|
+
const res = await vuln(getState(':vuln(high)'))
|
|
136
|
+
t.strictSame(
|
|
137
|
+
[...res.partial.nodes].map(n => n.name),
|
|
138
|
+
['b'],
|
|
139
|
+
'should select only packages with the specified vuln alert',
|
|
140
|
+
)
|
|
141
|
+
t.matchSnapshot({
|
|
142
|
+
nodes: [...res.partial.nodes].map(n => n.name),
|
|
143
|
+
edges: [...res.partial.edges].map(e => e.name),
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
await t.test(
|
|
148
|
+
'medium matches both potentialVulnerability and gptSecurity',
|
|
149
|
+
async t => {
|
|
150
|
+
const res = await vuln(getState(':vuln(medium)'))
|
|
151
|
+
t.strictSame(
|
|
152
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
153
|
+
['c', 'e'],
|
|
154
|
+
'should select packages with potentialVulnerability or gptSecurity',
|
|
155
|
+
)
|
|
156
|
+
t.matchSnapshot({
|
|
157
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
158
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
159
|
+
})
|
|
160
|
+
},
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
await t.test('low matches both mildCVE and gptAnomaly', async t => {
|
|
164
|
+
const res = await vuln(getState(':vuln(low)'))
|
|
165
|
+
t.strictSame(
|
|
166
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
167
|
+
['d', 'f'],
|
|
168
|
+
'should select packages with mildCVE or gptAnomaly',
|
|
169
|
+
)
|
|
170
|
+
t.matchSnapshot({
|
|
171
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
172
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
await t.test(
|
|
177
|
+
'greater than comparator with number (unquoted)',
|
|
178
|
+
async t => {
|
|
179
|
+
const res = await vuln(getState(':vuln(>1)'))
|
|
180
|
+
t.strictSame(
|
|
181
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
182
|
+
['c', 'd', 'e', 'f'],
|
|
183
|
+
'should select packages with vuln kind greater than 1',
|
|
184
|
+
)
|
|
185
|
+
t.matchSnapshot({
|
|
186
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
187
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
188
|
+
})
|
|
189
|
+
},
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
await t.test(
|
|
193
|
+
'greater than comparator with string kind (quoted)',
|
|
194
|
+
async t => {
|
|
195
|
+
const res = await vuln(getState(':vuln(">high")'))
|
|
196
|
+
t.strictSame(
|
|
197
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
198
|
+
['c', 'd', 'e', 'f'],
|
|
199
|
+
'should select packages with vuln kind greater than high',
|
|
200
|
+
)
|
|
201
|
+
t.matchSnapshot({
|
|
202
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
203
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
204
|
+
})
|
|
205
|
+
},
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
await t.test(
|
|
209
|
+
'less than comparator with number (unquoted)',
|
|
210
|
+
async t => {
|
|
211
|
+
const res = await vuln(getState(':vuln(<2)'))
|
|
212
|
+
t.strictSame(
|
|
213
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
214
|
+
['a', 'b'],
|
|
215
|
+
'should select packages with vuln kind less than 2',
|
|
216
|
+
)
|
|
217
|
+
t.matchSnapshot({
|
|
218
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
219
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
220
|
+
})
|
|
221
|
+
},
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
await t.test(
|
|
225
|
+
'less than comparator with string kind (quoted)',
|
|
226
|
+
async t => {
|
|
227
|
+
const res = await vuln(getState(':vuln("<medium")'))
|
|
228
|
+
t.strictSame(
|
|
229
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
230
|
+
['a', 'b'],
|
|
231
|
+
'should select packages with vuln kind less than medium',
|
|
232
|
+
)
|
|
233
|
+
t.matchSnapshot({
|
|
234
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
235
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
236
|
+
})
|
|
237
|
+
},
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
await t.test(
|
|
241
|
+
'greater than or equal to comparator with number (unquoted)',
|
|
242
|
+
async t => {
|
|
243
|
+
const res = await vuln(getState(':vuln(>=2)'))
|
|
244
|
+
t.strictSame(
|
|
245
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
246
|
+
['c', 'd', 'e', 'f'],
|
|
247
|
+
'should select packages with vuln kind greater than or equal to 2',
|
|
248
|
+
)
|
|
249
|
+
t.matchSnapshot({
|
|
250
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
251
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
252
|
+
})
|
|
253
|
+
},
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
await t.test(
|
|
257
|
+
'greater than or equal to comparator with string kind (quoted)',
|
|
258
|
+
async t => {
|
|
259
|
+
const res = await vuln(getState(':vuln(">=medium")'))
|
|
260
|
+
t.strictSame(
|
|
261
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
262
|
+
['c', 'd', 'e', 'f'],
|
|
263
|
+
'should select packages with vuln kind greater than or equal to medium',
|
|
264
|
+
)
|
|
265
|
+
t.matchSnapshot({
|
|
266
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
267
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
268
|
+
})
|
|
269
|
+
},
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
await t.test(
|
|
273
|
+
'less than or equal to comparator with number (unquoted)',
|
|
274
|
+
async t => {
|
|
275
|
+
const res = await vuln(getState(':vuln(<=1)'))
|
|
276
|
+
t.strictSame(
|
|
277
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
278
|
+
['a', 'b'],
|
|
279
|
+
'should select packages with vuln kind less than or equal to 1',
|
|
280
|
+
)
|
|
281
|
+
t.matchSnapshot({
|
|
282
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
283
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
284
|
+
})
|
|
285
|
+
},
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
await t.test(
|
|
289
|
+
'less than or equal to comparator with string kind (quoted)',
|
|
290
|
+
async t => {
|
|
291
|
+
const res = await vuln(getState(':vuln("<=high")'))
|
|
292
|
+
t.strictSame(
|
|
293
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
294
|
+
['a', 'b'],
|
|
295
|
+
'should select packages with vuln kind less than or equal to high',
|
|
296
|
+
)
|
|
297
|
+
t.matchSnapshot({
|
|
298
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
299
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
300
|
+
})
|
|
301
|
+
},
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
await t.test(
|
|
305
|
+
'parameterless :vuln matches medium+ severity',
|
|
306
|
+
async t => {
|
|
307
|
+
const res = await vuln(getState(':vuln'))
|
|
308
|
+
t.strictSame(
|
|
309
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
310
|
+
['a', 'b', 'c', 'e'],
|
|
311
|
+
'should select packages with vuln severity >= medium (exclude low)',
|
|
312
|
+
)
|
|
313
|
+
// Verify that packages d (mildCVE) and f (gptAnomaly) are excluded
|
|
314
|
+
t.notOk(
|
|
315
|
+
[...res.partial.nodes].some(n => n.name === 'd'),
|
|
316
|
+
'should exclude package d with mildCVE (low severity)',
|
|
317
|
+
)
|
|
318
|
+
t.notOk(
|
|
319
|
+
[...res.partial.nodes].some(n => n.name === 'f'),
|
|
320
|
+
'should exclude package f with gptAnomaly (low severity)',
|
|
321
|
+
)
|
|
322
|
+
t.matchSnapshot({
|
|
323
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
324
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
325
|
+
})
|
|
326
|
+
},
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
await t.test(
|
|
330
|
+
'comparator excludes non-vuln alert types',
|
|
331
|
+
async t => {
|
|
332
|
+
// @x/y has only a 'deprecated' alert — its type is not in
|
|
333
|
+
// alertLevelMap and it has no cveId, so it must be skipped
|
|
334
|
+
// (covers the currentAlertLevel == null continue branch)
|
|
335
|
+
const res = await vuln(getState(':vuln(">=medium")'))
|
|
336
|
+
t.notOk(
|
|
337
|
+
[...res.partial.nodes].some(n => n.name === '@x/y'),
|
|
338
|
+
'should exclude @x/y which only has a deprecated alert',
|
|
339
|
+
)
|
|
340
|
+
},
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
await t.test('wrong parameter', async t => {
|
|
344
|
+
await t.rejects(
|
|
345
|
+
vuln(getState(':vuln("")')),
|
|
346
|
+
{ message: /Failed to parse :vuln selector/ },
|
|
347
|
+
'should throw an error',
|
|
348
|
+
)
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
await t.test('invalid comparison value', async t => {
|
|
352
|
+
await t.rejects(
|
|
353
|
+
vuln(getState(':vuln(>invalid)')),
|
|
354
|
+
{ message: /Failed to parse :vuln selector/ },
|
|
355
|
+
'should throw an error for invalid comparison value',
|
|
356
|
+
)
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
await t.test('out of range number', async t => {
|
|
360
|
+
await t.rejects(
|
|
361
|
+
vuln(getState(':vuln(>5)')),
|
|
362
|
+
{ message: /Failed to parse :vuln selector/ },
|
|
363
|
+
'should throw an error for out of range number',
|
|
364
|
+
)
|
|
365
|
+
})
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
t.test('cveId matching', async t => {
|
|
369
|
+
const getState = (query: string, graph = getSimpleGraph()) => {
|
|
370
|
+
const ast = parse(query)
|
|
371
|
+
const current = ast.first.first
|
|
372
|
+
const state: ParserState = {
|
|
373
|
+
comment: '',
|
|
374
|
+
current,
|
|
375
|
+
initial: {
|
|
376
|
+
edges: new Set(graph.edges.values()),
|
|
377
|
+
nodes: new Set(graph.nodes.values()),
|
|
378
|
+
},
|
|
379
|
+
partial: {
|
|
380
|
+
edges: new Set(graph.edges.values()),
|
|
381
|
+
nodes: new Set(graph.nodes.values()),
|
|
382
|
+
},
|
|
383
|
+
collect: {
|
|
384
|
+
edges: new Set(),
|
|
385
|
+
nodes: new Set(),
|
|
386
|
+
},
|
|
387
|
+
cancellable: async () => {},
|
|
388
|
+
walk: async i => i,
|
|
389
|
+
securityArchive: asSecurityArchiveLike(
|
|
390
|
+
new Map([
|
|
391
|
+
[
|
|
392
|
+
joinDepIDTuple(['registry', '', 'a@1.0.0']),
|
|
393
|
+
{
|
|
394
|
+
id: joinDepIDTuple(['registry', '', 'a@1.0.0']),
|
|
395
|
+
alerts: [
|
|
396
|
+
{
|
|
397
|
+
type: 'socketUpstreamVulnerability',
|
|
398
|
+
severity: 'high' as const,
|
|
399
|
+
category: 'vulnerability',
|
|
400
|
+
key: 'upstream-vuln-1',
|
|
401
|
+
props: {
|
|
402
|
+
lastPublish: '2024-01-01',
|
|
403
|
+
cveId: 'CVE-2024-1234' as const,
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
],
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
[
|
|
410
|
+
joinDepIDTuple(['registry', '', 'b@1.0.0']),
|
|
411
|
+
{
|
|
412
|
+
id: joinDepIDTuple(['registry', '', 'b@1.0.0']),
|
|
413
|
+
alerts: [
|
|
414
|
+
{
|
|
415
|
+
type: 'socketUpstreamVulnerability',
|
|
416
|
+
severity: 'low' as const,
|
|
417
|
+
category: 'vulnerability',
|
|
418
|
+
key: 'upstream-vuln-2',
|
|
419
|
+
props: {
|
|
420
|
+
lastPublish: '2024-01-01',
|
|
421
|
+
cveId: 'CVE-2024-5678' as const,
|
|
422
|
+
},
|
|
423
|
+
},
|
|
424
|
+
],
|
|
425
|
+
},
|
|
426
|
+
],
|
|
427
|
+
[
|
|
428
|
+
joinDepIDTuple(['registry', '', 'c@1.0.0']),
|
|
429
|
+
{
|
|
430
|
+
id: joinDepIDTuple(['registry', '', 'c@1.0.0']),
|
|
431
|
+
alerts: [{ type: 'criticalCVE' }],
|
|
432
|
+
},
|
|
433
|
+
],
|
|
434
|
+
]),
|
|
435
|
+
),
|
|
436
|
+
importers: new Set(graph.importers),
|
|
437
|
+
retries: 0,
|
|
438
|
+
signal: new AbortController().signal,
|
|
439
|
+
specificity: { idCounter: 0, commonCounter: 0 },
|
|
440
|
+
}
|
|
441
|
+
return state
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
await t.test(
|
|
445
|
+
'parameterless :vuln matches cveId-bearing alerts with severity >= medium',
|
|
446
|
+
async t => {
|
|
447
|
+
const res = await vuln(getState(':vuln'))
|
|
448
|
+
const names = [...res.partial.nodes].map(n => n.name).sort()
|
|
449
|
+
t.ok(
|
|
450
|
+
names.includes('a'),
|
|
451
|
+
'should include a (socketUpstreamVulnerability with high severity cveId)',
|
|
452
|
+
)
|
|
453
|
+
t.ok(names.includes('c'), 'should include c (criticalCVE)')
|
|
454
|
+
t.notOk(
|
|
455
|
+
names.includes('b'),
|
|
456
|
+
'should exclude b (socketUpstreamVulnerability with low severity cveId)',
|
|
457
|
+
)
|
|
458
|
+
},
|
|
459
|
+
)
|
|
460
|
+
|
|
461
|
+
await t.test(
|
|
462
|
+
'exact match :vuln(high) matches cveId-bearing alerts by severity',
|
|
463
|
+
async t => {
|
|
464
|
+
const res = await vuln(getState(':vuln(high)'))
|
|
465
|
+
const names = [...res.partial.nodes].map(n => n.name).sort()
|
|
466
|
+
t.ok(
|
|
467
|
+
names.includes('a'),
|
|
468
|
+
'should include a (cveId with high severity)',
|
|
469
|
+
)
|
|
470
|
+
t.notOk(
|
|
471
|
+
names.includes('b'),
|
|
472
|
+
'should exclude b (cveId with low severity)',
|
|
473
|
+
)
|
|
474
|
+
t.notOk(
|
|
475
|
+
names.includes('c'),
|
|
476
|
+
'should exclude c (criticalCVE, not high)',
|
|
477
|
+
)
|
|
478
|
+
},
|
|
479
|
+
)
|
|
480
|
+
|
|
481
|
+
await t.test(
|
|
482
|
+
'comparator :vuln(">=high") matches cveId-bearing alerts by severity',
|
|
483
|
+
async t => {
|
|
484
|
+
const res = await vuln(getState(':vuln("<=high")'))
|
|
485
|
+
const names = [...res.partial.nodes].map(n => n.name).sort()
|
|
486
|
+
t.ok(
|
|
487
|
+
names.includes('a'),
|
|
488
|
+
'should include a (cveId with high severity)',
|
|
489
|
+
)
|
|
490
|
+
t.ok(names.includes('c'), 'should include c (criticalCVE)')
|
|
491
|
+
t.notOk(
|
|
492
|
+
names.includes('b'),
|
|
493
|
+
'should exclude b (cveId with low severity)',
|
|
494
|
+
)
|
|
495
|
+
},
|
|
496
|
+
)
|
|
497
|
+
})
|
|
498
|
+
|
|
499
|
+
t.test('missing security archive', async t => {
|
|
500
|
+
const getState = (query: string) => {
|
|
501
|
+
const ast = parse(query)
|
|
502
|
+
const current = ast.first.first
|
|
503
|
+
const state: ParserState = {
|
|
504
|
+
comment: '',
|
|
505
|
+
current,
|
|
506
|
+
initial: {
|
|
507
|
+
edges: new Set(),
|
|
508
|
+
nodes: new Set(),
|
|
509
|
+
},
|
|
510
|
+
partial: {
|
|
511
|
+
edges: new Set(),
|
|
512
|
+
nodes: new Set(),
|
|
513
|
+
},
|
|
514
|
+
collect: {
|
|
515
|
+
edges: new Set(),
|
|
516
|
+
nodes: new Set(),
|
|
517
|
+
},
|
|
518
|
+
cancellable: async () => {},
|
|
519
|
+
walk: async i => i,
|
|
520
|
+
securityArchive: undefined,
|
|
521
|
+
importers: new Set(),
|
|
522
|
+
retries: 0,
|
|
523
|
+
signal: new AbortController().signal,
|
|
524
|
+
specificity: { idCounter: 0, commonCounter: 0 },
|
|
525
|
+
}
|
|
526
|
+
return state
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
await t.rejects(
|
|
530
|
+
vuln(getState(':vuln(critical)')),
|
|
531
|
+
{ message: /Missing security archive/ },
|
|
532
|
+
'should throw an error',
|
|
533
|
+
)
|
|
534
|
+
})
|
|
535
|
+
|
|
536
|
+
t.test('isVulnKind', async t => {
|
|
537
|
+
t.ok(
|
|
538
|
+
isVulnKind('critical'),
|
|
539
|
+
'should return true for valid vuln kinds',
|
|
540
|
+
)
|
|
541
|
+
t.notOk(
|
|
542
|
+
isVulnKind('invalid'),
|
|
543
|
+
'should return false for invalid vuln kinds',
|
|
544
|
+
)
|
|
545
|
+
})
|
|
546
|
+
|
|
547
|
+
t.test('asVulnKind', async t => {
|
|
548
|
+
t.equal(
|
|
549
|
+
asVulnKind('critical'),
|
|
550
|
+
'critical',
|
|
551
|
+
'should return the vuln kind',
|
|
552
|
+
)
|
|
553
|
+
t.throws(
|
|
554
|
+
() => asVulnKind('invalid'),
|
|
555
|
+
{ message: /Expected a valid vuln kind/ },
|
|
556
|
+
'should throw an error for invalid vuln kinds',
|
|
557
|
+
)
|
|
558
|
+
})
|
|
559
|
+
|
|
560
|
+
t.test('parseInternals', async t => {
|
|
561
|
+
const testParseInternals = (query: string) => {
|
|
562
|
+
const ast = parse(query)
|
|
563
|
+
const nodes = asPostcssNodeWithChildren(ast.first.first).nodes
|
|
564
|
+
return parseInternals(nodes)
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
t.strictSame(
|
|
568
|
+
parseInternals([]),
|
|
569
|
+
{ kind: undefined, comparator: undefined },
|
|
570
|
+
'should handle empty nodes array (parameterless :vuln)',
|
|
571
|
+
)
|
|
572
|
+
|
|
573
|
+
// Test case for selector node exists but has no child nodes
|
|
574
|
+
t.strictSame(
|
|
575
|
+
parseInternals([{ type: 'selector', nodes: [] } as any]),
|
|
576
|
+
{ kind: undefined, comparator: undefined },
|
|
577
|
+
'should handle selector node with empty nodes array',
|
|
578
|
+
)
|
|
579
|
+
|
|
580
|
+
t.strictSame(
|
|
581
|
+
testParseInternals(':vuln(critical)'),
|
|
582
|
+
{ kind: 'critical', comparator: undefined },
|
|
583
|
+
'should parse simple kind without comparator',
|
|
584
|
+
)
|
|
585
|
+
|
|
586
|
+
t.strictSame(
|
|
587
|
+
testParseInternals(':vuln(">1")'),
|
|
588
|
+
{ kind: '1', comparator: '>' },
|
|
589
|
+
'should parse kind with greater than comparator',
|
|
590
|
+
)
|
|
591
|
+
|
|
592
|
+
t.strictSame(
|
|
593
|
+
testParseInternals(':vuln(<low)'),
|
|
594
|
+
{ kind: 'low', comparator: '<' },
|
|
595
|
+
'should parse kind with less than comparator',
|
|
596
|
+
)
|
|
597
|
+
|
|
598
|
+
t.strictSame(
|
|
599
|
+
testParseInternals(':vuln(">=medium")'),
|
|
600
|
+
{ kind: 'medium', comparator: '>=' },
|
|
601
|
+
'should parse kind with greater than or equal comparator',
|
|
602
|
+
)
|
|
603
|
+
|
|
604
|
+
t.strictSame(
|
|
605
|
+
testParseInternals(':vuln(<=2)'),
|
|
606
|
+
{ kind: '2', comparator: '<=' },
|
|
607
|
+
'should parse kind with less than or equal comparator',
|
|
608
|
+
)
|
|
609
|
+
|
|
610
|
+
t.throws(
|
|
611
|
+
() => testParseInternals(':vuln(>invalid)'),
|
|
612
|
+
{
|
|
613
|
+
message: /Expected a valid vuln kind or number between 0-3/,
|
|
614
|
+
},
|
|
615
|
+
'should throw for invalid kind with comparator',
|
|
616
|
+
)
|
|
617
|
+
|
|
618
|
+
t.throws(
|
|
619
|
+
() => testParseInternals(':vuln(>4)'),
|
|
620
|
+
{
|
|
621
|
+
message: /Expected a valid vuln kind or number between 0-3/,
|
|
622
|
+
},
|
|
623
|
+
'should throw for out of range number with comparator',
|
|
624
|
+
)
|
|
625
|
+
})
|