Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
linter = get_bad_module_attribute_use_implementation({
'm1.m2.m3.m4': ['bad_attribute'],
'm2.m3.m4': ['bad_attribute'],
'm3.m4': ['bad_attribute'],
'm4': ['bad_attribute'],
})
linter.visit(python_node)
result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=7,
col_offset=0,
message=linter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=8,
col_offset=0,
message=linter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=9,
col_offset=0,
message=linter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=10,
col_offset=0,
message=linter._error_tmpl
)
]
def test_bad_attribute_usage(self):
python_node = self.get_ast_node(
"""
import random
var = random.random()
"""
)
linter = dlint.linters.BadRandomGeneratorUseLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=4,
col_offset=6,
message=dlint.linters.BadRandomGeneratorUseLinter._error_tmpl
)
]
assert result == expected
python_node = self.get_ast_node(
"""
from twisted.internet.defer import inlineCallbacks
@inlineCallbacks
def func(arg):
return arg
"""
)
linter = dlint.linters.YieldReturnStatementLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [] if IS_PYTHON_3_3 else [
dlint.linters.base.Flake8Result(
lineno=6,
col_offset=4,
message=dlint.linters.YieldReturnStatementLinter._error_tmpl
)
]
assert result == expected
def test_bad_compile_usage(self):
python_node = self.get_ast_node(
"""
var = 1
result = compile('var + 1', '', 'eval')
"""
)
linter = dlint.linters.BadCompileUseLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=4,
col_offset=9,
message=dlint.linters.BadCompileUseLinter._error_tmpl
)
]
assert result == expected
python_node = self.get_ast_node(
"""
import foo
var = 'echo "TEST"'
foo.bar(var)
"""
)
linter = get_bad_module_attribute_use_implementation({'foo': ['bar']})
linter.visit(python_node)
result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=6,
col_offset=0,
message=linter._error_tmpl
)
]
assert result == expected
OneLogin_Saml2_Utils.validate_node_sign()
OneLogin_Saml2_Utils.validate_node_sign(fingerprintalg="sha1")
OneLogin_Saml2_Utils.validate_node_sign(fingerprintalg="sha256", validatecert=False)
OneLogin_Saml2_Utils.validate_binary_sign()
OneLogin_Saml2_Utils.validate_binary_sign(algorithm=OneLogin_Saml2_Constants.RSA_SHA1)
OneLogin_Saml2_Utils.validate_binary_sign(algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1")
"""
)
linter = dlint.linters.BadOneLoginKwargUseLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=5,
col_offset=0,
message=dlint.linters.BadOneLoginKwargUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=6,
col_offset=0,
message=dlint.linters.BadOneLoginKwargUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=8,
col_offset=0,
message=dlint.linters.BadOneLoginKwargUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=9,
def test_bad_exec_usage(self):
python_node = self.get_ast_node(
"""
var = 1
exec('print var + 1')
"""
)
linter = dlint.linters.BadExecUseLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=4,
col_offset=0,
message=dlint.linters.BadExecUseLinter._error_tmpl
)
]
assert result == expected
from ssl import CERT_NONE
urllib3.PoolManager(cert_reqs="CERT_NONE")
urllib3.ProxyManager(cert_reqs="CERT_NONE")
urllib3.HTTPSConnectionPool(cert_reqs="NONE")
urllib3.connection_from_url(cert_reqs=ssl.CERT_NONE)
urllib3.proxy_from_url(cert_reqs=CERT_NONE)
"""
)
linter = dlint.linters.BadUrllib3KwargUseLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=6,
col_offset=0,
message=dlint.linters.BadUrllib3KwargUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=7,
col_offset=0,
message=dlint.linters.BadUrllib3KwargUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=8,
col_offset=0,
message=dlint.linters.BadUrllib3KwargUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=9,
"""
from twisted.internet import defer
def func(arg):
if arg:
arg += 5
@defer.inlineCallbacks
def inner_func():
defer.returnValue('foo')
defer.returnValue('qux')
"""
)
linter = dlint.linters.ReturnValueInInlineCallbacksLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=4,
col_offset=0,
message=dlint.linters.ReturnValueInInlineCallbacksLinter._error_tmpl
)
]
assert result == expected
linter = dlint.linters.BadRequestsUseLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=4,
col_offset=0,
message=dlint.linters.BadRequestsUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=5,
col_offset=0,
message=dlint.linters.BadRequestsUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=6,
col_offset=0,
message=dlint.linters.BadRequestsUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=7,
col_offset=0,
message=dlint.linters.BadRequestsUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=8,
col_offset=0,
message=dlint.linters.BadRequestsUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=9,