-
-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the column offset to the issue model (#618)
* Add the column offset to the issue model and expose via the custom formatter * Fix import order and update auto-help * Fetch property from dict but default to 0 for backward compatibility. Update the test as well * Update test_custom.py Co-authored-by: Eric Brown <ericwb@users.noreply.github.com>
- Loading branch information
1 parent
b59beba
commit 82db41a
Showing
8 changed files
with
66 additions
and
3 deletions.
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
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
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
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
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
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
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
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,55 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import csv | ||
import tempfile | ||
|
||
import six | ||
import testtools | ||
|
||
import bandit | ||
from bandit.core import config | ||
from bandit.core import issue | ||
from bandit.core import manager | ||
from bandit.formatters import custom | ||
|
||
|
||
class CustomFormatterTests(testtools.TestCase): | ||
|
||
def setUp(self): | ||
super(CustomFormatterTests, self).setUp() | ||
conf = config.BanditConfig() | ||
self.manager = manager.BanditManager(conf, 'custom') | ||
(tmp_fd, self.tmp_fname) = tempfile.mkstemp() | ||
self.context = {'filename': self.tmp_fname, | ||
'lineno': 4, | ||
'linerange': [4], | ||
'col_offset': 30} | ||
self.check_name = 'hardcoded_bind_all_interfaces' | ||
self.issue = issue.Issue(bandit.MEDIUM, bandit.MEDIUM, | ||
'Possible binding to all interfaces.') | ||
self.manager.out_file = self.tmp_fname | ||
|
||
self.issue.fname = self.context['filename'] | ||
self.issue.lineno = self.context['lineno'] | ||
self.issue.linerange = self.context['linerange'] | ||
self.issue.col_offset = self.context['col_offset'] | ||
self.issue.test = self.check_name | ||
|
||
self.manager.results.append(self.issue) | ||
|
||
def test_report(self): | ||
with open(self.tmp_fname, 'w') as tmp_file: | ||
custom.report( | ||
self.manager, tmp_file, self.issue.severity, | ||
self.issue.confidence, | ||
template="{line},{col},{severity},{msg}") | ||
|
||
with open(self.tmp_fname) as f: | ||
reader = csv.DictReader(f, ['line', 'col', 'severity', 'message']) | ||
data = six.next(reader) | ||
self.assertEqual(six.text_type(self.context['lineno']), | ||
data['line']) | ||
self.assertEqual(six.text_type(self.context['col_offset']), | ||
data['col']) | ||
self.assertEqual(self.issue.severity, data['severity']) | ||
self.assertEqual(self.issue.text, data['message']) |