-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: output additional SARIF data (#4966)
* Added the following: artifacts scanned, CVSS score, package name, and fix information * Updated unit tests * Added an acceptance test Co-authored-by: schottsfired <[email protected]>
- Loading branch information
1 parent
c2eadce
commit 8f1ff94
Showing
12 changed files
with
181 additions
and
14 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
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 |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
"tool": { | ||
"driver": { | ||
"name": "Snyk Container", | ||
"properties": { | ||
"artifactsScanned": 2 | ||
}, | ||
"rules": [ | ||
{ | ||
"id": "SNYK-LINUX-BZIP2-106947", | ||
|
@@ -26,7 +29,8 @@ | |
"tags": [ | ||
"security", | ||
"deb" | ||
] | ||
], | ||
"cvssv3_baseScore": 6.5 | ||
} | ||
} | ||
] | ||
|
@@ -48,7 +52,12 @@ | |
"region": { | ||
"startLine": 1 | ||
} | ||
} | ||
}, | ||
"logicalLocations": [ | ||
{ | ||
"fullyQualifiedName": "[email protected]" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
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 |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
"tool": { | ||
"driver": { | ||
"name": "Snyk Container", | ||
"properties": { | ||
"artifactsScanned": 2 | ||
}, | ||
"rules": [ | ||
{ | ||
"id": "SNYK-LINUX-BZIP2-106947", | ||
|
@@ -26,7 +29,8 @@ | |
"tags": [ | ||
"security", | ||
"deb" | ||
] | ||
], | ||
"cvssv3_baseScore": 6.5 | ||
} | ||
} | ||
] | ||
|
@@ -48,7 +52,12 @@ | |
"region": { | ||
"startLine": 1 | ||
} | ||
} | ||
}, | ||
"logicalLocations": [ | ||
{ | ||
"fullyQualifiedName": "[email protected]" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
57 changes: 57 additions & 0 deletions
57
test/jest/acceptance/snyk-test/output-formats/sarif.spec.ts
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,57 @@ | ||
import { createProjectFromFixture } from '../../../util/createProject'; | ||
import { runSnykCLI } from '../../../util/runSnykCLI'; | ||
import { fakeServer } from '../../../../acceptance/fake-server'; | ||
|
||
jest.setTimeout(1000 * 60); | ||
|
||
describe('snyk test --sarif', () => { | ||
let server; | ||
let env: Record<string, string>; | ||
|
||
beforeAll((done) => { | ||
const port = process.env.PORT || process.env.SNYK_PORT || '12345'; | ||
const baseApi = '/api/v1'; | ||
env = { | ||
...process.env, | ||
SNYK_API: 'http://localhost:' + port + baseApi, | ||
SNYK_HOST: 'http://localhost:' + port, | ||
SNYK_TOKEN: '123456789', | ||
SNYK_DISABLE_ANALYTICS: '1', | ||
}; | ||
server = fakeServer(baseApi, env.SNYK_TOKEN); | ||
server.listen(port, () => { | ||
done(); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
server.restore(); | ||
}); | ||
|
||
afterAll((done) => { | ||
server.close(() => { | ||
done(); | ||
}); | ||
}); | ||
|
||
test('`snyk test --sarif` includes the expected output', async () => { | ||
const project = await createProjectFromFixture( | ||
'npm/with-vulnerable-lodash-dep', | ||
); | ||
server.setDepGraphResponse( | ||
await project.readJSON('test-dep-graph-result.json'), | ||
); | ||
|
||
const { code, stdout } = await runSnykCLI('test --sarif', { | ||
cwd: project.path(), | ||
env, | ||
}); | ||
expect(code).toEqual(1); | ||
|
||
expect(stdout).toContain('"artifactsScanned": 1'); | ||
expect(stdout).toContain('"cvssv3_baseScore": 5.3'); | ||
expect(stdout).toContain('"fullyQualifiedName": "[email protected]"'); | ||
expect(stdout).toContain('Upgrade to [email protected]'); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -7,9 +7,22 @@ Object { | |
Object { | ||
"results": Array [ | ||
Object { | ||
"fixes": Array [ | ||
Object { | ||
"artifactChanges": Array [], | ||
"description": Object { | ||
"text": "Upgrade to [email protected]", | ||
}, | ||
}, | ||
], | ||
"level": "error", | ||
"locations": Array [ | ||
Object { | ||
"logicalLocations": Array [ | ||
Object { | ||
"fullyQualifiedName": "[email protected]", | ||
}, | ||
], | ||
"physicalLocation": Object { | ||
"artifactLocation": Object { | ||
"uri": "package.json", | ||
|
@@ -29,6 +42,9 @@ Object { | |
"tool": Object { | ||
"driver": Object { | ||
"name": "Snyk Open Source", | ||
"properties": Object { | ||
"artifactsScanned": 969, | ||
}, | ||
"rules": Array [ | ||
Object { | ||
"fullDescription": Object { | ||
|
@@ -46,6 +62,7 @@ Object { | |
}, | ||
"id": "SNYK-JS-AJV-584908", | ||
"properties": Object { | ||
"cvssv3_baseScore": 7.5, | ||
"tags": Array [ | ||
"security", | ||
"CWE-400", | ||
|
Oops, something went wrong.