Files
MyAiConfiguration/scripts/benchmarks/tasks/09-path-traversal/hidden/test_hidden.py
T
Julian lechnerandClaude Opus 5.5 3480072ed7 test(benchmarks): add A/B task fixtures with hidden checks
Ten small Python tasks, each failing on the fixture and passing with a
reference solution, including workflow expectations for a small change, a
bugfix, and a delegable change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 12:45:40 +02:00

27 lines
911 B
Python

import os
import tempfile
import unittest
from pathlib import Path
from app.files import read_upload
class Hidden(unittest.TestCase):
def setUp(self):
self.directory = tempfile.TemporaryDirectory()
root = Path(self.directory.name)
(root / 'uploads/sub').mkdir(parents=True)
(root / 'uploads/sub/a.txt').write_bytes(b'ok')
(root / 'secret.txt').write_bytes(b'secret')
self.base = str(root / 'uploads')
def tearDown(self):
self.directory.cleanup()
def test_nested(self):
self.assertEqual(read_upload(self.base, 'sub/a.txt'), b'ok')
def test_traversal(self):
for name in ('../secret.txt', 'sub/../../secret.txt', os.path.join(os.path.dirname(self.base), 'secret.txt')):
with self.subTest(name), self.assertRaises((ValueError, PermissionError, FileNotFoundError)):
read_upload(self.base, name)