forked from mtusi2026/mtusi2026lab2
исправление - символ не дает 500
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
import unittest
|
||||
import uuid
|
||||
|
||||
from helpers import Client, read_history
|
||||
from helpers import Client, basic, read_history
|
||||
|
||||
PASSWORD = "Test-password-123"
|
||||
|
||||
@@ -86,6 +86,28 @@ class MessengerApiTest(unittest.TestCase):
|
||||
self.api.call("POST", "/api/v1/users", 201,
|
||||
body={"username": name, "display_name": "👋" * 100, "password": PASSWORD})
|
||||
|
||||
def test_nul_character_is_stored(self):
|
||||
# Замечание к MR: U+0000 допустим по контракту и должен сохраняться как есть, а не давать 500.
|
||||
name = "nul_" + uuid.uuid4().hex[:10]
|
||||
password = "Pass\u0000word-123"
|
||||
user = self.api.call("POST", "/api/v1/users", 201, schema="User",
|
||||
body={"username": name, "display_name": "A\u0000B", "password": password})["json"]
|
||||
self.assertEqual(user["display_name"], "A\u0000B")
|
||||
session = self.api.call("POST", "/api/v1/auth/sessions", 201, schema="Session",
|
||||
headers={"Authorization": basic(name, password)})["json"]
|
||||
self.assertEqual(session["user"]["display_name"], "A\u0000B")
|
||||
chat = self.api.call("POST", "/api/v1/chats", 201, actor=self.alice, schema="Chat",
|
||||
body={"title": "T\u0000itle", "member_ids": [self.alice["id"], self.bob["id"]]})["json"]
|
||||
self.assertEqual(chat["title"], "T\u0000itle")
|
||||
sent = self.send(self.alice, chat["id"], "hello\u0000world")["json"]
|
||||
self.assertEqual(sent["text"], "hello\u0000world")
|
||||
history, _ = read_history(self.api, self.bob, chat["id"])
|
||||
self.assertEqual([m["text"] for m in history], ["hello\u0000world"])
|
||||
got = self.api.call("GET", f"/api/v1/chats/{chat['id']}", actor=self.bob, schema="Chat")["json"]
|
||||
self.assertEqual(got["title"], "T\u0000itle")
|
||||
# username с U+0000 существовать не может: вход — обычный 401, а не 500.
|
||||
self.api.call("POST", "/api/v1/auth/sessions", 401, headers={"Authorization": basic("ab\u0000c", password)})
|
||||
|
||||
def test_pagination_walks_several_pages(self):
|
||||
chat = self.new_chat()
|
||||
sent = [self.send(self.alice, chat["id"], f"msg {i}")["json"] for i in range(7)]
|
||||
|
||||
Reference in New Issue
Block a user