Files
mtusi2026lab4/student-tests/test_attachment_too_large.sh
T
2026-10-30 21:09:56 +03:00

22 lines
720 B
Bash
Executable File

#!/bin/sh
# Grade 4 criteria (negative): 11 MiB body → 413 payload_too_large (not 500).
set -eu
. "$(dirname "$0")/lib.sh"
register_user alice
create_chat 'too-large' "[\"$USER_ID\"]"
big=$(mktemp)
# Valid PNG magic + padding to 11 MiB so Content-Length triggers early reject.
dd if=/dev/zero of="$big" bs=1M count=11 status=none
# Prepend PNG signature so it's not rejected as empty before size check.
printf '\x89PNG\r\n\x1a\n' | dd of="$big" conv=notrunc status=none 2>/dev/null || true
upload_file "$CHAT_ID" "$big" 'huge.png' 'image/png'
rm -f "$big"
expect_code 413
code=$(printf '%s' "$HTTP_BODY" | jq -r .error.code)
assert_eq "$code" payload_too_large error_code
printf 'PASS test_attachment_too_large\n'