Skip to content

Commit

Permalink
fix: stabilise rule id in sarif
Browse files Browse the repository at this point in the history
Remove unnecessary parts and keep the rule id as LANGUAGE/RULE
  • Loading branch information
Mila Votradovec committed Dec 17, 2020
1 parent ff6f275 commit 552389f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/sarif_converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ const getTools = (analysisResults: IAnalysisResult, suggestions: ISarifSuggestio
2: 'warning',
3: 'error',
}[suggestion.severity];

const suggestionId = suggestion.id;
// payload comes as URIencoded
const language = suggestion.id.split('%2F')[0];
const suggestionId = `${language}/${suggestion.rule}`;
const rule = {
id: suggestionId,
name: suggestion.rule,
Expand All @@ -66,7 +67,7 @@ const getTools = (analysisResults: IAnalysisResult, suggestions: ISarifSuggestio
text: '',
},
properties: {
tags: [suggestionId.split('%2F')[0], ...suggestion.tags, ...suggestion.categories],
tags: [language, ...suggestion.tags, ...suggestion.categories],
precision: 'very-high',
} as { tags: string[]; precision: string; cwe?: string[] },
};
Expand Down
2 changes: 1 addition & 1 deletion tests/git.analysis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('Functional test of analysis', () => {
expect(bundle.sarifResults?.runs[0].results?.length).toEqual(118);
expect(bundle.sarifResults?.runs[0].tool?.driver.rules?.length).toEqual(118);

const cweRule = bundle.sarifResults?.runs[0].tool?.driver.rules?.find(r => r.id === 'java%2Fdc_interfile_project%2FPT');
const cweRule = bundle.sarifResults?.runs[0].tool?.driver.rules?.find(r => r.id === 'java/PT');
expect(cweRule?.properties?.cwe).toContain('CWE-23');
expect(cweRule?.shortDescription?.text).toEqual('Path Traversal');

Expand Down

0 comments on commit 552389f

Please sign in to comment.