forked from mtusi2026/mtusi2026lab4
49 lines
1.7 KiB
Bash
Executable File
49 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
||
# Grade 3: PNG 320×200 → 201 ready → download bytes match sha256; message with attachment_ids.
|
||
set -eu
|
||
. "$(dirname "$0")/lib.sh"
|
||
|
||
png="$FIXTURES/320x200.png"
|
||
[ -f "$png" ] || die "missing fixture $png"
|
||
want_sha=$(sha256_file "$png")
|
||
want_size=$(wc -c < "$png" | tr -d ' ')
|
||
|
||
register_user alice
|
||
ALICE_ID=$USER_ID
|
||
ALICE_TOK=$TOKEN
|
||
register_user bob
|
||
BOB_ID=$USER_ID
|
||
BOB_TOK=$TOKEN
|
||
|
||
TOKEN=$ALICE_TOK
|
||
create_chat 'upload-ok' "[\"$ALICE_ID\",\"$BOB_ID\"]"
|
||
|
||
upload_file "$CHAT_ID" "$png" 'sample.png' 'image/png'
|
||
expect_code 201
|
||
AID=$(printf '%s' "$HTTP_BODY" | jq -r .id)
|
||
assert_eq "$(printf '%s' "$HTTP_BODY" | jq -r .status)" ready status
|
||
assert_eq "$(printf '%s' "$HTTP_BODY" | jq -r .content_type)" image/png ctype
|
||
assert_eq "$(printf '%s' "$HTTP_BODY" | jq -r .sha256)" "$want_sha" sha256
|
||
assert_eq "$(printf '%s' "$HTTP_BODY" | jq -r .size_bytes)" "$want_size" size
|
||
assert_eq "$(printf '%s' "$HTTP_BODY" | jq -r .error_code)" null error_code
|
||
assert_eq "$(printf '%s' "$HTTP_BODY" | jq -c .variants)" '[]' variants
|
||
|
||
http_json POST "/api/v1/chats/$CHAT_ID/messages" \
|
||
-H "Authorization: Bearer $ALICE_TOK" \
|
||
-H 'Content-Type: application/json' \
|
||
-H "Idempotency-Key: $(uniq_name idem)" \
|
||
-d "{\"text\":\"\",\"attachment_ids\":[\"$AID\"]}"
|
||
expect_code 201
|
||
assert_eq "$(printf '%s' "$HTTP_BODY" | jq -c .attachment_ids)" "[\"$AID\"]" msg_atts
|
||
|
||
out=$(mktemp)
|
||
curl -sS -m 60 -o "$out" -w '%{http_code}' \
|
||
-H "Authorization: Bearer $BOB_TOK" \
|
||
"$BASE_URL/api/v1/attachments/$AID/content" > /tmp/att_dl.code
|
||
assert_eq "$(cat /tmp/att_dl.code)" 200 download_status
|
||
got_sha=$(sha256_file "$out")
|
||
assert_eq "$got_sha" "$want_sha" download_sha256
|
||
rm -f "$out" /tmp/att_dl.code
|
||
|
||
printf 'PASS test_attachment_upload_ok\n'
|