@vltpkg/query 1.0.0-rc.33 → 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/malware.d.ts +3 -16
- package/dist/pseudo/malware.js +11 -171
- 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 +8 -8
- package/skills/dss-query/REFERENCE.md +8 -4
- package/skills/dss-query/SKILL.md +7 -7
- package/src/index.ts +21 -14
- package/src/parser.ts +2 -1
- package/src/pseudo/malware.ts +13 -221
- package/src/pseudo/vuln.ts +273 -0
- package/src/pseudo.ts +3 -3
- package/src/types.ts +3 -2
- package/tap-snapshots/test/pseudo/malware.ts.test.cjs +1 -170
- package/tap-snapshots/test/pseudo/vuln.ts.test.cjs +208 -0
- package/tap-snapshots/test/pseudo/vulnerable.ts.test.cjs +3 -1
- package/test/index.ts +8 -0
- package/test/pseudo/malware.ts +65 -312
- package/test/pseudo/vuln.ts +625 -0
- package/test/pseudo/vulnerable.ts +42 -35
- package/tsconfig.publish.tsbuildinfo +1 -1
- package/dist/pseudo/vulnerable.d.ts +0 -8
- package/dist/pseudo/vulnerable.js +0 -17
- package/src/pseudo/vulnerable.ts +0 -26
package/test/pseudo/malware.ts
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import t from 'tap'
|
|
2
2
|
import { joinDepIDTuple } from '@vltpkg/dep-id'
|
|
3
|
-
import { parse
|
|
3
|
+
import { parse } from '../../src/parser.ts'
|
|
4
4
|
import { asSecurityArchiveLike } from '@vltpkg/security-archive'
|
|
5
5
|
import { getSimpleGraph } from '../fixtures/graph.ts'
|
|
6
|
-
import {
|
|
7
|
-
malware,
|
|
8
|
-
isMalwareKind,
|
|
9
|
-
asMalwareKind,
|
|
10
|
-
parseInternals,
|
|
11
|
-
} from '../../src/pseudo/malware.ts'
|
|
6
|
+
import { malware } from '../../src/pseudo/malware.ts'
|
|
12
7
|
import type { ParserState } from '../../src/types.ts'
|
|
13
8
|
|
|
14
|
-
t.test('selects packages with
|
|
9
|
+
t.test('selects packages with malware alerts', async t => {
|
|
15
10
|
const getState = (query: string, graph = getSimpleGraph()) => {
|
|
16
11
|
const ast = parse(query)
|
|
17
12
|
const current = ast.first.first
|
|
@@ -52,14 +47,7 @@ t.test('selects packages with a specific malware kind', async t => {
|
|
|
52
47
|
joinDepIDTuple(['registry', '', 'c@1.0.0']),
|
|
53
48
|
{
|
|
54
49
|
id: joinDepIDTuple(['registry', '', 'c@1.0.0']),
|
|
55
|
-
alerts: [{ type: '
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
[
|
|
59
|
-
joinDepIDTuple(['registry', '', 'd@1.0.0']),
|
|
60
|
-
{
|
|
61
|
-
id: joinDepIDTuple(['registry', '', 'd@1.0.0']),
|
|
62
|
-
alerts: [{ type: 'gptAnomaly' }],
|
|
50
|
+
alerts: [{ type: 'deprecated' }],
|
|
63
51
|
},
|
|
64
52
|
],
|
|
65
53
|
[
|
|
@@ -69,13 +57,6 @@ t.test('selects packages with a specific malware kind', async t => {
|
|
|
69
57
|
alerts: [{ type: 'malware' }],
|
|
70
58
|
},
|
|
71
59
|
],
|
|
72
|
-
[
|
|
73
|
-
joinDepIDTuple(['registry', '', 'f@1.0.0']),
|
|
74
|
-
{
|
|
75
|
-
id: joinDepIDTuple(['registry', '', 'f@1.0.0']),
|
|
76
|
-
alerts: [{ type: 'gptMalware' }],
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
60
|
]),
|
|
80
61
|
),
|
|
81
62
|
importers: new Set(graph.importers),
|
|
@@ -87,188 +68,13 @@ t.test('selects packages with a specific malware kind', async t => {
|
|
|
87
68
|
}
|
|
88
69
|
|
|
89
70
|
await t.test(
|
|
90
|
-
'
|
|
91
|
-
async t => {
|
|
92
|
-
const res = await malware(getState(':malware("critical")'))
|
|
93
|
-
t.strictSame(
|
|
94
|
-
[...res.partial.nodes].map(n => n.name),
|
|
95
|
-
['a', 'e'],
|
|
96
|
-
'should select only packages with the specified malware alert',
|
|
97
|
-
)
|
|
98
|
-
t.matchSnapshot({
|
|
99
|
-
nodes: [...res.partial.nodes].map(n => n.name),
|
|
100
|
-
edges: [...res.partial.edges].map(e => e.name),
|
|
101
|
-
})
|
|
102
|
-
},
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
await t.test('filter using numbered param', async t => {
|
|
106
|
-
const res = await malware(getState(':malware(0)'))
|
|
107
|
-
t.strictSame(
|
|
108
|
-
[...res.partial.nodes].map(n => n.name),
|
|
109
|
-
['a', 'e'],
|
|
110
|
-
'should select only packages with the specified malware alert',
|
|
111
|
-
)
|
|
112
|
-
t.matchSnapshot({
|
|
113
|
-
nodes: [...res.partial.nodes].map(n => n.name),
|
|
114
|
-
edges: [...res.partial.edges].map(e => e.name),
|
|
115
|
-
})
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
await t.test('filter out using unquoted param', async t => {
|
|
119
|
-
const res = await malware(getState(':malware(high)'))
|
|
120
|
-
t.strictSame(
|
|
121
|
-
[...res.partial.nodes].map(n => n.name),
|
|
122
|
-
['b', 'f'],
|
|
123
|
-
'should select only packages with the specified malware alert',
|
|
124
|
-
)
|
|
125
|
-
t.matchSnapshot({
|
|
126
|
-
nodes: [...res.partial.nodes].map(n => n.name),
|
|
127
|
-
edges: [...res.partial.edges].map(e => e.name),
|
|
128
|
-
})
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
await t.test(
|
|
132
|
-
'greater than comparator with number (unquoted)',
|
|
133
|
-
async t => {
|
|
134
|
-
const res = await malware(getState(':malware(>1)'))
|
|
135
|
-
t.strictSame(
|
|
136
|
-
[...res.partial.nodes].map(n => n.name).sort(),
|
|
137
|
-
['c', 'd'],
|
|
138
|
-
'should select packages with malware kind greater than 1',
|
|
139
|
-
)
|
|
140
|
-
t.matchSnapshot({
|
|
141
|
-
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
142
|
-
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
143
|
-
})
|
|
144
|
-
},
|
|
145
|
-
)
|
|
146
|
-
|
|
147
|
-
await t.test(
|
|
148
|
-
'greater than comparator with string kind (quoted)',
|
|
149
|
-
async t => {
|
|
150
|
-
const res = await malware(getState(':malware(">high")'))
|
|
151
|
-
t.strictSame(
|
|
152
|
-
[...res.partial.nodes].map(n => n.name).sort(),
|
|
153
|
-
['c', 'd'],
|
|
154
|
-
'should select packages with malware kind greater than high',
|
|
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(
|
|
164
|
-
'less than comparator with number (unquoted)',
|
|
165
|
-
async t => {
|
|
166
|
-
const res = await malware(getState(':malware(<2)'))
|
|
167
|
-
t.strictSame(
|
|
168
|
-
[...res.partial.nodes].map(n => n.name).sort(),
|
|
169
|
-
['a', 'b', 'e', 'f'],
|
|
170
|
-
'should select packages with malware kind less than 2',
|
|
171
|
-
)
|
|
172
|
-
t.matchSnapshot({
|
|
173
|
-
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
174
|
-
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
175
|
-
})
|
|
176
|
-
},
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
await t.test(
|
|
180
|
-
'less than comparator with string kind (quoted)',
|
|
181
|
-
async t => {
|
|
182
|
-
const res = await malware(getState(':malware("<medium")'))
|
|
183
|
-
t.strictSame(
|
|
184
|
-
[...res.partial.nodes].map(n => n.name).sort(),
|
|
185
|
-
['a', 'b', 'e', 'f'],
|
|
186
|
-
'should select packages with malware kind less than medium',
|
|
187
|
-
)
|
|
188
|
-
t.matchSnapshot({
|
|
189
|
-
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
190
|
-
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
191
|
-
})
|
|
192
|
-
},
|
|
193
|
-
)
|
|
194
|
-
|
|
195
|
-
await t.test(
|
|
196
|
-
'greater than or equal to comparator with number (unquoted)',
|
|
197
|
-
async t => {
|
|
198
|
-
const res = await malware(getState(':malware(>=2)'))
|
|
199
|
-
t.strictSame(
|
|
200
|
-
[...res.partial.nodes].map(n => n.name).sort(),
|
|
201
|
-
['c', 'd'],
|
|
202
|
-
'should select packages with malware kind greater than or equal to 2',
|
|
203
|
-
)
|
|
204
|
-
t.matchSnapshot({
|
|
205
|
-
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
206
|
-
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
207
|
-
})
|
|
208
|
-
},
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
await t.test(
|
|
212
|
-
'greater than or equal to comparator with string kind (quoted)',
|
|
213
|
-
async t => {
|
|
214
|
-
const res = await malware(getState(':malware(">=medium")'))
|
|
215
|
-
t.strictSame(
|
|
216
|
-
[...res.partial.nodes].map(n => n.name).sort(),
|
|
217
|
-
['c', 'd'],
|
|
218
|
-
'should select packages with malware kind greater than or equal to medium',
|
|
219
|
-
)
|
|
220
|
-
t.matchSnapshot({
|
|
221
|
-
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
222
|
-
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
223
|
-
})
|
|
224
|
-
},
|
|
225
|
-
)
|
|
226
|
-
|
|
227
|
-
await t.test(
|
|
228
|
-
'less than or equal to comparator with number (unquoted)',
|
|
229
|
-
async t => {
|
|
230
|
-
const res = await malware(getState(':malware(<=1)'))
|
|
231
|
-
t.strictSame(
|
|
232
|
-
[...res.partial.nodes].map(n => n.name).sort(),
|
|
233
|
-
['a', 'b', 'e', 'f'],
|
|
234
|
-
'should select packages with malware kind less than or equal to 1',
|
|
235
|
-
)
|
|
236
|
-
t.matchSnapshot({
|
|
237
|
-
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
238
|
-
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
239
|
-
})
|
|
240
|
-
},
|
|
241
|
-
)
|
|
242
|
-
|
|
243
|
-
await t.test(
|
|
244
|
-
'less than or equal to comparator with string kind (quoted)',
|
|
245
|
-
async t => {
|
|
246
|
-
const res = await malware(getState(':malware("<=high")'))
|
|
247
|
-
t.strictSame(
|
|
248
|
-
[...res.partial.nodes].map(n => n.name).sort(),
|
|
249
|
-
['a', 'b', 'e', 'f'],
|
|
250
|
-
'should select packages with malware kind less than or equal to high',
|
|
251
|
-
)
|
|
252
|
-
t.matchSnapshot({
|
|
253
|
-
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
254
|
-
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
255
|
-
})
|
|
256
|
-
},
|
|
257
|
-
)
|
|
258
|
-
|
|
259
|
-
await t.test(
|
|
260
|
-
'parameterless :malware matches medium+ severity',
|
|
71
|
+
'matches nodes with malware or gptMalware alerts',
|
|
261
72
|
async t => {
|
|
262
73
|
const res = await malware(getState(':malware'))
|
|
263
74
|
t.strictSame(
|
|
264
75
|
[...res.partial.nodes].map(n => n.name).sort(),
|
|
265
|
-
['a', 'b', '
|
|
266
|
-
'should select packages with malware
|
|
267
|
-
)
|
|
268
|
-
// Verify that package 'd' with gptAnomaly (low/3) is excluded
|
|
269
|
-
t.notOk(
|
|
270
|
-
[...res.partial.nodes].some(n => n.name === 'd'),
|
|
271
|
-
'should exclude package d with gptAnomaly (low severity)',
|
|
76
|
+
['a', 'b', 'e'],
|
|
77
|
+
'should select only packages with malware or gptMalware alerts',
|
|
272
78
|
)
|
|
273
79
|
t.matchSnapshot({
|
|
274
80
|
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
@@ -277,29 +83,67 @@ t.test('selects packages with a specific malware kind', async t => {
|
|
|
277
83
|
},
|
|
278
84
|
)
|
|
279
85
|
|
|
280
|
-
await t.test('
|
|
281
|
-
await
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
'should
|
|
86
|
+
await t.test('excludes nodes without malware alerts', async t => {
|
|
87
|
+
const res = await malware(getState(':malware'))
|
|
88
|
+
t.notOk(
|
|
89
|
+
[...res.partial.nodes].some(n => n.name === 'c'),
|
|
90
|
+
'should exclude package c with only deprecated alert',
|
|
285
91
|
)
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
await t.rejects(
|
|
290
|
-
malware(getState(':malware(>invalid)')),
|
|
291
|
-
{ message: /Failed to parse :malware selector/ },
|
|
292
|
-
'should throw an error for invalid comparison value',
|
|
92
|
+
t.notOk(
|
|
93
|
+
[...res.partial.nodes].some(n => n.name === 'd'),
|
|
94
|
+
'should exclude package d with no security data',
|
|
293
95
|
)
|
|
294
96
|
})
|
|
97
|
+
})
|
|
295
98
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
99
|
+
t.test(':malware rejects parameters', async t => {
|
|
100
|
+
const getState = (query: string, graph = getSimpleGraph()) => {
|
|
101
|
+
const ast = parse(query)
|
|
102
|
+
const current = ast.first.first
|
|
103
|
+
const state: ParserState = {
|
|
104
|
+
comment: '',
|
|
105
|
+
current,
|
|
106
|
+
initial: {
|
|
107
|
+
edges: new Set(graph.edges.values()),
|
|
108
|
+
nodes: new Set(graph.nodes.values()),
|
|
109
|
+
},
|
|
110
|
+
partial: {
|
|
111
|
+
edges: new Set(graph.edges.values()),
|
|
112
|
+
nodes: new Set(graph.nodes.values()),
|
|
113
|
+
},
|
|
114
|
+
collect: {
|
|
115
|
+
edges: new Set(),
|
|
116
|
+
nodes: new Set(),
|
|
117
|
+
},
|
|
118
|
+
cancellable: async () => {},
|
|
119
|
+
walk: async i => i,
|
|
120
|
+
securityArchive: asSecurityArchiveLike(
|
|
121
|
+
new Map([
|
|
122
|
+
[
|
|
123
|
+
joinDepIDTuple(['registry', '', 'a@1.0.0']),
|
|
124
|
+
{
|
|
125
|
+
id: joinDepIDTuple(['registry', '', 'a@1.0.0']),
|
|
126
|
+
alerts: [{ type: 'malware' }],
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
]),
|
|
130
|
+
),
|
|
131
|
+
importers: new Set(graph.importers),
|
|
132
|
+
retries: 0,
|
|
133
|
+
signal: new AbortController().signal,
|
|
134
|
+
specificity: { idCounter: 0, commonCounter: 0 },
|
|
135
|
+
}
|
|
136
|
+
return state
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
await t.rejects(
|
|
140
|
+
malware(getState(':malware(critical)')),
|
|
141
|
+
{
|
|
142
|
+
message:
|
|
143
|
+
/:malware selector does not accept parameters\. Use :vuln\(<severity>\) for severity-based filtering\./,
|
|
144
|
+
},
|
|
145
|
+
'should throw when parameters are provided',
|
|
146
|
+
)
|
|
303
147
|
})
|
|
304
148
|
|
|
305
149
|
t.test('missing security archive', async t => {
|
|
@@ -333,99 +177,8 @@ t.test('missing security archive', async t => {
|
|
|
333
177
|
}
|
|
334
178
|
|
|
335
179
|
await t.rejects(
|
|
336
|
-
malware(getState(':malware
|
|
180
|
+
malware(getState(':malware')),
|
|
337
181
|
{ message: /Missing security archive/ },
|
|
338
182
|
'should throw an error',
|
|
339
183
|
)
|
|
340
184
|
})
|
|
341
|
-
|
|
342
|
-
t.test('isMalwareKind', async t => {
|
|
343
|
-
t.ok(
|
|
344
|
-
isMalwareKind('critical'),
|
|
345
|
-
'should return true for valid malware kinds',
|
|
346
|
-
)
|
|
347
|
-
t.notOk(
|
|
348
|
-
isMalwareKind('invalid'),
|
|
349
|
-
'should return false for invalid malware kinds',
|
|
350
|
-
)
|
|
351
|
-
})
|
|
352
|
-
|
|
353
|
-
t.test('asMalwareKind', async t => {
|
|
354
|
-
t.equal(
|
|
355
|
-
asMalwareKind('critical'),
|
|
356
|
-
'critical',
|
|
357
|
-
'should return the malware kind',
|
|
358
|
-
)
|
|
359
|
-
t.throws(
|
|
360
|
-
() => asMalwareKind('invalid'),
|
|
361
|
-
{ message: /Expected a valid malware kind/ },
|
|
362
|
-
'should throw an error for invalid malware kinds',
|
|
363
|
-
)
|
|
364
|
-
})
|
|
365
|
-
|
|
366
|
-
t.test('parseInternals', async t => {
|
|
367
|
-
const testParseInternals = (query: string) => {
|
|
368
|
-
const ast = parse(query)
|
|
369
|
-
const nodes = asPostcssNodeWithChildren(ast.first.first).nodes
|
|
370
|
-
return parseInternals(nodes)
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
t.strictSame(
|
|
374
|
-
parseInternals([]),
|
|
375
|
-
{ kind: undefined, comparator: undefined },
|
|
376
|
-
'should handle empty nodes array (parameterless :malware)',
|
|
377
|
-
)
|
|
378
|
-
|
|
379
|
-
// Test case for lines 87-88: selector node exists but has no child nodes
|
|
380
|
-
t.strictSame(
|
|
381
|
-
parseInternals([{ type: 'selector', nodes: [] } as any]),
|
|
382
|
-
{ kind: undefined, comparator: undefined },
|
|
383
|
-
'should handle selector node with empty nodes array',
|
|
384
|
-
)
|
|
385
|
-
|
|
386
|
-
t.strictSame(
|
|
387
|
-
testParseInternals(':malware(critical)'),
|
|
388
|
-
{ kind: 'critical', comparator: undefined },
|
|
389
|
-
'should parse simple kind without comparator',
|
|
390
|
-
)
|
|
391
|
-
|
|
392
|
-
t.strictSame(
|
|
393
|
-
testParseInternals(':malware(">1")'),
|
|
394
|
-
{ kind: '1', comparator: '>' },
|
|
395
|
-
'should parse kind with greater than comparator',
|
|
396
|
-
)
|
|
397
|
-
|
|
398
|
-
t.strictSame(
|
|
399
|
-
testParseInternals(':malware(<low)'),
|
|
400
|
-
{ kind: 'low', comparator: '<' },
|
|
401
|
-
'should parse kind with less than comparator',
|
|
402
|
-
)
|
|
403
|
-
|
|
404
|
-
t.strictSame(
|
|
405
|
-
testParseInternals(':malware(">=medium")'),
|
|
406
|
-
{ kind: 'medium', comparator: '>=' },
|
|
407
|
-
'should parse kind with greater than or equal comparator',
|
|
408
|
-
)
|
|
409
|
-
|
|
410
|
-
t.strictSame(
|
|
411
|
-
testParseInternals(':malware(<=2)'),
|
|
412
|
-
{ kind: '2', comparator: '<=' },
|
|
413
|
-
'should parse kind with less than or equal comparator',
|
|
414
|
-
)
|
|
415
|
-
|
|
416
|
-
t.throws(
|
|
417
|
-
() => testParseInternals(':malware(>invalid)'),
|
|
418
|
-
{
|
|
419
|
-
message: /Expected a valid malware kind or number between 0-3/,
|
|
420
|
-
},
|
|
421
|
-
'should throw for invalid kind with comparator',
|
|
422
|
-
)
|
|
423
|
-
|
|
424
|
-
t.throws(
|
|
425
|
-
() => testParseInternals(':malware(>4)'),
|
|
426
|
-
{
|
|
427
|
-
message: /Expected a valid malware kind or number between 0-3/,
|
|
428
|
-
},
|
|
429
|
-
'should throw for out of range number with comparator',
|
|
430
|
-
)
|
|
431
|
-
})
|