Хранить отзывы сессий в PostgreSQL, сохранять U+0000, ограничить ожидание БД
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import unittest
|
||||
import uuid
|
||||
|
||||
from helpers import call, new_chat, new_user, read_all_messages
|
||||
from helpers import call, login, new_chat, new_user, read_all_messages
|
||||
|
||||
|
||||
class ErrorFormatMixin:
|
||||
@@ -130,12 +130,27 @@ class IdentityTest(ErrorFormatMixin, unittest.TestCase):
|
||||
forged = call('POST', '/api/v1/chats/%s/messages' % chat['id'], {'text': 'hi', 'sender_id': bob['id']}, alice['token'])
|
||||
self.assertError(forged, 400, 'invalid_request')
|
||||
|
||||
def test_nul_character_is_rejected(self):
|
||||
"""Символ NUL нельзя сохранить в PostgreSQL text -> 400, а не 500"""
|
||||
def test_nul_character_is_preserved(self):
|
||||
"""U+0000 — допустимый code point: сообщение, display_name и title сохраняются и читаются без изменений"""
|
||||
username, password = 'nul_' + uuid.uuid4().hex[:12], 'Nul-password-123'
|
||||
status, _, user = call('POST', '/api/v1/users', {'username': username, 'display_name': 'a\u0000lice', 'password': password})
|
||||
self.assertEqual((status, user['display_name']), (201, 'a\u0000lice'))
|
||||
alice = dict(user, token=login(username, password)['token'])
|
||||
self.assertEqual(call('GET', '/api/v1/users/me', token=alice['token'])[2]['display_name'], 'a\u0000lice')
|
||||
status, _, chat = call('POST', '/api/v1/chats', {'title': 't\u0000', 'member_ids': [alice['id']]}, alice['token'])
|
||||
self.assertEqual((status, chat['title']), (201, 't\u0000'))
|
||||
path = '/api/v1/chats/%s/messages' % chat['id']
|
||||
status, _, message = call('POST', path, {'text': 'a\u0000b'}, alice['token'])
|
||||
self.assertEqual((status, message['text']), (201, 'a\u0000b'))
|
||||
self.assertEqual(call('GET', path, token=alice['token'])[2]['items'][0]['text'], 'a\u0000b')
|
||||
self.assertEqual(call('GET', '/api/v1/chats/' + chat['id'], token=alice['token'])[2]['title'], 't\u0000')
|
||||
|
||||
def test_lone_surrogate_is_rejected(self):
|
||||
"""Одиночный суррогат не кодируется в UTF-8 -> 400, а не 500"""
|
||||
alice = new_user('alice')
|
||||
chat = new_chat(alice)
|
||||
self.assertError(call('POST', '/api/v1/chats/%s/messages' % chat['id'], {'text': 'a\u0000b'}, alice['token']),
|
||||
400, 'invalid_request')
|
||||
self.assertError(call('POST', '/api/v1/chats/%s/messages' % chat['id'], raw=b'{"text": "a\\ud800b"}',
|
||||
token=alice['token']), 400, 'invalid_request')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user