forked from mtusi2026/mtusi2026lab4
feat: lab4 - S3 attachments, image validation, failover
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import io
|
||||
import requests
|
||||
|
||||
BASE = "http://localhost:8080"
|
||||
|
||||
# 1. Логин
|
||||
resp = requests.post(f"{BASE}/api/auth/login", json={"login": "test", "password": "test123"})
|
||||
token = resp.json()["token"]
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
|
||||
# 2. PNG 1x1
|
||||
png_data = bytes.fromhex(
|
||||
"89504e470d0a1a0a0000000d49484452000000010000000108060000001f15c4"
|
||||
"890000000d49444154789c63fcffff3f000500010000ffff0300c4f0ff0068"
|
||||
"98e7e70000000049454e44ae426082"
|
||||
)
|
||||
|
||||
# 3. Тестируем разные опасные filename
|
||||
dangerous_names = [
|
||||
"../../../etc/passwd",
|
||||
"../../secret.png",
|
||||
"/etc/passwd",
|
||||
"test/../evil.png",
|
||||
"..\\..\\windows\\system32\\evil.png",
|
||||
]
|
||||
|
||||
print("=== Dangerous filename test ===")
|
||||
all_rejected = True
|
||||
for name in dangerous_names:
|
||||
files = {"file": (name, io.BytesIO(png_data), "image/png")}
|
||||
r = requests.post(f"{BASE}/api/attachments", headers=headers, files=files)
|
||||
rejected = r.status_code == 400
|
||||
status = "PASS" if rejected else "FAIL"
|
||||
print(f"{status}: '{name}' -> {r.status_code} {r.text[:80]}")
|
||||
if not rejected:
|
||||
all_rejected = False
|
||||
|
||||
if all_rejected:
|
||||
print("\n✅ All dangerous filenames correctly rejected")
|
||||
else:
|
||||
print("\n❌ Some dangerous filenames were NOT rejected")
|
||||
Reference in New Issue
Block a user