-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: debian purls are validated on package name only
The purl spec does not include both the source and package names for a purl. Container will be generating purls without the source in the purl, which is why we need to relax the check for matching names.
- Loading branch information
1 parent
554097e
commit 7cae162
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { validatePackageURL } from '../../src/core/validate-graph'; | ||
|
||
describe('validatePackageURL', () => { | ||
describe('deb package type tests', () => { | ||
it.each([ | ||
[ | ||
'package name includes source', | ||
{ | ||
name: 'foo/bar', | ||
version: '1.2.3', | ||
purl: 'pkg:deb/[email protected]', | ||
}, | ||
], | ||
[ | ||
'purl is namespaced (includes a vendor)', | ||
{ | ||
name: 'foo/bar', | ||
version: '1.2.3', | ||
purl: 'pkg:deb/debian/[email protected]', | ||
}, | ||
], | ||
[ | ||
'package name does not include source', | ||
{ | ||
name: 'bar', | ||
version: '1.2.3', | ||
purl: 'pkg:deb/[email protected]', | ||
}, | ||
], | ||
[ | ||
'matches on upstream where only the source name is provided', | ||
{ | ||
name: 'foo/bar', | ||
version: '1.2.3', | ||
purl: 'pkg:deb/[email protected]?upstream=foo', | ||
}, | ||
], | ||
[ | ||
'matches on upstream where full upstream is provided', | ||
{ | ||
name: 'foo/bar', | ||
version: '1.2.3', | ||
purl: 'pkg:deb/[email protected]?upstream=foo%401.2.3', | ||
}, | ||
], | ||
[ | ||
'matches on package name where source is unavailable', | ||
{ | ||
name: 'bar', | ||
version: '1.2.3', | ||
purl: 'pkg:deb/[email protected]?upstream=foo%401.2.3', | ||
}, | ||
], | ||
])( | ||
'matches only on package name for debian purls: %s', | ||
(_testCaseName, pkg) => { | ||
expect(() => validatePackageURL(pkg)).not.toThrow(); | ||
}, | ||
); | ||
|
||
it.each([ | ||
[ | ||
'package name does not match purl name', | ||
{ | ||
name: 'foo/bar', | ||
version: '1.2.3', | ||
purl: 'pkg:deb/[email protected]', | ||
}, | ||
], | ||
[ | ||
'package source does not match purl source', | ||
{ | ||
name: 'foo/bar', | ||
version: '1.2.3', | ||
purl: 'pkg:deb/[email protected]?upstream=baz', | ||
}, | ||
], | ||
[ | ||
'purl includes source name', | ||
{ | ||
name: 'foo/bar', | ||
version: '1.2.3', | ||
purl: 'pkg:deb/debian/foo%[email protected]', | ||
}, | ||
], | ||
])('should throw on invalid purl: %s', (_testCaseName, pkg) => { | ||
expect(() => validatePackageURL(pkg)).toThrow(); | ||
}); | ||
}); | ||
}); |