Skip to content

Commit

Permalink
fix: validation logic of cocoapods purls
Browse files Browse the repository at this point in the history
  • Loading branch information
mcombuechen committed Aug 29, 2023
1 parent 2f3203e commit 87159ad
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/validate-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ export function validatePackageURL(pkg: types.PkgInfo): void {
);
break;

// CocoaPods have an optional subspec encoded in the subpath
// component of the purl, which – if present – should
// be appended to the spec.
case 'cocoapods':
assert(
pkg.name ===
(purlPkg.subpath
? `${purlPkg.name}/${purlPkg.subpath}`
: purlPkg.name),
`name and packageURL name do not match`,
);
break;

case 'golang': {
let expected = purlPkg.namespace
? `${purlPkg.namespace}/${purlPkg.name}`
Expand Down
52 changes: 52 additions & 0 deletions test/core/validate-graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,58 @@ describe('validatePackageURL', () => {
});
});

describe('cocoapods Purl type tests', () => {
it.each([
[
'cocoapods package without subspec',
{
name: 'bar',
version: '1.2.3',
purl: 'pkg:cocoapods/bar@1.2.3',
},
],
[
'cocoapods package with subspec',
{
name: 'spec/subspec',
version: '1.2.3',
purl: 'pkg:cocoapods/spec@1.2.3#subspec',
},
],
])('validates cocoapods Purls: %s', (name, pkg) => {
expect(() => validatePackageURL(pkg)).not.toThrow();
});

it.each([
[
'package name does not match purl name',
{
name: 'foo',
version: '1.2.3',
purl: 'pkg:cocoapods/baz@1.2.3',
},
],
[
'package name does not match subspec',
{
name: 'baz/foo',
version: '1.2.3',
purl: 'pkg:cocoapods/baz@1.2.3#bar',
},
],
[
'package name does not include subspec',
{
name: 'bar',
version: '1.2.3',
purl: 'pkg:cocoapods/bar@1.2.3#baz',
},
],
])('should throw on invalid purl: %s', (name, pkg) => {
expect(() => validatePackageURL(pkg)).toThrow();
});
});

describe('composer Purl type tests', () => {
it.each([
[
Expand Down

0 comments on commit 87159ad

Please sign in to comment.