Skip to content

Commit

Permalink
feat: add fingerprintings for Sarif output
Browse files Browse the repository at this point in the history
  • Loading branch information
orkamara committed Feb 9, 2021
1 parent 1f2a273 commit 6cb9222
Show file tree
Hide file tree
Showing 5 changed files with 1,711 additions and 39 deletions.
28 changes: 21 additions & 7 deletions src/sarif_converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ import { Log, ReportingConfiguration, ReportingDescriptor, Result } from 'sarif'

import { IAnalysisResult, IFileSuggestion } from './interfaces/analysis-result.interface';

interface Fingerprint extends IFileSuggestion {
version: number;
fingerprint: string;
}

interface ISarifSuggestion extends IFileSuggestion {
id: string;
ruleIndex: number;
rule: ReportingDescriptor;
level: ReportingConfiguration.level;
text: string;
file: string;
fingerprints: Fingerprint[];
}

interface ISarifSuggestions {
[suggestionIndex: number]: ISarifSuggestion;
}
Expand Down Expand Up @@ -98,12 +105,12 @@ const getTools = (analysisResults: IAnalysisResult, suggestions: ISarifSuggestio
return { tool: { driver: { ...output.driver, rules } }, suggestions: result };
};

const getResults = (suggestions: ISarifSuggestions) => {
function getResults(suggestions: ISarifSuggestions): Result[] {
const output = [];

for (const [, suggestion] of <[string, ISarifSuggestion][]>Object.entries(suggestions)) {
let helpers: any[] = [];
let result = {
let result: Result = {
ruleId: suggestion.id,
ruleIndex: suggestion.ruleIndex,
level: suggestion.level ? suggestion.level : 'none',
Expand All @@ -127,9 +134,15 @@ const getResults = (suggestions: ISarifSuggestions) => {
},
},
},
],
]
};

if (suggestion.fingerprints) {
result.fingerprints = {};
suggestion.fingerprints.forEach(fingerprinting => {
(result.fingerprints as any)[fingerprinting.version] = fingerprinting.fingerprint;
});
}
const codeThreadFlows = [];
let i = 0;
if (suggestion.markers && suggestion.markers.length >= 1) {
Expand Down Expand Up @@ -169,7 +182,6 @@ const getResults = (suggestions: ISarifSuggestions) => {
artifactLocation: {
uri: suggestion.file,
uriBaseId: '%SRCROOT%',
// index: i,
},
region: {
startLine: suggestion.rows[0],
Expand All @@ -182,9 +194,11 @@ const getResults = (suggestions: ISarifSuggestions) => {
});
}

const { message, argumentArray } = getArgumentsAndMessage(helpers, result.message.text);
result.message.text = message;
result.message.arguments = argumentArray;
if (result.message.text) {
const { message, argumentArray } = getArgumentsAndMessage(helpers, result.message.text);
result.message.text = message;
result.message.arguments = argumentArray;
}

const newResult = {
...result,
Expand Down
12 changes: 12 additions & 0 deletions tests/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ describe('Requests to public API', () => {
cols: [8, 27],
markers: [],
rows: [5, 5],
fingerprints: [
{
fingerprint: "f8e3391465a47f6586489cffd1f44ae47a1c4885c722de596d6eb931fe43bb16",
version: 0,
},
]
},
],
'3': [
Expand Down Expand Up @@ -417,6 +423,12 @@ describe('Requests to public API', () => {
},
],
rows: [10, 10],
fingerprints: [
{
fingerprint: "3e40a81739245db8fff4903a7e28e08bffa03486a677e7c91594cfdf15fb5a1d",
version: 0,
},
]
},
],
});
Expand Down

0 comments on commit 6cb9222

Please sign in to comment.