plugin XEP-0373, tests (unit/XEP-0373): Make rpad size >= 50:

XEP-0420 bounds starts at 0 but 0-length rpad defeats its purpose (the XEP actually says
"TODO: sane boundaries?"). Furthermore, some tests where failing randomly due to 0-lenght
rpad sometimes happening. This patch makes rpad minimum size at 50.
This commit is contained in:
Goffi 2026-04-09 21:42:16 +02:00
commit 09bef94ffe

View file

@ -602,8 +602,11 @@ class XEP_0373:
if include_rpad:
# XEP-0373 doesn't specify bounds for the length of the random padding. This
# uses the bounds specified in XEP-0420 for the closely related rpad affix.
rpad_length = secrets.randbelow(201)
# uses the bounds specified in XEP-0420 for the closely related rpad affix. We
# use a minimum of 50 characters to ensure meaningful protection against
# length-based side channel attacks. XEP-0420 specifies 0-200 characters, but
# 0-length padding defeats the security purpose of rpad.
rpad_length = secrets.randbelow(151) + 50 # Range [50, 200]
rpad_content = "".join(
secrets.choice(string.digits + string.ascii_letters + string.punctuation)
for __ in range(rpad_length)