This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Add report functionality for detect-secrets + tests #235
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2019 VMware, Inc. | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
|
||
const pathLib = require('path') | ||
|
||
const { getAnnotationLevel } = require('../../annotations_levels') | ||
|
||
/** | ||
* @param {*} issue an issue from which the annotation will be build | ||
* @param {String} filePath file path where the issue is located | ||
* @return {Object} returns an annotation object as specified here: | ||
* https://developer.github.com/v3/checks/runs/#annotations-object | ||
*/ | ||
function getAnnotation (issue, filePath) { | ||
const path = pathLib.normalize(filePath) | ||
const startLine = issue.line_number | ||
const endLine = startLine | ||
const annotationLevel = getAnnotationLevel('HIGH', 'LOW') | ||
const title = issue.type | ||
const message = `The issue was found by the ${issue.type} plugin in detect-secrets.` | ||
|
||
return { | ||
path, | ||
start_line: startLine, | ||
end_line: endLine, | ||
annotation_level: annotationLevel, | ||
title, | ||
message | ||
} | ||
} | ||
|
||
module.exports.getAnnotation = getAnnotation |
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,29 @@ | ||
// Copyright 2019 VMware, Inc. | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
|
||
const { getAnnotation } = require('./detect_secrets_annotations') | ||
const { countIssueLevels } = require('../../annotations_levels') | ||
|
||
/** | ||
* Process detect-secrets output (generate annotations, count issue levels) | ||
* @param {*} results detect-secrets json output | ||
* @returns {{{Object[]}, Object, String}} Object[] array of annotation objects | ||
* see https://developer.github.com/v3/checks/runs/#annotations-object | ||
* Object contains the number of errors, warnings and notices found | ||
* String consists of link|links to the documentation for the issues | ||
*/ | ||
MVrachev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
module.exports = (results) => { | ||
const filesWithIssues = Object.keys(results) | ||
let annotations = [] | ||
for (let file of filesWithIssues) { | ||
for (let issue of results[file]) { | ||
annotations.push(getAnnotation(issue, file)) | ||
} | ||
} | ||
const issueCount = countIssueLevels(annotations) | ||
let moreInfo = '' | ||
if (annotations.length > 0) { | ||
moreInfo = '[detect-secrets documentation](https://github.com/Yelp/detect-secrets#currently-supported-plugins)' | ||
} | ||
return { annotations, issueCount, moreInfo } | ||
} |
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,50 @@ | ||
// Copyright 2019 VMware, Inc. | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
|
||
const generateReport = require('../linters/detect_secrets/detect_secrets_report') | ||
|
||
const detectSecretsResults = require('./fixtures/reports/detect_secrets.vulnerable') | ||
|
||
describe('TSLint report generation', () => { | ||
let report = '' | ||
|
||
beforeEach(() => { | ||
report = generateReport(detectSecretsResults.results) | ||
}) | ||
|
||
test('Creates correct report structure', () => { | ||
expect(report).toHaveProperty('annotations') | ||
expect(report).toHaveProperty('issueCount.errors') | ||
expect(report).toHaveProperty('issueCount.warnings') | ||
expect(report).toHaveProperty('issueCount.notices') | ||
expect(report).toHaveProperty('moreInfo') | ||
}) | ||
|
||
test('Creates correct annotations', () => { | ||
expect(report.annotations).toHaveLength(4) | ||
expect(report.annotations[0].end_line).toBe(13) | ||
expect(report.annotations[1].start_line).toBe(68) | ||
expect(report.annotations[2].title).toEqual('Basic Auth Credentials') | ||
expect(report.annotations[3].path).toBe('test.yaml') | ||
|
||
report.annotations.forEach(annotation => { | ||
expect(annotation.annotation_level).toMatch(/notice|warning|failure/) | ||
expect(annotation.message).not.toBe('') | ||
}) | ||
}) | ||
|
||
test('Creates correct issue count', () => { | ||
expect(report.issueCount.errors).toBe(4) | ||
expect(report.issueCount.warnings).toBe(0) | ||
expect(report.issueCount.notices).toBe(0) | ||
}) | ||
|
||
test('Handles no vulnerable reports', () => { | ||
const report = generateReport([], '') | ||
|
||
expect(report.annotations).toHaveLength(0) | ||
expect(report.issueCount.errors).toBe(0) | ||
expect(report.issueCount.warnings).toBe(0) | ||
expect(report.issueCount.notices).toBe(0) | ||
}) | ||
}) |
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,59 @@ | ||
{ | ||
"exclude": { | ||
"files": null, | ||
"lines": null | ||
}, | ||
"generated_at": "2019-05-15T17:24:04Z", | ||
"plugins_used": [ | ||
{ | ||
"name": "AWSKeyDetector" | ||
}, | ||
{ | ||
"base64_limit": 4.5, | ||
"name": "Base64HighEntropyString" | ||
}, | ||
{ | ||
"name": "BasicAuthDetector" | ||
}, | ||
{ | ||
"hex_limit": 3, | ||
"name": "HexHighEntropyString" | ||
}, | ||
{ | ||
"name": "KeywordDetector" | ||
}, | ||
{ | ||
"name": "PrivateKeyDetector" | ||
}, | ||
{ | ||
"name": "SlackDetector" | ||
} | ||
], | ||
"results": { | ||
"test.js": [ | ||
{ | ||
"hashed_secret": "edbd2994e5980ce68a498791abc1fb9c40f6bb43", | ||
"line_number": 13, | ||
"type": "Secret Keyword" | ||
}, | ||
{ | ||
"hashed_secret": "daefe0b4345a654580dcad25c7c11ff4c944a8c0", | ||
"line_number": 68, | ||
"type": "Private Key" | ||
}, | ||
{ | ||
"hashed_secret": "99b5e14eaf6b7cd863796dab48ae736be2ac6b53", | ||
"line_number": 77, | ||
"type": "Basic Auth Credentials" | ||
} | ||
], | ||
"test.yaml": [ | ||
{ | ||
"hashed_secret": "66e02bb499b2a3f5f2894ce1b7959962c1a5a245", | ||
"line_number": 5, | ||
"type": "Base64 High Entropy String" | ||
} | ||
] | ||
}, | ||
"version": "0.12.2" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the severity always be high and confidence always low for these results?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's something we should discuss in our issue tracker
#209
I just put the severity and confidence Bandit uses when reporting hardcoded credentials.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to look at https://github.com/lyft/bandit-high-entropy-string. This is a bandit plugin to do detect-secrets like testing. As part of the plugin, it defines severity and confidence.