Skip to content

Commit 429c2b2

Browse files
committed
test for dynamic import added
1 parent 8ce1929 commit 429c2b2

4 files changed

Lines changed: 38 additions & 2 deletions

File tree

docs/examples/codeauditchecks.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,4 +762,4 @@
762762
<td>Vulnerable to path traversal attacks if used with untrusted archives.</td>
763763
</tr>
764764
</tbody>
765-
</table><br><p>Number of implemented security validations:<b>87</b></p><p>Version of codeaudit: <b>1.6.6</b><p>Because Python and cybersecurity are constantly changing, issue reports <b>SHOULD</b> specify the codeaudit version used.</p><p><b>Disclaimer:</b> <i>This SAST tool <a href="https://github.com/nocomplexity/codeaudit" target="_blank"><b>Python Code Audit</b></a> provides a powerful, automatic security analysis for Python source code. However, it's not a substitute for human review in combination with business knowledge. Undetected vulnerabilities may still exist.</i></p><p>This Python security report was created on: <b>2026-05-31 15:53</b> with <a href="https://github.com/nocomplexity/codeaudit" target="_blank"><b>Python Code Audit</b></a> version <b>1.6.6</b></p><hr><footer><div class="footer-links">Check the <a href="https://nocomplexity.com/documents/codeaudit/intro.html" target="_blank">documentation</a> for help on found issues.<br>Codeaudit is made with <span class="heart">&#10084;</span> by cyber security professionals who advocate for <a href="https://nocomplexity.com/simplify-security/" target="_blank">open simple security solutions</a>.<br><a href="https://nocomplexity.com/documents/codeaudit/CONTRIBUTE.html" target="_blank">Join the community</a> and contribute to make this tool better!</div></footer></div></body></html>
765+
</table><br><p>Number of implemented security validations:<b>87</b></p><p>Version of codeaudit: <b>1.6.6</b><p>Because Python and cybersecurity are constantly changing, issue reports <b>SHOULD</b> specify the codeaudit version used.</p><p><b>Disclaimer:</b> <i>This SAST tool <a href="https://github.com/nocomplexity/codeaudit" target="_blank"><b>Python Code Audit</b></a> provides a powerful, automatic security analysis for Python source code. However, it's not a substitute for human review in combination with business knowledge. Undetected vulnerabilities may still exist.</i></p><p>This Python security report was created on: <b>2026-05-31 16:06</b> with <a href="https://github.com/nocomplexity/codeaudit" target="_blank"><b>Python Code Audit</b></a> version <b>1.6.6</b></p><hr><footer><div class="footer-links">Check the <a href="https://nocomplexity.com/documents/codeaudit/intro.html" target="_blank">documentation</a> for help on found issues.<br>Codeaudit is made with <span class="heart">&#10084;</span> by cyber security professionals who advocate for <a href="https://nocomplexity.com/simplify-security/" target="_blank">open simple security solutions</a>.<br><a href="https://nocomplexity.com/documents/codeaudit/CONTRIBUTE.html" target="_blank">Join the community</a> and contribute to make this tool better!</div></footer></div></body></html>

docs/examples/demoscan.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Python_Code_Audit",
33
"version": "1.6.6",
4-
"generated_on": "2026-05-31 15:53",
4+
"generated_on": "2026-05-31 16:06",
55
"file_security_info": {
66
"0": {
77
"FileName": "demofile.py",

tests/test_dynamic_import.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-FileCopyrightText: 2025-present Maikel Mardjan(https://nocomplexity.com/) and all contributors!
2+
# SPDX-License-Identifier: GPL-3.0-or-later
3+
4+
import pytest
5+
from pathlib import Path
6+
7+
from codeaudit.security_checks import perform_validations
8+
9+
10+
def test_base64_use():
11+
current_file_directory = Path(__file__).parent
12+
13+
# validation1.py is in a subfolder:
14+
validation_file_path = (
15+
current_file_directory / "validationfiles" / "danger_imports.py"
16+
)
17+
18+
result = perform_validations(validation_file_path)
19+
20+
# actual_data = find_constructs(source, constructs)
21+
actual_data = result["result"]
22+
23+
# This is the expected dictionary
24+
expected_data = {"input": [5], "importlib.import_module": [7]}
25+
26+
# Assert that the actual data matches the expected data
27+
assert actual_data == expected_data
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import importlib
2+
3+
#dynamic modules import SHOULD be validated! Never trust, always...
4+
5+
user_input = input("Enter a module name to import: ")
6+
7+
my_module = importlib.import_module(user_input) #This what you NEVER want, but in practice programs using importlib use dynamic imports. Always understand the code before executing!
8+
9+
print(f"Successfully imported the {my_module.__name__} module.")

0 commit comments

Comments
 (0)