forked from mtusi2026/mtusi2026lab3
29 lines
1.4 KiB
Python
29 lines
1.4 KiB
Python
"""Additional grade-3 checks: concurrent replay and invalid uploads."""
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
import uuid
|
|
from client import Client, LAB, arguments, check, run
|
|
|
|
|
|
def main():
|
|
args = arguments('Extra acceptance checks')
|
|
c = Client(args.base_url)
|
|
alice,bob,eve,chat = c.bootstrap()
|
|
key = uuid.uuid4().hex
|
|
def send(_):
|
|
return c.message(alice,chat,'Concurrent retry',key=key)['json']
|
|
with ThreadPoolExecutor(max_workers=8) as pool:
|
|
results = list(pool.map(send,range(16)))
|
|
check(all(r==results[0] for r in results),'concurrent replay created different messages')
|
|
print('PASS: 16 concurrent retries return one message')
|
|
if LAB >= 4:
|
|
path = '/api/v1/chats/'+chat['id']+'/attachments'
|
|
content = open('tests/fixtures/sample.png','rb').read()
|
|
c.call('POST',path+'?filename=../x.png',400,actor=alice,raw=content,headers={'Content-Type':'image/png'})
|
|
c.call('POST',path+'?filename=x.jpg',415,actor=alice,raw=content,headers={'Content-Type':'image/jpeg'})
|
|
c.call('POST',path+'?filename=x.png',415,actor=alice,raw=b'broken',headers={'Content-Type':'image/png'})
|
|
c.call('POST',path+'?filename=x.png',413,actor=alice,raw=b'x'*(10485760+1),headers={'Content-Type':'image/png'})
|
|
print('PASS: unsafe filename, MIME mismatch, corruption and byte limit')
|
|
|
|
if __name__=='__main__':
|
|
run(main)
|