Завершить трек 2: burn-rate alerts, повторные эксперименты и отчёт

This commit is contained in:
2026-11-27 17:23:49 +03:00
parent 0355ba13d2
commit a5c650bcf5
50 changed files with 69318 additions and 300 deletions
+37
View File
@@ -0,0 +1,37 @@
"""HTTP boundary checks against unchanged course semantics, using synthetic bytes."""
import json
import math
import struct
import urllib.parse
import zlib
from common import *
def main():
c=Client(BASE);alice,bob,eve,chat=c.bootstrap()
payload=(ROOT/'tests/fixtures/sample.png').read_bytes()
path='/api/v1/chats/'+chat['id']+'/attachments?filename='
outcomes=[]
for filename in ['../x.png','a\\b.png','bad\x00.png']:
r=c.call('POST',path+urllib.parse.quote(filename,safe=''),400,actor=alice,raw=payload,headers={'Content-Type':'image/png'})
outcomes.append({'case':'invalid filename','status':r['status']})
oversized=(payload*math.ceil((10485760+1)/len(payload)))[:10485761]
r=c.call('POST',path+'large.png',413,actor=alice,raw=oversized,headers={'Content-Type':'image/png'})
outcomes.append({'case':'actual 10 MiB + 1 byte','status':r['status']})
huge=bytearray(payload)
struct.pack_into('>II',huge,16,40001,1001)
struct.pack_into('>I',huge,29,zlib.crc32(huge[12:29]))
r=c.call('POST',path+'pixels.png',413,actor=alice,raw=bytes(huge),headers={'Content-Type':'image/png'})
outcomes.append({'case':'40041001 declared pixels before decode','status':r['status']})
r=c.call('POST',path+'wrong.jpg',415,actor=alice,raw=payload,headers={'Content-Type':'image/jpeg'})
outcomes.append({'case':'MIME/content mismatch','status':r['status']})
key='semantic-'+str(time.time_ns())
first=c.message(alice,chat,'semantic',key=key)['json']
repeat=c.message(alice,chat,'semantic',key=key,attachments=[])['json']
check(first==repeat,'omitted/empty attachments idempotency differs')
c.call('POST','/api/v1/chats/'+chat['id']+'/messages',400,actor=alice,body={'text':'bad','sender_id':eve['id']},headers={'Idempotency-Key':'invalid-'+key})
save('bounds.json',{'checks':outcomes,'semantic_replay_equal':True,'spoofed_sender_rejected':True})
print('PASS: real byte/pixel limits, MIME, filename, semantic replay and sender spoof rejection')
if __name__=='__main__':main()