-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathresolved-vulnerabilities.test.ts
More file actions
122 lines (105 loc) · 3.43 KB
/
resolved-vulnerabilities.test.ts
File metadata and controls
122 lines (105 loc) · 3.43 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
import {test, expect} from '@jest/globals'
import {getResolvedVulnerabilities} from '../src/resolved-vulnerabilities'
import {Changes, Change} from '../src/schemas'
const vulnerableRemovedChange: Change = {
change_type: 'removed',
manifest: 'package.json',
ecosystem: 'npm',
name: 'lodash',
version: '4.17.20',
package_url: 'pkg:npm/lodash@4.17.20',
license: 'MIT',
source_repository_url: 'https://github.com/lodash/lodash',
scope: 'runtime',
vulnerabilities: [
{
severity: 'high',
advisory_ghsa_id: 'GHSA-35jh-r3h4-6jhm',
advisory_summary: 'lodash Prototype Pollution vulnerability',
advisory_url: 'https://github.com/advisories/GHSA-35jh-r3h4-6jhm'
},
{
severity: 'critical',
advisory_ghsa_id: 'GHSA-p6mc-m468-83gw',
advisory_summary: 'lodash Command Injection via template',
advisory_url: 'https://github.com/advisories/GHSA-p6mc-m468-83gw'
}
]
}
const nonVulnerableRemovedChange: Change = {
change_type: 'removed',
manifest: 'package.json',
ecosystem: 'npm',
name: 'express',
version: '4.18.0',
package_url: 'pkg:npm/express@4.18.0',
license: 'MIT',
source_repository_url: 'https://github.com/expressjs/express',
scope: 'runtime',
vulnerabilities: []
}
const addedChange: Change = {
change_type: 'added',
manifest: 'package.json',
ecosystem: 'npm',
name: 'react',
version: '18.0.0',
package_url: 'pkg:npm/react@18.0.0',
license: 'MIT',
source_repository_url: 'https://github.com/facebook/react',
scope: 'runtime',
vulnerabilities: [
{
severity: 'moderate',
advisory_ghsa_id: 'GHSA-test-1234',
advisory_summary: 'Test vulnerability',
advisory_url: 'https://github.com/advisories/GHSA-test-1234'
}
]
}
test('extracts resolved vulnerabilities from removed packages', () => {
const changes: Changes = [
vulnerableRemovedChange,
nonVulnerableRemovedChange,
addedChange
]
const resolvedVulns = getResolvedVulnerabilities(changes)
expect(resolvedVulns).toHaveLength(2)
expect(resolvedVulns[0]).toEqual({
severity: 'high',
advisory_ghsa_id: 'GHSA-35jh-r3h4-6jhm',
advisory_summary: 'lodash Prototype Pollution vulnerability',
advisory_url: 'https://github.com/advisories/GHSA-35jh-r3h4-6jhm',
package_name: 'lodash',
package_version: '4.17.20',
package_url: 'pkg:npm/lodash@4.17.20',
manifest: 'package.json',
ecosystem: 'npm'
})
expect(resolvedVulns[1]).toEqual({
severity: 'critical',
advisory_ghsa_id: 'GHSA-p6mc-m468-83gw',
advisory_summary: 'lodash Command Injection via template',
advisory_url: 'https://github.com/advisories/GHSA-p6mc-m468-83gw',
package_name: 'lodash',
package_version: '4.17.20',
package_url: 'pkg:npm/lodash@4.17.20',
manifest: 'package.json',
ecosystem: 'npm'
})
})
test('returns empty array when no removed packages have vulnerabilities', () => {
const changes: Changes = [nonVulnerableRemovedChange, addedChange]
const resolvedVulns = getResolvedVulnerabilities(changes)
expect(resolvedVulns).toHaveLength(0)
})
test('ignores added packages with vulnerabilities', () => {
const changes: Changes = [addedChange]
const resolvedVulns = getResolvedVulnerabilities(changes)
expect(resolvedVulns).toHaveLength(0)
})
test('handles empty changes array', () => {
const changes: Changes = []
const resolvedVulns = getResolvedVulnerabilities(changes)
expect(resolvedVulns).toHaveLength(0)
})