Skip to content

Commit

Permalink
Add more_info URL to screen formatter (#360)
Browse files Browse the repository at this point in the history
* Add more_info URL to screen output

Patch set adds more_info URL to the screen output.

Partially-Closes: #323

Signed-off-by: Tin Lam <tin@irrational.io>
  • Loading branch information
stannum-l authored and ericwb committed Aug 9, 2018
1 parent a9fe5e5 commit a39b408
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions bandit/formatters/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
Screen formatter
================
This formatter outputs the issues as color coded text.
This formatter outputs the issues as color coded text to screen.
:Example:
.. code-block:: none
>> Issue: [B301:blacklist_calls] Use of unsafe yaml load. Allows
>> Issue: [B506: yaml_load] Use of unsafe yaml load. Allows
instantiation of arbitrary objects. Consider yaml.safe_load().
Severity: Medium Confidence: High
Location: examples/yaml_load.py:5
More Info: https://bandit.readthedocs.io/en/latest/
4 ystr = yaml.dump({'a' : 1, 'b' : 2, 'c' : 3})
5 y = yaml.load(ystr)
6 yaml.dump(y)
Expand All @@ -44,6 +45,7 @@
import sys

from bandit.core import constants
from bandit.core import docs_utils
from bandit.core import test_properties

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -100,6 +102,9 @@ def _output_issue_str(issue, indent, show_lineno=True, show_code=True,
issue.lineno if show_lineno else "",
COLOR['DEFAULT']))

bits.append("%s More Info: %s" % (
indent, docs_utils.get_url(issue.test_id)))

if show_code:
bits.extend([indent + l for l in
issue.get_code(lines, True).split('\n')])
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/formatters/test_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import bandit
from bandit.core import config
from bandit.core import docs_utils
from bandit.core import issue
from bandit.core import manager
from bandit.formatters import screen
Expand All @@ -46,7 +47,9 @@ def _template(_issue, _indent_val, _code, _color):
_issue.confidence.capitalize()),
"{} Location: {}:{}{}".
format(_indent_val, _issue.fname, _issue.lineno,
screen.COLOR['DEFAULT'])]
screen.COLOR['DEFAULT']),
"{} More Info: {}".format(
_indent_val, docs_utils.get_url(_issue.test_id))]
if _code:
return_val.append("{}{}".format(_indent_val, _code))
return '\n'.join(return_val)
Expand Down

0 comments on commit a39b408

Please sign in to comment.