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
This commit is contained in:
Rasmus Wriedt Larsen
2020-11-30 15:12:05 +01:00
parent 5aa2c2f9d4
commit e5e8ec6ecc
2 changed files with 76 additions and 0 deletions

View File

@@ -34,6 +34,14 @@ test_taint
| test_logical.py:128 | ok | test_nesting_not_with_and_true | s |
| test_logical.py:137 | fail | test_with_return | s |
| test_logical.py:146 | fail | test_with_exception | s |
| test_reference.py:31 | fail | test_basic | s2 |
| test_reference.py:31 | ok | test_basic | s |
| test_reference.py:33 | ok | test_basic | s |
| test_reference.py:33 | ok | test_basic | s2 |
| test_reference.py:41 | fail | test_identical_call | s.strip() |
| test_reference.py:43 | ok | test_identical_call | s.strip() |
| test_reference.py:56 | fail | test_class_attribute_access | c.foo |
| test_reference.py:58 | ok | test_class_attribute_access | c.foo |
isSanitizer
| TestTaintTrackingConfiguration | test.py:21:39:21:39 | ControlFlowNode for s |
| TestTaintTrackingConfiguration | test.py:50:10:50:29 | ControlFlowNode for emulated_escaping() |
@@ -48,3 +56,6 @@ isSanitizerGuard
| TestTaintTrackingConfiguration | test_logical.py:115:12:115:21 | ControlFlowNode for is_safe() |
| TestTaintTrackingConfiguration | test_logical.py:120:16:120:25 | ControlFlowNode for is_safe() |
| TestTaintTrackingConfiguration | test_logical.py:125:20:125:29 | ControlFlowNode for is_safe() |
| TestTaintTrackingConfiguration | test_reference.py:30:8:30:17 | ControlFlowNode for is_safe() |
| TestTaintTrackingConfiguration | test_reference.py:40:8:40:25 | ControlFlowNode for is_safe() |
| TestTaintTrackingConfiguration | test_reference.py:55:8:55:21 | ControlFlowNode for is_safe() |

View File

@@ -0,0 +1,65 @@
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()