-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #753 from actions/juxtin/debug-purl
Parse purls cautiously in getDeniedChanges
- Loading branch information
Showing
18 changed files
with
677 additions
and
427 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 |
---|---|---|
|
@@ -106,6 +106,25 @@ test('denies packages that match the deny group list exactly', async () => { | |
expect(deniedChanges[0]).toBe(changes[1]) | ||
}) | ||
|
||
test(`denies packages using the namespace from the name when there's no package_url`, async () => { | ||
const changes: Changes = [ | ||
createTestChange({ | ||
package_url: 'pkg:npm/org.test.pass/[email protected]', | ||
ecosystem: 'npm' | ||
}), | ||
createTestChange({ | ||
name: 'org.test:deny-this', | ||
package_url: '', | ||
ecosystem: 'maven' | ||
}) | ||
] | ||
const deniedGroups = createTestPURLs(['pkg:maven/org.test/']) | ||
const deniedChanges = await getDeniedChanges(changes, [], deniedGroups) | ||
|
||
expect(deniedChanges.length).toEqual(1) | ||
expect(deniedChanges[0]).toBe(changes[1]) | ||
}) | ||
|
||
test('allows packages not defined in the deny packages and groups list', async () => { | ||
const changes: Changes = [npmChange, pipChange] | ||
const deniedPackages = createTestPURLs([ | ||
|
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,162 @@ | ||
import {expect, test} from '@jest/globals' | ||
import {parsePURL} from '../src/purl' | ||
|
||
test('parsePURL returns an error if the purl does not start with "pkg:"', () => { | ||
const purl = 'not-a-purl' | ||
const result = parsePURL(purl) | ||
expect(result.error).toEqual('package-url must start with "pkg:"') | ||
}) | ||
|
||
test('parsePURL returns an error if the purl does not contain a type', () => { | ||
const purl = 'pkg:/' | ||
const result = parsePURL(purl) | ||
expect(result.error).toEqual('package-url must contain a type') | ||
}) | ||
|
||
test('parsePURL returns an error if the purl does not contain a namespace or name', () => { | ||
const purl = 'pkg:ecosystem/' | ||
const result = parsePURL(purl) | ||
expect(result.type).toEqual('ecosystem') | ||
expect(result.error).toEqual('package-url must contain a namespace or name') | ||
}) | ||
|
||
test('parsePURL returns a PURL with the correct values in the happy case', () => { | ||
const purl = 'pkg:ecosystem/namespace/name@version' | ||
const result = parsePURL(purl) | ||
expect(result.type).toEqual('ecosystem') | ||
expect(result.namespace).toEqual('namespace') | ||
expect(result.name).toEqual('name') | ||
expect(result.version).toEqual('version') | ||
expect(result.original).toEqual(purl) | ||
expect(result.error).toBeNull() | ||
}) | ||
|
||
test('parsePURL table test', () => { | ||
const examples = [ | ||
{ | ||
purl: 'pkg:npm/@n4m3SPACE/Name@^1.2.3', | ||
expected: { | ||
type: 'npm', | ||
namespace: '@n4m3SPACE', | ||
name: 'Name', | ||
version: '^1.2.3', | ||
original: 'pkg:npm/@n4m3SPACE/Name@^1.2.3', | ||
error: null | ||
} | ||
}, | ||
{ | ||
purl: 'pkg:npm/%40ns%20foo/n%40me@1.%2f2.3', | ||
expected: { | ||
type: 'npm', | ||
namespace: '@ns foo', | ||
name: 'n@me', | ||
version: '1./2.3', | ||
original: 'pkg:npm/%40ns%20foo/n%40me@1.%2f2.3', | ||
error: null | ||
} | ||
}, | ||
{ | ||
purl: 'pkg:ecosystem/name@version', | ||
expected: { | ||
type: 'ecosystem', | ||
namespace: null, | ||
name: 'name', | ||
version: 'version', | ||
original: 'pkg:ecosystem/name@version', | ||
error: null | ||
} | ||
}, | ||
{ | ||
purl: 'pkg:npm/namespace/', | ||
expected: { | ||
type: 'npm', | ||
namespace: 'namespace', | ||
name: null, | ||
version: null, | ||
original: 'pkg:npm/namespace/', | ||
error: null | ||
} | ||
}, | ||
{ | ||
purl: 'pkg:ecosystem/name', | ||
expected: { | ||
type: 'ecosystem', | ||
namespace: null, | ||
name: 'name', | ||
version: null, | ||
original: 'pkg:ecosystem/name', | ||
error: null | ||
} | ||
}, | ||
{ | ||
purl: 'pkg:/?', | ||
expected: { | ||
type: '', | ||
namespace: null, | ||
name: null, | ||
version: null, | ||
original: 'pkg:/?', | ||
error: 'package-url must contain a type' | ||
} | ||
}, | ||
{ | ||
purl: 'pkg:ecosystem/#', | ||
expected: { | ||
type: 'ecosystem', | ||
namespace: null, | ||
name: null, | ||
version: null, | ||
original: 'pkg:ecosystem/#', | ||
error: 'package-url must contain a namespace or name' | ||
} | ||
}, | ||
{ | ||
purl: 'pkg:ecosystem/name@version#subpath?attributes=123', | ||
expected: { | ||
type: 'ecosystem', | ||
namespace: null, | ||
name: 'name', | ||
version: 'version', | ||
original: 'pkg:ecosystem/name@version#subpath?attributes=123', | ||
error: null | ||
} | ||
}, | ||
{ | ||
purl: 'pkg:ecosystem/name@version#subpath', | ||
expected: { | ||
type: 'ecosystem', | ||
namespace: null, | ||
name: 'name', | ||
version: 'version', | ||
original: 'pkg:ecosystem/name@version#subpath', | ||
error: null | ||
} | ||
}, | ||
{ | ||
purl: 'pkg:ecosystem/namespace/name@version?attributes', | ||
expected: { | ||
type: 'ecosystem', | ||
namespace: 'namespace', | ||
name: 'name', | ||
version: 'version', | ||
original: 'pkg:ecosystem/namespace/name@version?attributes', | ||
error: null | ||
} | ||
}, | ||
{ | ||
purl: 'pkg:ecosystem/name#subpath?attributes', | ||
expected: { | ||
type: 'ecosystem', | ||
namespace: null, | ||
name: 'name', | ||
version: null, | ||
original: 'pkg:ecosystem/name#subpath?attributes', | ||
error: null | ||
} | ||
} | ||
] | ||
for (const example of examples) { | ||
const result = parsePURL(example.purl) | ||
expect(result).toEqual(example.expected) | ||
} | ||
}) |
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
Oops, something went wrong.