Исправление по замечанию PR #99: текст с U+0000 вместо 500
PostgreSQL text не хранит 0x00. Expand-миграция 0004 добавляет *_raw bytea для messages.text, users.display_name, chats.title: точные UTF-8 байты пишутся туда, если строка содержит U+0000, API возвращает исходную строку. Тест test_nul_in_text_roundtrip: ответ, история, идемпотентный повтор, 409 на другой текст. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -248,15 +248,42 @@ def test_infrastructure_rules(_c: Client):
|
||||
check(cfg['HostConfig']['ReadonlyRootfs'], 'api root fs must be read-only (no local state)')
|
||||
mounts = {m['Destination'] for m in cfg['Mounts']}
|
||||
check(mounts <= {'/run/secrets/database_url', '/run/secrets/cache_url'}, f'api has unexpected mounts {mounts}')
|
||||
check(sql('SELECT count(*) FROM schema_migrations') == '3', 'unexpected migration count')
|
||||
check(sql('SELECT count(*) FROM schema_migrations') == '4', 'unexpected migration count')
|
||||
with urllib.request.urlopen(os.environ.get('LB_STATS_URL', 'http://lb:8404/stats') + ';csv', timeout=2) as r:
|
||||
text = r.read().decode()
|
||||
check(',UP,' in text or ',UP ' in text, 'LB stats show no UP backend')
|
||||
|
||||
|
||||
def test_nul_in_text_roundtrip(c: Client):
|
||||
"""Замечание к PR #99: {"text":"abc\\u0000def"} давал 500. Строка с U+0000 сохраняется точно."""
|
||||
alice, bob, _eve, _chat = c.bootstrap()
|
||||
text = 'abc\u0000def'
|
||||
chat = c.call('POST', '/api/v1/chats', 201, actor=alice,
|
||||
body={'title': 'чат\u0000NUL', 'member_ids': [alice['id'], bob['id']]}, schema='Chat')['json']
|
||||
check(chat['title'] == 'чат\u0000NUL', 'title with NUL changed in response')
|
||||
got = c.call('GET', '/api/v1/chats/' + chat['id'], actor=bob, schema='Chat')['json']
|
||||
check(got['title'] == 'чат\u0000NUL', 'title with NUL changed on read')
|
||||
key = uuid.uuid4().hex
|
||||
first = c.message(alice, chat, text, key=key)['json']
|
||||
check(first['text'] == text, 'response text differs')
|
||||
replay = c.message(alice, chat, text, key=key)['json']
|
||||
check(replay == first, 'idempotent replay differs')
|
||||
c.call('POST', '/api/v1/chats/' + chat['id'] + '/messages', 409, actor=alice,
|
||||
body={'text': 'abc\ufffddef'}, headers={'Idempotency-Key': key}) # U+FFFD — другой текст
|
||||
c.message(alice, chat, '\u0000') # только NUL — не пробел, допустим
|
||||
history = c.call('GET', '/api/v1/chats/' + chat['id'] + '/messages', actor=bob,
|
||||
schema='MessagePage')['json']['items']
|
||||
check([m['text'] for m in history] == [text, '\u0000'], 'history lost NUL')
|
||||
name = 'Имя\u0000Фамилия'
|
||||
user = c.call('POST', '/api/v1/users', 201, body={'username': 'nul_' + uuid.uuid4().hex[:12],
|
||||
'display_name': name, 'password': 'T3st-' + uuid.uuid4().hex}, schema='User')['json']
|
||||
check(user['display_name'] == name, 'display_name with NUL changed')
|
||||
|
||||
|
||||
TESTS = [test_session_across_replicas, test_same_key_concurrent_across_replicas,
|
||||
test_same_key_concurrent_different_bodies, test_key_scope_and_format, test_replay_rechecks_session,
|
||||
test_transient_failure_not_recorded, test_sigterm_drain, test_infrastructure_rules]
|
||||
test_transient_failure_not_recorded, test_sigterm_drain, test_infrastructure_rules,
|
||||
test_nul_in_text_roundtrip]
|
||||
|
||||
|
||||
def main() -> int:
|
||||
|
||||
Reference in New Issue
Block a user