|
| 1 | +# All functions starting with "test_" should run and execute `print("OK")` exactly once. |
| 2 | +# This can be checked by running validTest.py. |
| 3 | + |
| 4 | +import sys |
| 5 | +import os |
| 6 | + |
| 7 | +sys.path.append(os.path.dirname(os.path.dirname((__file__)))) |
| 8 | +from testlib import * |
| 9 | + |
| 10 | +# These are defined so that we can evaluate the test code. |
| 11 | +NONSOURCE = "not a source" |
| 12 | +SOURCE = "source" |
| 13 | + |
| 14 | +def is_source(x): |
| 15 | + return x == "source" or x == b"source" or x == 42 or x == 42.0 or x == 42j |
| 16 | + |
| 17 | + |
| 18 | +def SINK(x): |
| 19 | + if is_source(x): |
| 20 | + print("OK") |
| 21 | + else: |
| 22 | + print("Unexpected flow", x) |
| 23 | + |
| 24 | + |
| 25 | +def SINK_F(x): |
| 26 | + if is_source(x): |
| 27 | + print("Unexpected flow", x) |
| 28 | + else: |
| 29 | + print("OK") |
| 30 | + |
| 31 | + |
| 32 | +def In(tainted): |
| 33 | + def captureIn1(): |
| 34 | + sinkI1 = tainted |
| 35 | + SINK(sinkI1) #$ MISSING:captured |
| 36 | + captureIn1() |
| 37 | + |
| 38 | + def captureIn2(): |
| 39 | + def m(): |
| 40 | + sinkI2 = tainted |
| 41 | + SINK(sinkI2) #$ MISSING:captured |
| 42 | + m() |
| 43 | + captureIn2() |
| 44 | + |
| 45 | + # captureIn3 = lambda arg:( |
| 46 | + # sinkI3 = tainted; |
| 47 | + # check(sinkI3); |
| 48 | + # return arg) |
| 49 | + # [ captureIn3(x) for x in " " ] |
| 50 | + |
| 51 | + def captureIn1NotCalled(): |
| 52 | + nonSink0 = tainted |
| 53 | + SINK_F(nonSink0) |
| 54 | + |
| 55 | + def captureIn2NotCalled(): |
| 56 | + def m(): |
| 57 | + nonSink0 = tainted |
| 58 | + SINK_F(nonSink0) |
| 59 | + captureIn2NotCalled() |
| 60 | + |
| 61 | +@expects(2) |
| 62 | +def test_In(): |
| 63 | + In(SOURCE) |
| 64 | + |
| 65 | +def Out(): |
| 66 | + sinkO1 = { "x": "" } |
| 67 | + def captureOut1(): |
| 68 | + sinkO1["x"] = "source" |
| 69 | + captureOut1() |
| 70 | + SINK(sinkO1["x"]) #$ MISSING:captured |
| 71 | + |
| 72 | + sinkO2 = { "x": "" } |
| 73 | + def captureOut2(): |
| 74 | + def m(): |
| 75 | + sinkO2["x"] = "source" |
| 76 | + m() |
| 77 | + captureOut2() |
| 78 | + SINK(sinkO2["x"]) #$ MISSING:captured |
| 79 | + |
| 80 | + nonSink0 = { "x": "" } |
| 81 | + def captureOut1NotCalled(): |
| 82 | + nonSink0["x"] = "source" |
| 83 | + SINK_F(nonSink0["x"]) |
| 84 | + |
| 85 | + def captureOut2NotCalled(): |
| 86 | + def m(): |
| 87 | + nonSink0["x"] = "source" |
| 88 | + captureOut2NotCalled() |
| 89 | + SINK_F(nonSink0["x"]) |
| 90 | + |
| 91 | +@expects(4) |
| 92 | +def test_Out(): |
| 93 | + Out() |
| 94 | + |
| 95 | +def Through(tainted): |
| 96 | + sinkO1 = { "x": "" } |
| 97 | + def captureOut1(): |
| 98 | + sinkO1["x"] = tainted |
| 99 | + captureOut1() |
| 100 | + SINK(sinkO1["x"]) #$ MISSING:captured |
| 101 | + |
| 102 | + sinkO2 = { "x": "" } |
| 103 | + def captureOut2(): |
| 104 | + def m(): |
| 105 | + sinkO2["x"] = tainted |
| 106 | + m() |
| 107 | + captureOut2() |
| 108 | + SINK(sinkO2["x"]) #$ MISSING:captured |
| 109 | + |
| 110 | + nonSink0 = { "x": "" } |
| 111 | + def captureOut1NotCalled(): |
| 112 | + nonSink0["x"] = tainted |
| 113 | + SINK_F(nonSink0["x"]) |
| 114 | + |
| 115 | + def captureOut2NotCalled(): |
| 116 | + def m(): |
| 117 | + nonSink0["x"] = tainted |
| 118 | + captureOut2NotCalled() |
| 119 | + SINK_F(nonSink0["x"]) |
| 120 | + |
| 121 | +@expects(4) |
| 122 | +def test_Through(): |
| 123 | + Through(SOURCE) |
0 commit comments