forked from mtusi2026/mtusi2026lab4
92 lines
2.5 KiB
Batchfile
92 lines
2.5 KiB
Batchfile
@echo off
|
|
setlocal EnableDelayedExpansion
|
|
cd /d "%~dp0.."
|
|
|
|
set BASE=http://localhost:8080
|
|
set TMP=%TEMP%\lab4-persistence
|
|
|
|
if not exist "%TMP%\token.txt" (
|
|
echo FAIL: state not found. Run scripts\persistence-attachment.bat first.
|
|
exit /b 1
|
|
)
|
|
|
|
set /p TOKEN=<"%TMP%\token.txt"
|
|
set /p CHAT_ID=<"%TMP%\chat_id.txt"
|
|
set /p ATT_ID=<"%TMP%\att_id.txt"
|
|
set /p MSG_ID=<"%TMP%\msg_id.txt"
|
|
set /p EXPECTED_SHA=<"%TMP%\sha256.txt"
|
|
|
|
echo === Persistence verify after restart ===
|
|
echo chat=%CHAT_ID%
|
|
echo attachment=%ATT_ID%
|
|
echo message=%MSG_ID%
|
|
echo expected sha256=%EXPECTED_SHA%
|
|
|
|
echo === Check metadata ===
|
|
curl.exe -s -X GET "%BASE%/api/v1/attachments/%ATT_ID%" ^
|
|
-H "Authorization: Bearer %TOKEN%" ^
|
|
-o "%TMP%\meta.json" ^
|
|
-w "%%{http_code}" > "%TMP%\meta.code"
|
|
|
|
set /p RC=<"%TMP%\meta.code"
|
|
if not "%RC%"=="200" (
|
|
echo FAIL: metadata HTTP %RC%
|
|
type "%TMP%\meta.json"
|
|
exit /b 1
|
|
)
|
|
|
|
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\meta.json' -Raw | ConvertFrom-Json).sha256"') do set META_SHA=%%a
|
|
|
|
if not "%META_SHA%"=="%EXPECTED_SHA%" (
|
|
echo FAIL: metadata sha256 mismatch
|
|
exit /b 1
|
|
)
|
|
|
|
echo PASS: attachment metadata survived restart
|
|
|
|
echo === Check content ===
|
|
curl.exe -s -X GET "%BASE%/api/v1/attachments/%ATT_ID%/content" ^
|
|
-H "Authorization: Bearer %TOKEN%" ^
|
|
-o "%TMP%\download.png" ^
|
|
-w "%%{http_code}" > "%TMP%\content.code"
|
|
|
|
set /p RC=<"%TMP%\content.code"
|
|
if not "%RC%"=="200" (
|
|
echo FAIL: content HTTP %RC%
|
|
exit /b 1
|
|
)
|
|
|
|
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-FileHash -Algorithm SHA256 -Path '%TMP%\download.png').Hash.ToLower()"') do set DL_SHA=%%a
|
|
|
|
if not "%DL_SHA%"=="%EXPECTED_SHA%" (
|
|
echo FAIL: downloaded sha256 mismatch
|
|
exit /b 1
|
|
)
|
|
|
|
echo PASS: attachment bytes survived restart
|
|
|
|
echo === Check message history ===
|
|
curl.exe -s -X GET "%BASE%/api/v1/chats/%CHAT_ID%/messages?limit=100" ^
|
|
-H "Authorization: Bearer %TOKEN%" ^
|
|
-o "%TMP%\history.json" ^
|
|
-w "%%{http_code}" > "%TMP%\history.code"
|
|
|
|
set /p RC=<"%TMP%\history.code"
|
|
if not "%RC%"=="200" (
|
|
echo FAIL: history HTTP %RC%
|
|
type "%TMP%\history.json"
|
|
exit /b 1
|
|
)
|
|
|
|
powershell -NoProfile -Command "$h=Get-Content '%TMP%\history.json' -Raw | ConvertFrom-Json; if (-not ($h.items | Where-Object { $_.id -eq '%MSG_ID%' -and $_.attachment_ids -contains '%ATT_ID%' })) { exit 1 }"
|
|
|
|
if errorlevel 1 (
|
|
echo FAIL: message with attachment not found after restart
|
|
exit /b 1
|
|
)
|
|
|
|
echo PASS: message with attachment survived restart
|
|
echo PASS: old session token still works
|
|
echo.
|
|
echo ALL PERSISTENCE CHECKS PASSED
|
|
exit /b 0 |