|
4 | 4 |
|
5 | 5 | from ddtrace.appsec._iast._taint_tracking import OriginType |
6 | 6 | from ddtrace.appsec._iast._taint_tracking import Source |
| 7 | +from ddtrace.appsec._iast._taint_tracking import create_context |
| 8 | +from ddtrace.appsec._iast._taint_tracking import destroy_context |
7 | 9 | from ddtrace.appsec._iast._taint_tracking import get_tainted_ranges |
8 | 10 | from ddtrace.appsec._iast._taint_tracking import is_pyobject_tainted |
9 | 11 | from ddtrace.appsec._iast._taint_tracking import taint_pyobject |
@@ -301,3 +303,73 @@ def test_taint_ranges_as_evidence_info_different_tainted_op1_and_op3_add(): |
301 | 303 | {"value": tainted_text2, "source": 1}, |
302 | 304 | ] |
303 | 305 | assert sources == [input_info1, input_info2] |
| 306 | + |
| 307 | + |
| 308 | +def test_taint_object_error_with_no_context(): |
| 309 | + """Test taint_pyobject without context. This test is to ensure that the function does not raise an exception.""" |
| 310 | + string_to_taint = "my_string" |
| 311 | + create_context() |
| 312 | + result = taint_pyobject( |
| 313 | + pyobject=string_to_taint, |
| 314 | + source_name="test_add_aspect_tainting_left_hand", |
| 315 | + source_value=string_to_taint, |
| 316 | + source_origin=OriginType.PARAMETER, |
| 317 | + ) |
| 318 | + |
| 319 | + ranges_result = get_tainted_ranges(result) |
| 320 | + assert len(ranges_result) == 1 |
| 321 | + |
| 322 | + destroy_context() |
| 323 | + result = taint_pyobject( |
| 324 | + pyobject=string_to_taint, |
| 325 | + source_name="test_add_aspect_tainting_left_hand", |
| 326 | + source_value=string_to_taint, |
| 327 | + source_origin=OriginType.PARAMETER, |
| 328 | + ) |
| 329 | + |
| 330 | + ranges_result = get_tainted_ranges(result) |
| 331 | + assert len(ranges_result) == 0 |
| 332 | + |
| 333 | + create_context() |
| 334 | + result = taint_pyobject( |
| 335 | + pyobject=string_to_taint, |
| 336 | + source_name="test_add_aspect_tainting_left_hand", |
| 337 | + source_value=string_to_taint, |
| 338 | + source_origin=OriginType.PARAMETER, |
| 339 | + ) |
| 340 | + |
| 341 | + ranges_result = get_tainted_ranges(result) |
| 342 | + assert len(ranges_result) == 1 |
| 343 | + |
| 344 | + |
| 345 | +def test_get_ranges_from_object_with_no_context(): |
| 346 | + """Test taint_pyobject without context. This test is to ensure that the function does not raise an exception.""" |
| 347 | + string_to_taint = "my_string" |
| 348 | + create_context() |
| 349 | + result = taint_pyobject( |
| 350 | + pyobject=string_to_taint, |
| 351 | + source_name="test_add_aspect_tainting_left_hand", |
| 352 | + source_value=string_to_taint, |
| 353 | + source_origin=OriginType.PARAMETER, |
| 354 | + ) |
| 355 | + |
| 356 | + destroy_context() |
| 357 | + ranges_result = get_tainted_ranges(result) |
| 358 | + assert len(ranges_result) == 0 |
| 359 | + |
| 360 | + |
| 361 | +def test_propagate_ranges_with_no_context(): |
| 362 | + """Test taint_pyobject without context. This test is to ensure that the function does not raise an exception.""" |
| 363 | + string_to_taint = "my_string" |
| 364 | + create_context() |
| 365 | + result = taint_pyobject( |
| 366 | + pyobject=string_to_taint, |
| 367 | + source_name="test_add_aspect_tainting_left_hand", |
| 368 | + source_value=string_to_taint, |
| 369 | + source_origin=OriginType.PARAMETER, |
| 370 | + ) |
| 371 | + |
| 372 | + destroy_context() |
| 373 | + result_2 = add_aspect(result, "another_string") |
| 374 | + ranges_result = get_tainted_ranges(result_2) |
| 375 | + assert len(ranges_result) == 0 |
0 commit comments