PayloadsAllTheThings/test_python_md.py
lshep-bf 3b957de607 Update Python deserialization documentation and add unit test
Add more examples and sections to `Insecure Deserialization/Python.md` and create a new test file `test_python_md.py`.

* **Insecure Deserialization/Python.md**:
  - Add examples of vulnerable code snippets and their secure alternatives for `pickle` and `PyYAML`.
  - Include a section on common pitfalls and how to avoid them when using deserialization in Python.
  - Provide a list of tools and libraries that can help detect and prevent insecure deserialization in Python applications.
  - Add references to relevant documentation, articles, and research papers for further reading.
  - Include a section on how to test for insecure deserialization vulnerabilities in Python applications, including both manual and automated testing techniques.

* **test_python_md.py**:
  - Import the `unittest` and `re` modules.
  - Create a test case that reads the `Insecure Deserialization/Python.md` file.
  - Extract the Python code blocks from the markdown file.
  - Execute each code block and check for any exceptions.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/swisskyrepo/PayloadsAllTheThings?shareId=XXXX-XXXX-XXXX-XXXX).
2025-01-20 14:42:00 -08:00

20 lines
547 B
Python

import unittest
import re
class TestPythonMd(unittest.TestCase):
def test_python_code_blocks(self):
with open('Insecure Deserialization/Python.md', 'r') as file:
content = file.read()
# Extract Python code blocks
code_blocks = re.findall(r'```python(.*?)```', content, re.DOTALL)
for code in code_blocks:
try:
exec(code)
except Exception as e:
self.fail(f"Code block failed to execute: {e}")
if __name__ == '__main__':
unittest.main()