Skip to content

Commit

Permalink
Merge pull request #186 from SalimBensiali/fix-incorrect-vulnerable-m…
Browse files Browse the repository at this point in the history
…anifest-path-check

Fix incorrect vulnerable manifest path check
  • Loading branch information
brrygrdn committed Mar 30, 2022
2 parents e79f0f2 + aa4ffba commit 7e50846
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions src/dependabot/verified_commits.test.ts
Expand Up @@ -134,39 +134,83 @@ const response = {
}
}

const responseWithManifestFileAtRoot = {
data: {
repository: {
vulnerabilityAlerts: {
nodes: [
{
vulnerableManifestFilename: 'package.json',
vulnerableManifestPath: 'package.json',
vulnerableRequirements: '= 4.0.1',
state: 'DISMISSED',
securityVulnerability: { package: { name: 'coffee-script' } },
securityAdvisory: { cvss: { score: 4.5 }, ghsaId: 'FOO' }
}
]
}
}
}
}

test('it returns the alert state if it matches all 3', async () => {
nock('https://api.github.com').post('/graphql', query)
.reply(200, response)

expect(await getAlert('coffee-script', '4.0.1', '/wwwroot', mockGitHubClient, mockGitHubPullContext())).toEqual({ alertState: 'DISMISSED', cvss: 4.5, ghsaId: 'FOO' })

nock('https://api.github.com').post('/graphql', query)
.reply(200, responseWithManifestFileAtRoot)

expect(await getAlert('coffee-script', '4.0.1', '/', mockGitHubClient, mockGitHubPullContext())).toEqual({ alertState: 'DISMISSED', cvss: 4.5, ghsaId: 'FOO' })
})

test('it returns the alert state if it matches 2 and the version is blank', async () => {
nock('https://api.github.com').post('/graphql', query)
.reply(200, response)

expect(await getAlert('coffee-script', '', '/wwwroot', mockGitHubClient, mockGitHubPullContext())).toEqual({ alertState: 'DISMISSED', cvss: 4.5, ghsaId: 'FOO' })

nock('https://api.github.com').post('/graphql', query)
.reply(200, responseWithManifestFileAtRoot)

expect(await getAlert('coffee-script', '', '/', mockGitHubClient, mockGitHubPullContext())).toEqual({ alertState: 'DISMISSED', cvss: 4.5, ghsaId: 'FOO' })
})

test('it returns default if it does not match the version', async () => {
nock('https://api.github.com').post('/graphql', query)
.reply(200, response)

expect(await getAlert('coffee-script', '4.0.2', '/wwwroot', mockGitHubClient, mockGitHubPullContext())).toEqual({ alertState: '', cvss: 0, ghsaId: '' })

nock('https://api.github.com').post('/graphql', query)
.reply(200, responseWithManifestFileAtRoot)

expect(await getAlert('coffee-script', '4.0.2', '/', mockGitHubClient, mockGitHubPullContext())).toEqual({ alertState: '', cvss: 0, ghsaId: '' })
})

test('it returns default if it does not match the directory', async () => {
nock('https://api.github.com').post('/graphql', query)
.reply(200, response)

expect(await getAlert('coffee-script', '4.0.1', '/', mockGitHubClient, mockGitHubPullContext())).toEqual({ alertState: '', cvss: 0, ghsaId: '' })

nock('https://api.github.com').post('/graphql', query)
.reply(200, responseWithManifestFileAtRoot)

expect(await getAlert('coffee-script', '4.0.1', '/wwwroot', mockGitHubClient, mockGitHubPullContext())).toEqual({ alertState: '', cvss: 0, ghsaId: '' })
})

test('it returns default if it does not match the name', async () => {
nock('https://api.github.com').post('/graphql', query)
.reply(200, response)

expect(await getAlert('coffee', '4.0.1', '/wwwroot', mockGitHubClient, mockGitHubPullContext())).toEqual({ alertState: '', cvss: 0, ghsaId: '' })

nock('https://api.github.com').post('/graphql', query)
.reply(200, responseWithManifestFileAtRoot)

expect(await getAlert('coffee', '4.0.1', '/', mockGitHubClient, mockGitHubPullContext())).toEqual({ alertState: '', cvss: 0, ghsaId: '' })
})

test('trimSlashes should only trim slashes from both ends', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/dependabot/verified_commits.ts
Expand Up @@ -78,7 +78,7 @@ export async function getAlert (name: string, version: string, directory: string

const nodes = alerts?.repository?.vulnerabilityAlerts?.nodes
const found = nodes.find(a => (version === '' || a.vulnerableRequirements === `= ${version}`) &&
trimSlashes(a.vulnerableManifestPath) === `${trimSlashes(directory)}/${a.vulnerableManifestFilename}` &&
trimSlashes(a.vulnerableManifestPath) === trimSlashes(`${directory}/${a.vulnerableManifestFilename}`) &&
a.securityVulnerability.package.name === name)

return {
Expand Down

0 comments on commit 7e50846

Please sign in to comment.