Files
codeql/python/ql/test/experimental/dataflow/tainttracking/customSanitizer/test_reference.py
Rasmus Wriedt Larsen e5e8ec6ecc Python: Add a few test-cases for barrier guards and references
I'm not sure references is the best name, but it's the best I could come up with
jsut now
2020-12-07 15:27:20 +01:00

66 lines
1.1 KiB
Python

import sys; import os; sys.path.append(os.path.dirname(os.path.dirname((__file__))))
from taintlib import *
# This has no runtime impact, but allows autocomplete to work
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from ..taintlib import *
# Actual tests
"""Testing logical constructs not/and/or works out of the box.
"""
import random
def random_choice():
return bool(random.randint(0, 1))
def is_safe(arg):
return arg == "safe"
def test_basic():
s = TAINTED_STRING
s2 = s
if is_safe(s):
ensure_not_tainted(s, s2)
else:
ensure_tainted(s, s2)
def test_identical_call():
"""This code pattern is being used in real world code"""
s = TAINTED_STRING
if is_safe(s.strip()):
ensure_not_tainted(s.strip())
else:
ensure_tainted(s.strip())
class C(object):
def __init__(self, value):
self.foo = value
def test_class_attribute_access():
s = TAINTED_STRING
c = C(s)
if is_safe(c.foo):
ensure_not_tainted(c.foo)
else:
ensure_tainted(c.foo)
# Make tests runable
test_basic()
test_identical_call()
test_class_attribute_access()