forked from mtusi2026/mtusi2026lab4
50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Negative and isolation checks required by level 4."""
|
|
|
|
from pathlib import Path
|
|
from urllib.parse import quote
|
|
|
|
from client import Client, arguments, run
|
|
|
|
|
|
def main():
|
|
args = arguments("Lab4 negative upload scenarios")
|
|
client = Client(args.base_url, args.ca_file)
|
|
alice, bob, eve, chat = client.bootstrap()
|
|
base = "/api/v1/chats/" + chat["id"] + "/attachments?filename="
|
|
client.call(
|
|
"POST", base + "large.png", 413, actor=alice,
|
|
raw=b"x" * (10 * 1024 * 1024 + 1), headers={"Content-Type": "image/png"},
|
|
)
|
|
client.call(
|
|
"POST", base + "broken.png", 415, actor=alice,
|
|
raw=b"not-an-image", headers={"Content-Type": "image/png"},
|
|
)
|
|
content = (Path(__file__).parent / "fixtures/sample.png").read_bytes()
|
|
client.call(
|
|
"POST", base + "spoofed.jpg", 415, actor=alice,
|
|
raw=content, headers={"Content-Type": "image/jpeg"},
|
|
)
|
|
client.call(
|
|
"POST", base + quote("../unsafe.png", safe=""), 400, actor=alice,
|
|
raw=content, headers={"Content-Type": "image/png"},
|
|
)
|
|
attachment, _ = client.attachment(alice, chat)
|
|
for suffix in ("", "/content"):
|
|
client.call("GET", "/api/v1/attachments/" + attachment["id"] + suffix, 404, actor=eve)
|
|
other = client.call(
|
|
"POST", "/api/v1/chats", 201, actor=alice,
|
|
body={"title": "Другой чат", "member_ids": [alice["id"], eve["id"]]}, schema="Chat",
|
|
)["json"]
|
|
alien, _ = client.attachment(alice, other)
|
|
client.call(
|
|
"POST", "/api/v1/chats/" + chat["id"] + "/messages", 404, actor=bob,
|
|
body={"text": "", "attachment_ids": [alien["id"]]},
|
|
headers={"Idempotency-Key": "cross-chat-attachment"},
|
|
)
|
|
print("PASS: lab4 level-4 negative and authorization scenarios")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run(main)
|