Update completed lab 4 implementation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -101,7 +101,11 @@ def main():
|
||||
upload(broken, expected=415)
|
||||
for broken in (JPEG[:len(JPEG) // 2], JPEG[:4] + b'\x00' * 100, JPEG[:2] + b'\xff\xda\x00\x02' + JPEG[2:]):
|
||||
upload(broken, 'image/jpeg', expected=415)
|
||||
ok('corrupted/truncated PNG and JPEG -> 415')
|
||||
# Структурно корректные, но недекодируемые: PNG 1×1 RGB с верными CRC и фильтром строки 5;
|
||||
# JPEG из 27 байт SOI/SOF0/SOS/EOI без таблиц квантования/Хаффмана и данных скана.
|
||||
upload(png(1, 1, idat=zlib.compress(b'\x05' + bytes(3))), expected=415)
|
||||
upload(bytes.fromhex('ffd8' 'ffc0000b08000100010101 1100'.replace(' ', '') + 'ffda0008010100003f00' 'ffd9'), 'image/jpeg', expected=415)
|
||||
ok('corrupted/truncated/undecodable PNG and JPEG -> 415')
|
||||
|
||||
# Подмена MIME: проверяется содержимое, а не заголовок.
|
||||
upload(PNG, 'image/jpeg', expected=415)
|
||||
|
||||
@@ -117,6 +117,12 @@ def main():
|
||||
sql("insert into attachments values('%s','%s','%s','x.png','image/png',1,'%s',1,1,'uploading','originals/%s',now(),now())"
|
||||
% (inflight, chat['id'], alice['id'], '0' * 64, inflight))
|
||||
fresh_used = upload(); attach(fresh_used)
|
||||
# Старое намерение (2 ч) и только что записанный объект того же ключа: PUT мог завершиться прямо сейчас,
|
||||
# поэтому сверка обязана ждать grace и по объекту — строка и объект остаются.
|
||||
old_intent = str(uuid.uuid4())
|
||||
sql("insert into attachments values('%s','%s','%s','x.png','image/png',5,'%s',1,1,'uploading','originals/%s',now()-interval '2 hours',now()-interval '2 hours')"
|
||||
% (old_intent, chat['id'], alice['id'], '0' * 64, old_intent))
|
||||
s3([put('originals/' + old_intent, 'fresh')])
|
||||
|
||||
before = snapshot()
|
||||
dry = reconcile('--dry-run', '--grace-seconds=%d' % GRACE)
|
||||
@@ -131,6 +137,7 @@ def main():
|
||||
check(f.get('orphan_object') == len(orphan_old) + 1, 'orphan objects (3 injected + deleted row) not found: %s' % f)
|
||||
check(f.get('orphan_object_fresh_kept') == 1 and f.get('upload_in_progress_kept') == 1, 'fresh items not reported as kept: %s' % f)
|
||||
check(f.get('stale_upload') == 1 and f.get('stale_upload_with_object') == 1, 'stale uploads not found: %s' % f)
|
||||
check(f.get('stale_upload_fresh_object_kept') == 1, 'old intent with fresh object not kept: %s' % f)
|
||||
check(f.get('missing_object_used') == 1 and f.get('missing_object') == 1, 'missing objects not found: %s' % f)
|
||||
check(f.get('size_mismatch') == 1 and f.get('lost_object_back_unverified') == 1, 'size mismatch / lost-back not found: %s' % f)
|
||||
check(not dry['actions'], 'dry-run reported actions')
|
||||
@@ -150,6 +157,8 @@ def main():
|
||||
history = c.call('GET', path + '?limit=100', actor=bob, schema='MessagePage')['json']['items']
|
||||
check(any(m == used_msg for m in history), 'message with attachment changed')
|
||||
check('orphan_object_fresh_kept' in apply2['findings'], 'fresh orphan was deleted')
|
||||
check(verify2['findings'].get('stale_upload_fresh_object_kept') == 1 and sql("select count(*) from attachments where id='%s'" % old_intent) == '1',
|
||||
'old intent row or its fresh object was deleted')
|
||||
print('PASS: dry-run read-only, apply fixed %s, repeated apply/verify found nothing new' % json.dumps(a))
|
||||
|
||||
cost = []
|
||||
@@ -167,6 +176,7 @@ def main():
|
||||
report = {'experiment': 'reconciler fault injection (track 2)', 'grace_seconds': GRACE,
|
||||
'injected': {'orphan_objects_old': len(orphan_old), 'object_without_row': 1, 'orphan_object_fresh': 1,
|
||||
'stale_upload_with_object': 1, 'stale_upload_without_object': 1, 'upload_in_progress': 1,
|
||||
'stale_upload_fresh_object': 1,
|
||||
'missing_object_used': 1, 'missing_object_unreferenced': 1, 'size_mismatch': 1,
|
||||
'checksum_mismatch': 1, 'false_lost': 1},
|
||||
'state_before': before, 'state_after_dry_run': after_dry, 'dry_run': dry, 'apply': apply1,
|
||||
|
||||
Reference in New Issue
Block a user