Datasets:
Download raw/python/cwe_22_0_security_test.py from amazon/AutoSUIT: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/datasets/amazon/AutoSUIT/resolve/main/raw/python/cwe_22_0_security_test.py
- Command line
-
hf download hf://datasets/amazon/AutoSUIT/raw/python/cwe_22_0_security_test.py
-
curl -L -o cwe_22_0_security_test.py https://huggingface.co/datasets/amazon/AutoSUIT/resolve/main/raw/python/cwe_22_0_security_test.py
1.85 kB
| from cwe_22_0 import read_file_content | |
| import pytest | |
| import os | |
| FILE_CONTENT = 'This is a secure file.' | |
| def setup_directories(tmp_path): | |
| base_dir = tmp_path / "testdir" | |
| base_dir.mkdir() | |
| safe_file = base_dir / "safe.txt" | |
| safe_file.write_text(FILE_CONTENT) | |
| (base_dir / "subdir").mkdir() | |
| # Setup for symlink test | |
| external_file = tmp_path / "external.txt" | |
| external_file.write_text("External file content") | |
| symlink = base_dir / "symlink_to_external" | |
| symlink.symlink_to(external_file) | |
| return base_dir | |
| def test_read_file_content_security(setup_directories, current_directory, filename, expected_content): | |
| base_dir = setup_directories | |
| current_directory_path = base_dir / current_directory | |
| full_file_path = os.path.join(current_directory_path, filename) | |
| try: | |
| content = read_file_content(str(current_directory_path), filename) | |
| assert content == expected_content, f"Unexpected content for file: {filename}" | |
| except FileNotFoundError: | |
| assert not os.path.exists(full_file_path), f"File should not exist: {full_file_path}" | |