Fix tests and severity display
This commit is contained in:
parent
a27c13bb58
commit
b44ed7cc7f
@ -847,6 +847,61 @@ var res = string.Format("{0} {1}", array); // Compliant we don't know the size o
|
||||
</span>
|
||||
,
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"code"
|
||||
</span>
|
||||
: {
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"impacts"
|
||||
</span>
|
||||
: {
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"MAINTAINABILITY"
|
||||
</span>
|
||||
:
|
||||
<span
|
||||
class="hljs-string"
|
||||
>
|
||||
"MEDIUM"
|
||||
</span>
|
||||
|
||||
},
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"attribute"
|
||||
</span>
|
||||
:
|
||||
<span
|
||||
class="hljs-string"
|
||||
>
|
||||
"CLEAR"
|
||||
</span>
|
||||
|
||||
},
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"severity"
|
||||
</span>
|
||||
:
|
||||
<span
|
||||
class="hljs-string"
|
||||
>
|
||||
"MEDIUM"
|
||||
</span>
|
||||
,
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
@ -939,19 +994,6 @@ var res = string.Format("{0} {1}", array); // Compliant we don't know the size o
|
||||
</span>
|
||||
,
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"defaultSeverity"
|
||||
</span>
|
||||
:
|
||||
<span
|
||||
class="hljs-string"
|
||||
>
|
||||
"Major"
|
||||
</span>
|
||||
,
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
@ -1887,6 +1929,48 @@ exports[`renders cfamily version of S1000 1`] = `
|
||||
</span>
|
||||
,
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"code"
|
||||
</span>
|
||||
: {
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"impacts"
|
||||
</span>
|
||||
: {
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"MAINTAINABILITY"
|
||||
</span>
|
||||
:
|
||||
<span
|
||||
class="hljs-string"
|
||||
>
|
||||
"MEDIUM"
|
||||
</span>
|
||||
|
||||
},
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"attribute"
|
||||
</span>
|
||||
:
|
||||
<span
|
||||
class="hljs-string"
|
||||
>
|
||||
"CLEAR"
|
||||
</span>
|
||||
|
||||
},
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
@ -1987,19 +2071,6 @@ exports[`renders cfamily version of S1000 1`] = `
|
||||
: []
|
||||
},
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"defaultSeverity"
|
||||
</span>
|
||||
:
|
||||
<span
|
||||
class="hljs-string"
|
||||
>
|
||||
"Major"
|
||||
</span>
|
||||
,
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
@ -2026,6 +2097,19 @@ exports[`renders cfamily version of S1000 1`] = `
|
||||
</span>
|
||||
,
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"severity"
|
||||
</span>
|
||||
:
|
||||
<span
|
||||
class="hljs-string"
|
||||
>
|
||||
"MEDIUM"
|
||||
</span>
|
||||
,
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
@ -3561,6 +3645,61 @@ var res = string.Format("{0} {1}", array); // Compliant we don't know the size o
|
||||
</span>
|
||||
,
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"code"
|
||||
</span>
|
||||
: {
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"impacts"
|
||||
</span>
|
||||
: {
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"MAINTAINABILITY"
|
||||
</span>
|
||||
:
|
||||
<span
|
||||
class="hljs-string"
|
||||
>
|
||||
"MEDIUM"
|
||||
</span>
|
||||
|
||||
},
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"attribute"
|
||||
</span>
|
||||
:
|
||||
<span
|
||||
class="hljs-string"
|
||||
>
|
||||
"CLEAR"
|
||||
</span>
|
||||
|
||||
},
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"severity"
|
||||
</span>
|
||||
:
|
||||
<span
|
||||
class="hljs-string"
|
||||
>
|
||||
"MEDIUM"
|
||||
</span>
|
||||
,
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
@ -3653,19 +3792,6 @@ var res = string.Format("{0} {1}", array); // Compliant we don't know the size o
|
||||
</span>
|
||||
,
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
"defaultSeverity"
|
||||
</span>
|
||||
:
|
||||
<span
|
||||
class="hljs-string"
|
||||
>
|
||||
"Major"
|
||||
</span>
|
||||
,
|
||||
|
||||
<span
|
||||
class="hljs-attr"
|
||||
>
|
||||
|
@ -3,6 +3,12 @@
|
||||
"type": "CODE_SMELL",
|
||||
"status": "ready",
|
||||
"quickfix": "unknown",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "CLEAR"
|
||||
},
|
||||
"remediation": {
|
||||
"func": "Constant/Issue",
|
||||
"constantCost": "1h"
|
||||
@ -21,6 +27,7 @@
|
||||
},
|
||||
"ruleSpecification": "RSPEC-1000",
|
||||
"sqKey": "UnnamedNamespaceInHeader",
|
||||
"severity": "MEDIUM",
|
||||
"scope": "Main",
|
||||
"securityStandards": {
|
||||
"CERT": [
|
||||
|
@ -6,6 +6,12 @@
|
||||
"func": "Constant/Issue",
|
||||
"constantCost": "1h"
|
||||
},
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "CLEAR"
|
||||
},
|
||||
"tags": [
|
||||
"cert",
|
||||
"misra-c++2008",
|
||||
@ -20,6 +26,7 @@
|
||||
},
|
||||
"ruleSpecification": "RSPEC-1000",
|
||||
"sqKey": "UnnamedNamespaceInHeader",
|
||||
"severity": "MEDIUM",
|
||||
"scope": "Main",
|
||||
"securityStandards": {
|
||||
"CERT": [
|
||||
|
@ -2,6 +2,12 @@
|
||||
"title": "Printf-style format strings should be used correctly",
|
||||
"type": "CODE_SMELL",
|
||||
"status": "ready",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "CLEAR"
|
||||
},
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "10min"
|
||||
@ -31,6 +37,7 @@
|
||||
"FIO47-C."
|
||||
]
|
||||
},
|
||||
"severity": "MEDIUM",
|
||||
"languagesSupport": [
|
||||
{
|
||||
"name": "cfamily",
|
||||
|
@ -2,6 +2,13 @@
|
||||
"title": "Composite format strings should be used correctly",
|
||||
"type": "CODE_SMELL",
|
||||
"status": "ready",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "CLEAR"
|
||||
},
|
||||
"severity": "MEDIUM",
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "10min"
|
||||
|
@ -2,6 +2,13 @@
|
||||
"title": "Printf-style format strings should be used correctly",
|
||||
"type": "CODE_SMELL",
|
||||
"status": "ready",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "CLEAR"
|
||||
},
|
||||
"severity": "MEDIUM",
|
||||
"remediation": {
|
||||
"func": "Constant/Issue",
|
||||
"constantCost": "10min"
|
||||
|
@ -26,7 +26,15 @@
|
||||
"CERT": [
|
||||
"FIO47-C."
|
||||
]
|
||||
}, "ruleSpecification": "RSPEC-3457",
|
||||
},
|
||||
"code": {
|
||||
"attribute": "CLEAR",
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
}
|
||||
},
|
||||
"severity": "MEDIUM",
|
||||
"ruleSpecification": "RSPEC-3457",
|
||||
"sqKey": "S3457",
|
||||
"scope": "All",
|
||||
"languagesSupport": [
|
||||
|
@ -12,6 +12,13 @@
|
||||
"allKeys": [
|
||||
"S3457"
|
||||
],
|
||||
"code": {
|
||||
"attribute": "CLEAR",
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
}
|
||||
},
|
||||
"severity": "MEDIUM",
|
||||
"ruleSpecification": "RSPEC-3457",
|
||||
"sqKey": "S3457",
|
||||
"scope": "All",
|
||||
|
@ -2,6 +2,13 @@
|
||||
"title": "Database queries should not be vulnerable to injection attacks",
|
||||
"type": "VULNERABILITY",
|
||||
"status": "ready",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "CLEAR"
|
||||
},
|
||||
"severity": "MEDIUM",
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "30min"
|
||||
|
@ -2,6 +2,13 @@
|
||||
"title": "Database queries should not be vulnerable to injection attacks",
|
||||
"type": "VULNERABILITY",
|
||||
"status": "ready",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "CLEAR"
|
||||
},
|
||||
"severity": "MEDIUM",
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "30min"
|
||||
|
@ -2,6 +2,13 @@
|
||||
"title": "\"<signal.h>\" should not be used",
|
||||
"type": "BUG",
|
||||
"status": "ready",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "CLEAR"
|
||||
},
|
||||
"severity": "MEDIUM",
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "4h"
|
||||
|
@ -2,6 +2,13 @@
|
||||
"title": "\"<signal.h>\" should not be used",
|
||||
"type": "BUG",
|
||||
"status": "ready",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "CLEAR"
|
||||
},
|
||||
"severity": "MEDIUM",
|
||||
"remediation": {
|
||||
"func": "Constant/Issue",
|
||||
"constantCost": "4h"
|
||||
|
@ -2,6 +2,12 @@
|
||||
"title": "Header files should not contain unnamed namespaces",
|
||||
"type": "CODE_SMELL",
|
||||
"status": "ready",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "CLEAR"
|
||||
},
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "1h"
|
||||
|
@ -2,6 +2,12 @@
|
||||
"title": "Composite format strings should be used correctly",
|
||||
"type": "CODE_SMELL",
|
||||
"status": "ready",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "CLEAR"
|
||||
},
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "10min"
|
||||
|
@ -2,6 +2,12 @@
|
||||
"title": "Database queries should not be vulnerable to injection attacks",
|
||||
"type": "VULNERABILITY",
|
||||
"status": "ready",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "CLEAR"
|
||||
},
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "30min"
|
||||
|
@ -6,6 +6,12 @@
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "4h"
|
||||
},
|
||||
"code": {
|
||||
"attribute": "CLEAR",
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"based-on-misra",
|
||||
"lock-in"
|
||||
|
@ -26,7 +26,7 @@ describe('index store generation', () => {
|
||||
{ "name": "python", "status": "deprecated", }
|
||||
],
|
||||
tags: ['cert', 'clumsy', 'confusing'],
|
||||
severities: ['Major', 'Minor'],
|
||||
severities: ['MEDIUM'],
|
||||
qualityProfiles: ['Sonar way'],
|
||||
});
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { maxSeverity } from '../types/Severities';
|
||||
import { Severity, maxSeverity } from '../types/Severities';
|
||||
import { LanguageSupport } from '../types/RuleMetadata';
|
||||
import { getRulesDirectories, listSupportedLanguages } from './utils';
|
||||
|
||||
@ -138,7 +138,7 @@ function getRuleMetadata(srcDir: string, language?: string) {
|
||||
const genericJson = fs.existsSync(genericFile) ? JSON.parse(fs.readFileSync(genericFile, 'utf8')) : {};
|
||||
const merged = { ...genericJson, ...languageSpecificJson };
|
||||
if (merged.hasOwnProperty('code') && merged.code.hasOwnProperty('impacts')) {
|
||||
merged['severity'] = maxSeverity(merged.code.impacts);
|
||||
merged['severity'] = Severity[maxSeverity(merged.code.impacts)];
|
||||
}
|
||||
return merged;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import path from 'path';
|
||||
import { stripHtml } from 'string-strip-html';
|
||||
import lunr, { Token } from 'lunr';
|
||||
|
||||
import { Severity, maxSeverity } from '../types/Severities';
|
||||
import { Severity, compareSeverities, maxSeverity } from '../types/Severities';
|
||||
import { IndexedRule, IndexStore, Type, IndexAggregates } from '../types/IndexStore';
|
||||
import { logger as rootLogger } from './deploymentLogger';
|
||||
import { LanguageSupport } from '../types/RuleMetadata';
|
||||
@ -22,7 +22,7 @@ export interface IndexedRuleWithDescription extends IndexedRule {
|
||||
function buildOneRuleRecord(allLanguages: string[], rulesPath: string, ruleDir: string) {
|
||||
|
||||
const types = new Set<Type>();
|
||||
const severities = new Set<Severity>();
|
||||
const severities = new Set<string>();
|
||||
const allKeys = new Set<string>([ruleDir]);
|
||||
const titles = new Set<string>();
|
||||
const tags = new Set<string>();
|
||||
@ -54,9 +54,9 @@ function buildOneRuleRecord(allLanguages: string[], rulesPath: string, ruleDir:
|
||||
titles.add(metadata.title);
|
||||
types.add(metadata.type);
|
||||
if (!metadata.hasOwnProperty('code')) {
|
||||
severities.add(Severity.INFO);
|
||||
severities.add(Severity[Severity.INFO]);
|
||||
} else {
|
||||
severities.add(maxSeverity(metadata.code.impacts));
|
||||
severities.add(Severity[maxSeverity(metadata.code.impacts)]);
|
||||
}
|
||||
supportedLanguages.push({ name: lang, status: metadata.status });
|
||||
if (metadata.tags) {
|
||||
@ -110,7 +110,7 @@ function buildOneRuleIndexedRecord(rulesPath: string, ruleDir: string)
|
||||
id: ruleDir,
|
||||
supportedLanguages: Array.from(record.supportedLanguages).sort((a, b) => a.name.localeCompare(b.name)),
|
||||
types: Array.from(record.types).sort((a, b) => a.localeCompare(b)),
|
||||
severities: Array.from(record.severities).sort((a, b) => b - a),
|
||||
severities: Array.from(record.severities).sort((a, b) => compareSeverities(b, a)),
|
||||
all_keys: Array.from(record.allKeys).sort((a, b) => a.localeCompare(b)),
|
||||
titles: Array.from(record.titles).sort((a, b) => a.localeCompare(b)),
|
||||
tags: Array.from(record.tags).sort((a, b) => a.localeCompare(b)),
|
||||
|
@ -7,7 +7,7 @@ export interface IndexedRule {
|
||||
supportedLanguages: LanguageSupport[];
|
||||
// FIXME: type, defaultSeverity should never be null but the index generation has a bug
|
||||
types: Type[];
|
||||
severities: Severity[];
|
||||
severities: string[];
|
||||
all_keys: string[];
|
||||
titles: string[];
|
||||
tags: string[];
|
||||
|
@ -17,4 +17,10 @@ export function maxSeverity(impacts: any): Severity {
|
||||
}
|
||||
}
|
||||
return maxSeverity;
|
||||
}
|
||||
|
||||
export function compareSeverities(a: string, b:string): number {
|
||||
const seva: Severity = Severity[a as keyof typeof Severity];
|
||||
const sevb: Severity = Severity[b as keyof typeof Severity];
|
||||
return seva - sevb;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user