mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
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:
@@ -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() |
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user