Files
mtusi2026lab4/scripts/private-bucket-check.bat
2026-10-26 16:10:22 +03:00

39 lines
1001 B
Batchfile

@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0.."
set TMP=%TEMP%\lab4-private
if not exist "%TMP%" mkdir "%TMP%"
echo === Private bucket check ===
for /f "delims=" %%a in ('docker compose exec -T postgres psql -U messenger -d messenger -tAc "SELECT s3_key FROM attachments ORDER BY created_at DESC LIMIT 1"') do set KEY=%%a
if "%KEY%"=="" (
echo FAIL: no attachments found. Run scripts\manual-attachments.bat first.
exit /b 1
)
echo Latest s3_key: %KEY%
docker compose exec -T api sh -lc "wget -S -O /dev/null http://rustfs:9000/messenger/%KEY% 2>&1" > "%TMP%\out.txt" 2>&1
echo.
echo Direct unauthenticated response:
type "%TMP%\out.txt"
echo.
findstr /c:"HTTP/1.1 200" "%TMP%\out.txt" >nul
if not errorlevel 1 (
echo FAIL: bucket appears public, direct GET returned 200
exit /b 1
)
findstr /c:"HTTP/" "%TMP%\out.txt" >nul
if errorlevel 1 (
echo WARN: could not parse HTTP status from wget output
exit /b 2
)
echo PASS: direct unauthenticated access is not 200
exit /b 0