-
Notifications
You must be signed in to change notification settings - Fork 13
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 #60 from snyk/fix/wrong-number-of-issues-on-sarif
[COD-254] fix: wrong number of calculated issues as part of the Sarif conversion
- Loading branch information
Showing
4 changed files
with
196 additions
and
55 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,96 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Functional test of analysis detailed sarif tests analyze remote git and formatter sarif with supported files 1`] = ` | ||
Array [ | ||
Object { | ||
"files": 115, | ||
"isSupported": false, | ||
"lang": "Unknown", | ||
}, | ||
Object { | ||
"files": 34, | ||
"isSupported": false, | ||
"lang": "Markdown", | ||
}, | ||
Object { | ||
"files": 6, | ||
"isSupported": false, | ||
"lang": "YAML", | ||
}, | ||
Object { | ||
"files": 3, | ||
"isSupported": false, | ||
"lang": "Shell", | ||
}, | ||
Object { | ||
"files": 39, | ||
"isSupported": false, | ||
"lang": "Text", | ||
}, | ||
Object { | ||
"files": 34, | ||
"isSupported": false, | ||
"lang": "XML", | ||
}, | ||
Object { | ||
"files": 4, | ||
"isSupported": false, | ||
"lang": "INI", | ||
}, | ||
Object { | ||
"files": 122, | ||
"isSupported": true, | ||
"lang": "JavaScript", | ||
}, | ||
Object { | ||
"files": 81, | ||
"isSupported": false, | ||
"lang": "JSON", | ||
}, | ||
Object { | ||
"files": 13, | ||
"isSupported": false, | ||
"lang": "CSS", | ||
}, | ||
Object { | ||
"files": 21, | ||
"isSupported": false, | ||
"lang": "Java Properties", | ||
}, | ||
Object { | ||
"files": 6, | ||
"isSupported": false, | ||
"lang": "SVG", | ||
}, | ||
Object { | ||
"files": 78, | ||
"isSupported": true, | ||
"lang": "HTML", | ||
}, | ||
Object { | ||
"files": 45, | ||
"isSupported": false, | ||
"lang": "Less", | ||
}, | ||
Object { | ||
"files": 989, | ||
"isSupported": true, | ||
"lang": "Java", | ||
}, | ||
Object { | ||
"files": 4, | ||
"isSupported": false, | ||
"lang": "SQLPL", | ||
}, | ||
Object { | ||
"files": 8, | ||
"isSupported": false, | ||
"lang": "CSV", | ||
}, | ||
Object { | ||
"files": 1, | ||
"isSupported": false, | ||
"lang": "Batchfile", | ||
}, | ||
] | ||
`; |
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 |
---|---|---|
|
@@ -94,7 +94,7 @@ describe('Functional test of analysis', () => { | |
}); | ||
|
||
// Test DC JSON format first | ||
expect(Object.keys(bundle.analysisResults.suggestions).length).toEqual(121); | ||
expect(Object.keys(bundle.analysisResults.suggestions).length).toEqual(120); | ||
|
||
const cweSuggestion = Object.values(bundle.analysisResults.suggestions).find( | ||
s => s.id === 'java%2Fdc_interfile_project%2FPT', | ||
|
@@ -104,8 +104,8 @@ describe('Functional test of analysis', () => { | |
expect(cweSuggestion?.title).toBeTruthy(); | ||
expect(cweSuggestion?.text).toBeTruthy(); | ||
|
||
expect(bundle.sarifResults?.runs[0].results?.length).toEqual(121); | ||
expect(bundle.sarifResults?.runs[0].tool?.driver.rules?.length).toEqual(121); | ||
expect(bundle.sarifResults?.runs[0].results?.length).toEqual(236); | ||
expect(bundle.sarifResults?.runs[0].tool?.driver.rules?.length).toEqual(120); | ||
|
||
const cweRule = bundle.sarifResults?.runs[0].tool?.driver.rules?.find(r => r.id === 'java/PT'); | ||
expect(cweRule?.properties?.cwe).toContain('CWE-23'); | ||
|
@@ -160,6 +160,27 @@ describe('Functional test of analysis', () => { | |
TEST_TIMEOUT, | ||
); | ||
|
||
it( | ||
'analyze remote git and formatter sarif with supported files', | ||
async () => { | ||
const bundle = await analyzeGit({ | ||
baseURL, | ||
sessionToken, | ||
includeLint: false, | ||
severity: 1, | ||
gitUri: '[email protected]:OpenRefine/OpenRefine.git@437dc4d74110ce006b9f829fe05f461cc8ed1170', | ||
sarif: true, | ||
}); | ||
expect(bundle.sarifResults?.runs[0].properties?.coverage).toMatchSnapshot(); | ||
|
||
const numOfIssues = getNumOfIssues(bundle); | ||
const numOfIssuesInSarif = bundle.sarifResults?.runs[0].results?.length; | ||
|
||
expect(numOfIssuesInSarif).toEqual(numOfIssues); | ||
}, | ||
TEST_TIMEOUT, | ||
); | ||
|
||
it('should match sarif schema', () => { | ||
const validationResult = jsonschema.validate(sarifResults, sarifSchema); | ||
// this is to debug any errors found | ||
|
@@ -169,3 +190,14 @@ describe('Functional test of analysis', () => { | |
}); | ||
}); | ||
}); | ||
|
||
function getNumOfIssues(bundle: IGitBundle): number { | ||
let numberOfIssues = 0; | ||
|
||
Object.keys(bundle.analysisResults.files).forEach(filePath => { | ||
const curFile = bundle.analysisResults.files[filePath]; | ||
numberOfIssues += Object.keys(curFile).length; | ||
}); | ||
|
||
return numberOfIssues; | ||
} |
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