forked from mtusi2026/mtusi2026lab4
34 lines
1.9 KiB
Python
34 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Свои negative-сценарии lab4: 413, 415, подмена MIME, чужой attachment, вложение чужого чата, restart/failover."""
|
|
import sys, uuid
|
|
from pathlib import Path
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tests'))
|
|
from client import Client, Failure, run, LAB, check
|
|
|
|
def main():
|
|
c = Client()
|
|
alice, bob, eve, chat = c.bootstrap()
|
|
# 413: > 10 MiB
|
|
big = b'\x89PNG\r\n\x1a\n' + b'\0' * (10*1024*1024 + 10)
|
|
c.call('POST', f"/api/v1/chats/{chat['id']}/attachments?filename=big.png",
|
|
413, actor=alice, raw=big, headers={'Content-Type':'image/png'})
|
|
# 415: text/plain, MIME определяется по содержимому
|
|
c.call('POST', f"/api/v1/chats/{chat['id']}/attachments?filename=x.txt",
|
|
415, actor=alice, raw=b'hello', headers={'Content-Type':'text/plain'})
|
|
# 400: битый PNG
|
|
c.call('POST', f"/api/v1/chats/{chat['id']}/attachments?filename=bad.png",
|
|
400, actor=alice, raw=b'\x89PNG\r\n\x1a\n' + b'\0'*100, headers={'Content-Type':'image/png'})
|
|
# чужой attachment_id: eve не участник
|
|
att, content = c.attachment(alice, chat)
|
|
c.call('GET', f"/api/v1/attachments/{att['id']}", 404, actor=eve)
|
|
c.call('GET', f"/api/v1/attachments/{att['id']}/content", 404, actor=eve)
|
|
# привязка вложения к чужому чату: bob создаёт чат с alice, но ссылается на att из другого чата
|
|
chat2 = c.call('POST','/api/v1/chats',201,actor=bob,
|
|
body={'title':'второй','member_ids':[bob['id'],alice['id']]},schema='Chat')['json']
|
|
c.call('POST', f"/api/v1/chats/{chat2['id']}/messages", 404, actor=bob,
|
|
body={'text':'x','attachment_ids':[att['id']]},
|
|
headers={'Idempotency-Key': uuid.uuid4().hex})
|
|
print('PASS: lab4 negative suite')
|
|
|
|
if __name__=='__main__':
|
|
run(main) |