Skip to content

Commit 1394b38

Browse files
committed
Python: Improve customSanitizer tests
Before we didn't show how we treated the value _after_ the check. But we do actually handle this nicely 💪
1 parent 8df04c5 commit 1394b38

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

python/ql/test/experimental/dataflow/tainttracking/customSanitizer/InlineTaintTest.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ untaintedArgumentToEnsureTaintedNotMarkedAsMissing
33
failures
44
isSanitizer
55
| TestTaintTrackingConfiguration | test.py:21:39:21:39 | ControlFlowNode for s |
6-
| TestTaintTrackingConfiguration | test.py:50:10:50:29 | ControlFlowNode for emulated_escaping() |
6+
| TestTaintTrackingConfiguration | test.py:53:10:53:29 | ControlFlowNode for emulated_escaping() |
77
isSanitizerGuard
8-
| TestTaintTrackingConfiguration | test.py:35:8:35:26 | ControlFlowNode for emulated_is_safe() |
8+
| TestTaintTrackingConfiguration | test.py:38:8:38:26 | ControlFlowNode for emulated_is_safe() |
99
| TestTaintTrackingConfiguration | test_logical.py:29:8:29:17 | ControlFlowNode for is_safe() |
1010
| TestTaintTrackingConfiguration | test_logical.py:44:8:44:17 | ControlFlowNode for is_safe() |
1111
| TestTaintTrackingConfiguration | test_logical.py:52:12:52:21 | ControlFlowNode for is_safe() |

python/ql/test/experimental/dataflow/tainttracking/customSanitizer/test.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ def emulated_authentication_check(arg):
1414
raise Exception("user unauthenticated")
1515

1616

17-
def test_custom_sanitizer():
17+
def test_custom_sanitizer_exception():
1818
s = TAINTED_STRING
1919

2020
try:
2121
emulated_authentication_check(s)
2222
ensure_not_tainted(s)
2323
except:
24-
pass
24+
ensure_tainted(s) # $ tainted
25+
raise
26+
27+
ensure_not_tainted(s)
2528

2629

2730
def emulated_is_safe(arg):
@@ -34,11 +37,11 @@ def test_custom_sanitizer_guard():
3437

3538
if emulated_is_safe(s):
3639
ensure_not_tainted(s)
37-
s = TAINTED_STRING
38-
ensure_tainted(s) # $ tainted
3940
else:
4041
ensure_tainted(s) # $ tainted
4142

43+
ensure_tainted(s) # $ tainted
44+
4245

4346
def emulated_escaping(arg):
4447
return arg.replace("<", "?").replace(">", "?").replace("'", "?").replace("\"", "?")
@@ -53,6 +56,9 @@ def test_escape():
5356

5457
# Make tests runable
5558

56-
test_custom_sanitizer()
59+
try:
60+
test_custom_sanitizer_exception()
61+
except Exception:
62+
pass
5763
test_custom_sanitizer_guard()
5864
test_escape()

0 commit comments

Comments
 (0)