Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Fix some bug risks and code quality issues #312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version = 1

test_patterns = [
'tests/**'
]

exclude_patterns = [
'docs/**',
'lambda/**'
]

[[analyzers]]
name = 'python'
enabled = true
runtime_version = '3.x.x'

[analyzers.meta]
max_line_length = 100
skip_doc_coverage = ["module", "magic", "class"]
2 changes: 1 addition & 1 deletion gatherers/censys.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def gather(self):

# Construct the query.
query = query_for(self.suffixes)
logging.debug("Censys query:\n%s\n" % query)
logging.debug("Censys query:\n%s\n", query)

# Plan to store in cache/censys/export.csv.
download_path = utils.cache_path(
Expand Down
4 changes: 3 additions & 1 deletion gatherers/gathererabc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

class Gatherer(metaclass=ABCMeta):

def __init__(self, suffixes: List[str], options: dict, extra: dict={}):
def __init__(self, suffixes: List[str], options: dict, extra: dict = None):
if extra is None:
extra = {}
self.suffixes = suffixes
self.options = options
self.extra = extra
Expand Down
2 changes: 1 addition & 1 deletion gatherers/rdns.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def gather(self):
exit(1)

with open(path) as lines:
logging.debug("\tReading %s..." % path)
logging.debug("\tReading %s...", path)

for record in process_lines(lines, ip_filter, number_filter):
yield record
Expand Down
4 changes: 2 additions & 2 deletions scanners/sslyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def analyze_protocols_and_ciphers(data, sslv2, sslv3, tlsv1, tlsv1_1, tlsv1_2, t
)
data['ciphers'] = [cipher.name for cipher in accepted_ciphers]

if len(accepted_ciphers) > 0:
if accepted_ciphers:
# Look at accepted cipher suites for RC4 or DHE.
# This is imperfect, as the advertising of RC4 could discriminate based on client.
# DHE and ECDHE may not remain the only forward secret options for TLS.
Expand Down Expand Up @@ -526,7 +526,7 @@ def analyze_certs(certs):
if oid in apple_ev:
browsers.append("Apple")

if len(browsers) > 0:
if browsers:
data['certs']['ev']['trusted'] = True

# Log each new OID we observe as marked for EV.
Expand Down
13 changes: 9 additions & 4 deletions utils/scan_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ def format_last_exception():


# Command Line Conveniences #
def scan(command: List[str], env: dict=None,
allowed_return_codes: list=[]) -> Union[str, None]:
def scan(command: List[str], env: dict = None,
allowed_return_codes: list = None) -> Union[str, None]:
if allowed_return_codes is None:
allowed_return_codes = []
try:
response = subprocess.check_output(
command,
Expand Down Expand Up @@ -180,7 +182,7 @@ def configure_logging(options: Union[dict, None]=None) -> None:
# This loads the whole thing into memory: it's not a great solution for
# super-large lists of domains.
def sort_csv(input_filename):
logging.warning("Sorting %s..." % input_filename)
logging.warning("Sorting %s...", input_filename)

input_file = open(input_filename, encoding='utf-8', newline='')
tmp_filename = "%s.tmp" % input_filename
Expand Down Expand Up @@ -221,7 +223,10 @@ def sort_csv(input_filename):
shutil.move(tmp_filename, input_filename)


def write_rows(rows, domain, base_domain, scanner, csv_writer, meta={}):
def write_rows(rows, domain, base_domain, scanner, csv_writer, meta=None):

if meta is None:
meta = {}

# If we didn't get any info, we'll still output information about why the scan failed.
if rows is None:
Expand Down
4 changes: 3 additions & 1 deletion utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,9 @@ def try_command(command):
return False


def scan(command, env=None, allowed_return_codes=[]):
def scan(command, env=None, allowed_return_codes=None):
if allowed_return_codes is None:
allowed_return_codes = []
try:
response = subprocess.check_output(
command,
Expand Down