Skip to content

Commit

Permalink
Fixups for pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed Mar 1, 2022
1 parent 956b3a0 commit 229aa95
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
10 changes: 5 additions & 5 deletions bandit/core/node_visitor.py
Expand Up @@ -299,10 +299,10 @@ def process(self, data):
# Run tests that do not require access to the AST,
# but only to the whole file source:
self.context = {
'filename': self.fname,
'lineno': 0,
'linerange': [0, 1],
'col_offset': 0,
"filename": self.fname,
"lineno": 0,
"linerange": [0, 1],
"col_offset": 0,
}
self.update_scores(self.tester.run_tests(self.context, 'File'))
self.update_scores(self.tester.run_tests(self.context, "File"))
return self.scores
29 changes: 19 additions & 10 deletions bandit/plugins/trojansource.py
@@ -1,7 +1,5 @@
# -*- coding:utf-8 -*-
#
# SPDX-License-Identifier: Apache-2.0

r"""
=====================================================
B113: TrojanSource - Bidirectional control characters
Expand All @@ -27,21 +25,30 @@
.. versionadded:: 1.7.2
""" # noqa: E501

from tokenize import detect_encoding

import bandit
from bandit.core import test_properties as test


BIDI_CHARACTERS = ('\u202A', '\u202B', '\u202C', '\u202D', '\u202E',
'\u2066', '\u2067', '\u2068', '\u2069', '\u200F')
BIDI_CHARACTERS = (
"\u202A",
"\u202B",
"\u202C",
"\u202D",
"\u202E",
"\u2066",
"\u2067",
"\u2068",
"\u2069",
"\u200F",
)


@test.test_id('B113')
@test.checks('File')
@test.test_id("B113")
@test.checks("File")
def trojansource(context):
with open(context.filename, 'rb') as src_file:
with open(context.filename, "rb") as src_file:
encoding, _ = detect_encoding(src_file.readline)
with open(context.filename, encoding=encoding) as src_file:
for lineno, line in enumerate(src_file.readlines(), start=1):
Expand All @@ -50,8 +57,10 @@ def trojansource(context):
col_offset = line.index(char) + 1
except ValueError:
continue
text = ("A Python source file contains bidirectional"
" control characters (%r)." % char)
text = (
"A Python source file contains bidirectional"
" control characters (%r)." % char
)
return bandit.Issue(
severity=bandit.HIGH,
confidence=bandit.MEDIUM,
Expand Down
12 changes: 6 additions & 6 deletions tests/functional/test_functional.py
Expand Up @@ -891,14 +891,14 @@ def test_snmp_security_check(self):

def test_trojansource(self):
expect = {
'SEVERITY': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 0, 'HIGH': 1},
'CONFIDENCE': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 1, 'HIGH': 0}
"SEVERITY": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 1},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 1, "HIGH": 0},
}
self.check_example('trojansource.py', expect)
self.check_example("trojansource.py", expect)

def test_trojansource_latin1(self):
expect = {
'SEVERITY': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 0, 'HIGH': 0},
'CONFIDENCE': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 0, 'HIGH': 0}
"SEVERITY": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 0},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 0},
}
self.check_example('trojansource_latin1.py', expect)
self.check_example("trojansource_latin1.py", expect)

0 comments on commit 229aa95

Please sign in to comment.