Add more_info URL to the JSON output

Currently, outputting bandit findings as JSON does not put the ``more_info``
URL in the output as it would if the output format is HTML.  This patch
set updates the JSON formatter to include the ``more_info`` URL to be inline
with the HTML display.

Change-Id: I58a8490b427fe146d517a8aff124f4443562f48b
Closes-Bug: #1695890
Signed-off-by: Tin Lam <tin@irrational.io>
This commit is contained in:
Tin Lam 2017-12-27 23:14:17 -06:00
parent 03b390b59b
commit 185a2a8a42
3 changed files with 12 additions and 0 deletions

View File

@ -65,6 +65,7 @@ This formatter outputs the issues in JSON.
"line_range": [
5
],
"more_info": "https://docs.openstack.org/developer/bandit/",
"test_name": "blacklist_calls",
"test_id": "B301"
}
@ -84,6 +85,7 @@ import logging
import operator
import sys
from bandit.core import docs_utils
from bandit.core import test_properties
LOG = logging.getLogger(__name__)
@ -114,12 +116,15 @@ def report(manager, fileobj, sev_level, conf_level, lines=-1):
collector = []
for r in results:
d = r.as_dict()
d['more_info'] = docs_utils.get_url(d['test_id'])
if len(results[r]) > 1:
d['candidates'] = [c.as_dict() for c in results[r]]
collector.append(d)
else:
collector = [r.as_dict() for r in results]
for elem in collector:
elem['more_info'] = docs_utils.get_url(elem['test_id'])
itemgetter = operator.itemgetter
if manager.agg_type == 'vuln':

View File

@ -0,0 +1,5 @@
---
features:
- |
[bug/1695890] The ``more_info`` URL link displayed in the HTML output is
now also available in the JSON output.

View File

@ -94,3 +94,5 @@ class JsonFormatterTests(testtools.TestCase):
data['results'][0]['line_range'])
self.assertEqual(self.check_name, data['results'][0]['test_name'])
self.assertIn('candidates', data['results'][0])
self.assertIn('more_info', data['results'][0])
self.assertIsNotNone(data['results'][0]['more_info'])