fix(pairing): accept spaced approval codes
Port from qwibitai/nanoclaw#3282: normalize visual whitespace in DM pairing codes while preserving exact-match rejection for chatter-wrapped input.
This commit is contained in:
@@ -464,7 +464,9 @@ class PairingStore:
|
||||
"""
|
||||
with self._lock:
|
||||
self._cleanup_expired(platform)
|
||||
code = code.upper().strip()
|
||||
# Chat UIs insert visual spacing between code characters; strip all
|
||||
# whitespace, then match exactly (surrounding words still fail). #89937
|
||||
code = "".join(str(code or "").upper().split())
|
||||
# Before the lookup, or an already-issued valid code would bypass lockout.
|
||||
if self._is_locked_out(platform):
|
||||
return None
|
||||
|
||||
@@ -275,6 +275,25 @@ class TestApprovalFlow:
|
||||
assert result["user_id"] == "user1"
|
||||
assert result["user_name"] == "Alice"
|
||||
|
||||
def test_approve_code_with_internal_spacing(self, tmp_path):
|
||||
with patch("gateway.pairing.PAIRING_DIR", tmp_path):
|
||||
store = PairingStore()
|
||||
code = store.generate_code("telegram", "user1", "Alice")
|
||||
spaced_code = " ".join(code)
|
||||
result = store.approve_code("telegram", f" {spaced_code} ")
|
||||
|
||||
assert isinstance(result, dict)
|
||||
assert result["user_id"] == "user1"
|
||||
assert result["user_name"] == "Alice"
|
||||
|
||||
def test_approve_code_with_words_still_fails(self, tmp_path):
|
||||
with patch("gateway.pairing.PAIRING_DIR", tmp_path):
|
||||
store = PairingStore()
|
||||
code = store.generate_code("telegram", "user1", "Alice")
|
||||
result = store.approve_code("telegram", f"code {code}")
|
||||
|
||||
assert result is None
|
||||
|
||||
def test_approved_user_is_approved(self, tmp_path):
|
||||
with patch("gateway.pairing.PAIRING_DIR", tmp_path):
|
||||
store = PairingStore()
|
||||
|
||||
Reference in New Issue
Block a user