Skip to content

fix: validation logic of cocoapods purls #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/[email protected]',
},
],
[
'cocoapods package with subspec',
{
name: 'spec/subspec',
version: '1.2.3',
purl: 'pkg:cocoapods/[email protected]#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/[email protected]',
},
],
[
'package name does not match subspec',
{
name: 'baz/foo',
version: '1.2.3',
purl: 'pkg:cocoapods/[email protected]#bar',
},
],
[
'package name does not include subspec',
{
name: 'bar',
version: '1.2.3',
purl: 'pkg:cocoapods/[email protected]#baz',
},
],
])('should throw on invalid purl: %s', (name, pkg) => {
expect(() => validatePackageURL(pkg)).toThrow();
});
});

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