lab4: наблюдаемые результаты в evidence
This commit is contained in:
@@ -73,33 +73,40 @@ def main():
|
||||
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')
|
||||
print('happy path: direct PUT 200, complete ready, checksum/size match')
|
||||
|
||||
client.message(alice, chat, '', attachments=[attachment['id']])
|
||||
download = client.call('GET', '/api/v1/attachments/' + attachment['id'] + '/content', actor=bob)
|
||||
check(download['bytes'] == content, 'download differs from the presigned original')
|
||||
print('message with attachment downloaded as the second chat member')
|
||||
|
||||
# Completion is idempotent.
|
||||
again = complete(client, alice, presigned['attachment_id'], digest)['json']
|
||||
check(again['id'] == attachment['id'], 'repeated complete returned another attachment')
|
||||
print('repeated complete is idempotent')
|
||||
|
||||
# A foreign user cannot complete someone else's pending upload.
|
||||
pending = presign(client, alice, chat, content)
|
||||
complete(client, bob, pending['attachment_id'], digest, expected=404)
|
||||
print('foreign complete: 404')
|
||||
|
||||
# Incomplete upload: complete before PUT.
|
||||
incomplete = presign(client, alice, chat, content)
|
||||
complete(client, alice, incomplete['attachment_id'], digest, expected=409)
|
||||
print('complete before PUT: 409')
|
||||
|
||||
# Wrong checksum: the object is rejected and removed.
|
||||
mismatch = presign(client, alice, chat, content)
|
||||
check(put(mismatch['upload_url'], content) == 200, 'direct PUT failed')
|
||||
complete(client, alice, mismatch['attachment_id'], '0' * 64, expected=409)
|
||||
print('wrong completion checksum: 409')
|
||||
|
||||
# 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') == 403, 'oversized PUT must be rejected by S3')
|
||||
complete(client, alice, oversized['attachment_id'], digest, expected=409)
|
||||
print('oversized direct PUT: 403 from S3; complete: 409 (nothing stored)')
|
||||
|
||||
# Last PUT wins before completion; the declared checksum must describe it.
|
||||
# The replacement is the same length because Content-Length is signed.
|
||||
@@ -110,6 +117,7 @@ def main():
|
||||
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')
|
||||
print('same-size overwrite: last PUT wins, checksum verified')
|
||||
|
||||
# A user outside the chat cannot obtain a presigned URL.
|
||||
other = client.call(
|
||||
|
||||
Reference in New Issue
Block a user