Skip to content

Commit

Permalink
chore(iast): pyiobase_check tests (#10844)
Browse files Browse the repository at this point in the history
Code Security: Add tests for PyIOBase_Check function

## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met 
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
  • Loading branch information
gnufede committed Sep 27, 2024
1 parent e160b36 commit 0bd5ea0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ddtrace/appsec/_iast/_taint_tracking/tests/test_stringutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@ TEST_F(PyReMatchCheck, TEstPyReMatchNullObject)
ASSERT_FALSE(PyReMatch_Check(null_obj));
}

using PyIOBaseCheck = PyEnvWithContext;

TEST_F(PyIOBaseCheck, TestPyIOBaseValidObject)
{
py::object io_module = py::module_::import("io");
py::object stringio_obj = io_module.attr("StringIO")("a");

ASSERT_TRUE(PyIOBase_Check(stringio_obj.ptr()));
}

TEST_F(PyIOBaseCheck, TestPyIOBaseInvalidObject)
{
py::object non_io_obj = py::int_(42); // Not a `_io._IOBase` object

ASSERT_FALSE(PyIOBase_Check(non_io_obj.ptr()));
}

TEST_F(PyIOBaseCheck, TestPyIOBaseNullObject)
{
PyObject* null_obj = Py_None;

ASSERT_FALSE(PyIOBase_Check(null_obj));
}

using IsFastTaintedCheck = PyEnvCheck;

TEST_F(IsFastTaintedCheck, FastTaintedNullptrReturnsTrue)
Expand Down

0 comments on commit 0bd5ea0

Please sign in to comment.