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

33 lines
884 B
Bash
Executable File

#!/bin/sh
# Non-member → 404 on GET metadata and /content (no leak).
set -eu
. "$(dirname "$0")/lib.sh"
png="$FIXTURES/tiny.png"
[ -f "$png" ] || die "missing fixture $png"
register_user alice
ALICE_ID=$USER_ID
ALICE_TOK=$TOKEN
register_user eve
EVE_TOK=$TOKEN
TOKEN=$ALICE_TOK
create_chat 'foreign' "[\"$ALICE_ID\"]"
upload_file "$CHAT_ID" "$png" 'tiny.png' 'image/png'
expect_code 201
AID=$(printf '%s' "$HTTP_BODY" | jq -r .id)
http_json GET "/api/v1/attachments/$AID" -H "Authorization: Bearer $EVE_TOK"
expect_code 404
assert_eq "$(printf '%s' "$HTTP_BODY" | jq -r .error.code)" not_found meta
http_json GET "/api/v1/attachments/$AID/content" -H "Authorization: Bearer $EVE_TOK"
expect_code 404
assert_eq "$(printf '%s' "$HTTP_BODY" | jq -r .error.code)" not_found content
http_json GET "/api/v1/attachments/$AID"
expect_code 401
printf 'PASS test_attachment_foreign\n'