Skip to content

Commit e53cac0

Browse files
authored
Merge pull request #111 from snyk/fix/validate-cocoapods-purl
fix: validation logic of cocoapods purls
2 parents 2f3203e + 87159ad commit e53cac0

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/core/validate-graph.ts

+13
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ export function validatePackageURL(pkg: types.PkgInfo): void {
6060
);
6161
break;
6262

63+
// CocoaPods have an optional subspec encoded in the subpath
64+
// component of the purl, which – if present – should
65+
// be appended to the spec.
66+
case 'cocoapods':
67+
assert(
68+
pkg.name ===
69+
(purlPkg.subpath
70+
? `${purlPkg.name}/${purlPkg.subpath}`
71+
: purlPkg.name),
72+
`name and packageURL name do not match`,
73+
);
74+
break;
75+
6376
case 'golang': {
6477
let expected = purlPkg.namespace
6578
? `${purlPkg.namespace}/${purlPkg.name}`

test/core/validate-graph.test.ts

+52
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,58 @@ describe('validatePackageURL', () => {
8888
});
8989
});
9090

91+
describe('cocoapods Purl type tests', () => {
92+
it.each([
93+
[
94+
'cocoapods package without subspec',
95+
{
96+
name: 'bar',
97+
version: '1.2.3',
98+
purl: 'pkg:cocoapods/[email protected]',
99+
},
100+
],
101+
[
102+
'cocoapods package with subspec',
103+
{
104+
name: 'spec/subspec',
105+
version: '1.2.3',
106+
purl: 'pkg:cocoapods/[email protected]#subspec',
107+
},
108+
],
109+
])('validates cocoapods Purls: %s', (name, pkg) => {
110+
expect(() => validatePackageURL(pkg)).not.toThrow();
111+
});
112+
113+
it.each([
114+
[
115+
'package name does not match purl name',
116+
{
117+
name: 'foo',
118+
version: '1.2.3',
119+
purl: 'pkg:cocoapods/[email protected]',
120+
},
121+
],
122+
[
123+
'package name does not match subspec',
124+
{
125+
name: 'baz/foo',
126+
version: '1.2.3',
127+
purl: 'pkg:cocoapods/[email protected]#bar',
128+
},
129+
],
130+
[
131+
'package name does not include subspec',
132+
{
133+
name: 'bar',
134+
version: '1.2.3',
135+
purl: 'pkg:cocoapods/[email protected]#baz',
136+
},
137+
],
138+
])('should throw on invalid purl: %s', (name, pkg) => {
139+
expect(() => validatePackageURL(pkg)).toThrow();
140+
});
141+
});
142+
91143
describe('composer Purl type tests', () => {
92144
it.each([
93145
[

0 commit comments

Comments
 (0)