lab4: исправления по ревью

This commit is contained in:
Vladislav Kunetskiy
2026-10-21 23:25:11 +03:00
parent 3389c6c900
commit e9f0fde6f2
32 changed files with 451 additions and 131 deletions
+9 -4
View File
@@ -69,6 +69,7 @@ def main():
# Happy path: direct PUT, completion, message, download.
presigned = presign(client, alice, chat, content)
check(presigned['method'] == 'PUT', 'presign method must be PUT')
check('content-length' in presigned['upload_url'], 'content-length must be signed into the URL')
check(put(presigned['upload_url'], content) == 200, 'direct PUT failed')
attachment = complete(client, alice, presigned['attachment_id'], digest)['json']
check(attachment['sha256'] == digest and attachment['size_bytes'] == len(content), 'completed metadata mismatch')
@@ -94,14 +95,18 @@ def main():
check(put(mismatch['upload_url'], content) == 200, 'direct PUT failed')
complete(client, alice, mismatch['attachment_id'], '0' * 64, expected=409)
# Declared size is enforced at completion, after the direct PUT.
# Content-Length is signed, so S3 rejects a different number of bytes at
# write time instead of storing an oversized staging object.
oversized = presign(client, alice, chat, content)
check(put(oversized['upload_url'], content + b'x') == 200, 'direct PUT failed')
complete(client, alice, oversized['attachment_id'], digest, expected=400)
check(put(oversized['upload_url'], content + b'x') == 403, 'oversized PUT must be rejected by S3')
complete(client, alice, oversized['attachment_id'], digest, expected=409)
# Last PUT wins before completion; the declared checksum must describe it.
# The replacement is the same length because Content-Length is signed.
overwrite = presign(client, alice, chat, content)
check(put(overwrite['upload_url'], b'not an image') == 200, 'first PUT failed')
corrupt = bytearray(content)
corrupt[0] ^= 0xFF
check(put(overwrite['upload_url'], bytes(corrupt)) == 200, 'first PUT failed')
check(put(overwrite['upload_url'], content) == 200, 'second PUT failed')
overwritten = complete(client, alice, overwrite['attachment_id'], digest)['json']
check(overwritten['sha256'] == digest, 'last PUT was not the completed object')