Complete lab 7 TLS and secret management
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"""Inject a corrupt staged object and prove bounded failure is visible."""
|
||||
import subprocess
|
||||
import time
|
||||
from client import Client, arguments, check, run
|
||||
|
||||
|
||||
def main():
|
||||
args=arguments('Bounded retry and safe failed state')
|
||||
c=Client(args.base_url,args.ca_file,timeout=10)
|
||||
alice,bob,eve,chat=c.bootstrap()
|
||||
subprocess.run(['docker','compose','stop','worker'],check=True,stdout=subprocess.DEVNULL)
|
||||
try:
|
||||
att,original=c.attachment(alice,chat)
|
||||
code="from app.worker import s3,BUCKET; import os,psycopg; c=psycopg.connect(os.environ['DATABASE_URL']); k=c.execute('SELECT stage_key FROM attachments WHERE id=%s',(\""+att['id']+"\",)).fetchone()[0]; s3().put_object(Bucket=BUCKET,Key=k,Body=b'corrupt image data',ContentType='image/png'); c.close()"
|
||||
subprocess.run(['docker','compose','exec','-T','api1','python','-c',code],check=True,stdout=subprocess.DEVNULL)
|
||||
finally:
|
||||
subprocess.run(['docker','compose','up','-d','worker'],check=True,stdout=subprocess.DEVNULL)
|
||||
deadline=time.monotonic()+60
|
||||
while time.monotonic()<deadline:
|
||||
att=c.call('GET','/api/v1/attachments/'+att['id'],actor=bob,schema='Attachment')['json']
|
||||
if att['status']=='failed': break
|
||||
time.sleep(.5)
|
||||
check(att['status']=='failed','corrupt image did not reach bounded failed state')
|
||||
check(att['error_code'] in ('invalid_image','retry_exhausted'),'unexpected public failure code')
|
||||
c.call('GET','/api/v1/attachments/'+att['id']+'/content',409,actor=bob)
|
||||
c.call('POST','/api/v1/chats/'+chat['id']+'/messages',409,actor=alice,
|
||||
body={'text':'','attachment_ids':[att['id']]},headers={'Idempotency-Key':'failed-attachment-test'})
|
||||
print('PASS: corrupt job ended as failed after bounded retries; content and message attachment are rejected')
|
||||
|
||||
if __name__=='__main__': run(main)
|
||||
Reference in New Issue
Block a user