Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct broken URLs for license issues
Update the vulnerability URL generation so that it differentiates between license and security issues. License issues should resolve to a 301 redirect, where as security issues have their own page on https://security.snyk.io
- Loading branch information
1 parent
813eb23
commit 8a46931
Showing
5 changed files
with
39 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import config from '../config'; | ||
|
||
const licenseRegex = /^snyk:lic/i; | ||
|
||
export function getVulnerabilityUrl(vulnerabilityId: string): string { | ||
return licenseRegex.test(vulnerabilityId) | ||
? `${config.ROOT}/vuln/${vulnerabilityId}` | ||
: `${config.PUBLIC_VULN_DB_URL}/vuln/${vulnerabilityId}`; | ||
} |
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
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,24 @@ | ||
import { getVulnerabilityUrl } from '../../../../../src/lib/formatters/get-vuln-url'; | ||
import config from '../../../../../src/lib/config'; | ||
|
||
describe('getVulnerabilityUrl', () => { | ||
it('returns a valid license URL', () => { | ||
expect(getVulnerabilityUrl('snyk:lic:pip:certifi:MPL-2.0')).toBe( | ||
`${config.ROOT}/vuln/snyk:lic:pip:certifi:MPL-2.0`, | ||
); | ||
}); | ||
|
||
it('returns a valid license URL - UPPERCASE', () => { | ||
expect(getVulnerabilityUrl('SNYK:LIC:PIP:CERTIFI:MPL-2.0')).toBe( | ||
`${config.ROOT}/vuln/SNYK:LIC:PIP:CERTIFI:MPL-2.0`, | ||
); | ||
}); | ||
|
||
it('returns a valid vulnerability URL', () => { | ||
expect( | ||
getVulnerabilityUrl('SNYK-JS-LOOPBACKCONNECTORPOSTGRESQL-2980123'), | ||
).toBe( | ||
`${config.PUBLIC_VULN_DB_URL}/vuln/SNYK-JS-LOOPBACKCONNECTORPOSTGRESQL-2980123`, | ||
); | ||
}); | ||
}); |