From 8488039fb9dc8de56a60b56e56b672a540f67963 Mon Sep 17 00:00:00 2001 From: yoff Date: Sun, 8 Feb 2026 09:32:23 +0100 Subject: [PATCH] python: add tests for guards compared to booleans --- .../customSanitizer/test_logical.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/python/ql/test/library-tests/dataflow/tainttracking/customSanitizer/test_logical.py b/python/ql/test/library-tests/dataflow/tainttracking/customSanitizer/test_logical.py index 26e69b8fc05..99b5eafad41 100644 --- a/python/ql/test/library-tests/dataflow/tainttracking/customSanitizer/test_logical.py +++ b/python/ql/test/library-tests/dataflow/tainttracking/customSanitizer/test_logical.py @@ -192,6 +192,49 @@ def test_with_exception_neg(): ensure_not_tainted(s) +def test_comparison_with_bool(): + s = TAINTED_STRING + + if is_safe(s) == True: + ensure_not_tainted(s) # $ SPURIOUS: tainted + else: + ensure_tainted(s) # $ tainted + + if is_safe(s) == False: + ensure_tainted(s) # $ tainted + else: + ensure_not_tainted(s) # $ SPURIOUS: tainted + + if is_safe(s) != True: + ensure_tainted(s) # $ tainted + else: + ensure_not_tainted(s) # $ SPURIOUS: tainted + + if is_safe(s) != False: + ensure_not_tainted(s) # $ SPURIOUS: tainted + else: + ensure_tainted(s) # $ tainted + + if is_safe(s) is True: + ensure_not_tainted(s) # $ SPURIOUS: tainted + else: + ensure_tainted(s) # $ tainted + + if is_safe(s) is False: + ensure_tainted(s) # $ tainted + else: + ensure_not_tainted(s) # $ SPURIOUS: tainted + + if is_safe(s) is not True: + ensure_tainted(s) # $ tainted + else: + ensure_not_tainted(s) # $ SPURIOUS: tainted + + if is_safe(s) is not False: + ensure_not_tainted(s) # $ SPURIOUS: tainted + else: + ensure_tainted(s) # $ tainted + # Make tests runable test_basic() @@ -211,3 +254,4 @@ try: test_with_exception_neg() except: pass +test_comparison_with_bool()