Fix attachment contract and reconcile storage safely across API replicas
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""Dependency and commit failure checks on a local isolated stand."""
|
||||
from client import Client, check, run
|
||||
from track2 import sql, mc, command
|
||||
import time, uuid
|
||||
|
||||
def main():
|
||||
c=Client(timeout=30); a,b,e,chat=c.bootstrap()
|
||||
att,data=c.attachment(a,chat)
|
||||
key=sql("select object_key from attachments where id='"+att['id']+"';")
|
||||
code=command(['docker','compose','exec','-T','minio','sh','-c','curl -s -o /dev/null -w "%{http_code}" http://localhost:9000/messenger-attachments/'+key])
|
||||
check(code=='403','bucket public')
|
||||
print('PASS direct anonymous GET existing object returns 403',flush=True)
|
||||
command(['docker','compose','stop','minio'])
|
||||
try:
|
||||
c.call('GET','/health/ready',503)
|
||||
c.call('POST','/api/v1/chats/'+chat['id']+'/attachments?filename=x.png',503,actor=a,raw=data,headers={'Content-Type':'image/png'})
|
||||
print('PASS S3 outage: readiness and upload return 503',flush=True)
|
||||
finally: command(['docker','compose','start','minio'])
|
||||
time.sleep(3)
|
||||
# DB trigger rejects metadata after successful PUT. Transaction rolls back; S3 compensation is tested.
|
||||
before=sql('select count(*) from attachments;')
|
||||
objects=mc('mc ls proof/messenger-attachments/')
|
||||
sql("create function proof_reject() returns trigger language plpgsql as $$ begin raise exception 'injected'; end; $$; create trigger proof_reject before insert on attachments for each row execute function proof_reject();")
|
||||
try:
|
||||
c.call('POST','/api/v1/chats/'+chat['id']+'/attachments?filename=x.png',500,actor=a,raw=data,headers={'Content-Type':'image/png'})
|
||||
finally:
|
||||
sql('drop trigger proof_reject on attachments; drop function proof_reject();')
|
||||
check(sql('select count(*) from attachments;')==before,'metadata committed')
|
||||
# saveAndFlush makes rejection observable before compensation, otherwise reconciler cleans after grace.
|
||||
print('PASS DB failure: no success response, no committed metadata; orphan cleanup covered by track2',flush=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
run(main)
|
||||
Reference in New Issue
Block a user