forked from mtusi2026/mtusi2026lab4
Добавил загрузку картинок в S3 и проверку доступа к вложениям
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"""Stop the API that actually accepted the binary upload, then download via LB."""
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import time
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
sys.path[:0]=[str(ROOT/'tests'),str(ROOT/'scripts')]
|
||||
from client import Client, Failure
|
||||
from ops import containers, command, compose
|
||||
|
||||
def main():
|
||||
c=Client(timeout=5)
|
||||
alice,bob,eve,chat=c.bootstrap()
|
||||
raw=(ROOT/'tests/fixtures/sample.png').read_bytes()
|
||||
response=c.call('POST','/api/v1/chats/'+chat['id']+'/attachments?filename=failover.png',201,
|
||||
actor=alice,raw=raw,headers={'Content-Type':'image/png'},schema='Attachment')
|
||||
instance=response['headers']['X-Instance-Id']
|
||||
matches=[r for r in containers() if instance.startswith(r['Config']['Hostname']+'-')]
|
||||
assert len(matches)==1
|
||||
victim=matches[0]['Id']; started=time.monotonic()
|
||||
command(['docker','stop','--time','6',victim])
|
||||
try:
|
||||
deadline=time.monotonic()+10
|
||||
while True:
|
||||
try:
|
||||
result=c.call('GET','/api/v1/attachments/'+response['json']['id']+'/content',actor=bob)
|
||||
break
|
||||
except Failure:
|
||||
if time.monotonic()>deadline: raise
|
||||
time.sleep(.2)
|
||||
assert result['headers']['X-Instance-Id']!=instance
|
||||
assert result['bytes']==raw
|
||||
assert command(['docker','inspect','--format','{{.State.Running}}',victim])=='false'
|
||||
report={'upload_instance':instance,'stopped_container':victim,
|
||||
'download_instance':result['headers']['X-Instance-Id'],
|
||||
'sha256':hashlib.sha256(raw).hexdigest(),'size_bytes':len(raw),
|
||||
'stop_and_download_seconds':round(time.monotonic()-started,3),'status':'PASS'}
|
||||
(ROOT/'evidence/uploader-failover.json').write_text(json.dumps(report,indent=2))
|
||||
finally:
|
||||
compose('start','api')
|
||||
print('PASS: original downloaded through another replica after uploader stopped')
|
||||
|
||||
if __name__=='__main__': main()
|
||||
Reference in New Issue
Block a user