mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-16 09:31:37 +00:00
fix(simplex): accept display name in SIMPLEX_ALLOWED_USERS
SIMPLEX_ALLOWED_USERS silently denied every contact when operators listed display names instead of numeric contactIds. The SimpleX UI never surfaces the numeric id, so display names are what operators naturally put in the env var. _is_user_authorized only compared source.user_id (the contactId), so the allowlist never matched. Expand check_ids to include source.user_name for the simplex platform, mirroring the existing WhatsApp phone-LID aliasing pattern. Adds doc + setup-prompt clarification and three regression tests. Salvaged from PR #40393. Adds manishbyatroy to release.py AUTHOR_MAP.
This commit is contained in:
parent
9d72680ca3
commit
490c486ff6
5 changed files with 129 additions and 6 deletions
|
|
@ -100,6 +100,109 @@ def test_whatsapp_lid_user_matches_phone_allowlist_via_session_mapping(monkeypat
|
|||
assert runner._is_user_authorized(source) is True
|
||||
|
||||
|
||||
def test_simplex_allowlist_accepts_display_name(monkeypatch):
|
||||
"""SIMPLEX_ALLOWED_USERS should match the contact's display name as well
|
||||
as the numeric contactId. The SimpleX UI surfaces only display names, so
|
||||
operators naturally put those in the env var — and the adapter sets
|
||||
user_id=contactId for stability. Both forms must work. (#TBD)"""
|
||||
_clear_auth_env(monkeypatch)
|
||||
monkeypatch.delenv("SIMPLEX_ALLOWED_USERS", raising=False)
|
||||
monkeypatch.setenv("SIMPLEX_ALLOWED_USERS", "hujikuji")
|
||||
|
||||
# Register the simplex plugin so the env-var lookup resolves.
|
||||
from gateway.platform_registry import platform_registry, PlatformEntry
|
||||
platform_registry.register(PlatformEntry(
|
||||
name="simplex",
|
||||
label="SimpleX Chat",
|
||||
adapter_factory=lambda cfg: None,
|
||||
check_fn=lambda: True,
|
||||
allowed_users_env="SIMPLEX_ALLOWED_USERS",
|
||||
allow_all_env="SIMPLEX_ALLOW_ALL_USERS",
|
||||
))
|
||||
|
||||
simplex = Platform("simplex")
|
||||
runner, _adapter = _make_runner(
|
||||
simplex,
|
||||
GatewayConfig(platforms={simplex: PlatformConfig(enabled=True)}),
|
||||
)
|
||||
|
||||
# contactId in the allowlist would still work — but the operator chose
|
||||
# the display name. Verify the gateway honors it.
|
||||
source = SessionSource(
|
||||
platform=simplex,
|
||||
user_id="4", # adapter sets this to the numeric contactId
|
||||
chat_id="hujikuji",
|
||||
user_name="hujikuji", # adapter sets this to displayName
|
||||
chat_type="dm",
|
||||
)
|
||||
assert runner._is_user_authorized(source) is True
|
||||
|
||||
|
||||
def test_simplex_allowlist_accepts_numeric_contact_id(monkeypatch):
|
||||
"""The numeric contactId form must still work — the new display-name
|
||||
matching must not regress existing setups."""
|
||||
_clear_auth_env(monkeypatch)
|
||||
monkeypatch.delenv("SIMPLEX_ALLOWED_USERS", raising=False)
|
||||
monkeypatch.setenv("SIMPLEX_ALLOWED_USERS", "4")
|
||||
|
||||
from gateway.platform_registry import platform_registry, PlatformEntry
|
||||
platform_registry.register(PlatformEntry(
|
||||
name="simplex",
|
||||
label="SimpleX Chat",
|
||||
adapter_factory=lambda cfg: None,
|
||||
check_fn=lambda: True,
|
||||
allowed_users_env="SIMPLEX_ALLOWED_USERS",
|
||||
allow_all_env="SIMPLEX_ALLOW_ALL_USERS",
|
||||
))
|
||||
|
||||
simplex = Platform("simplex")
|
||||
runner, _adapter = _make_runner(
|
||||
simplex,
|
||||
GatewayConfig(platforms={simplex: PlatformConfig(enabled=True)}),
|
||||
)
|
||||
|
||||
source = SessionSource(
|
||||
platform=simplex,
|
||||
user_id="4",
|
||||
chat_id="hujikuji",
|
||||
user_name="hujikuji",
|
||||
chat_type="dm",
|
||||
)
|
||||
assert runner._is_user_authorized(source) is True
|
||||
|
||||
|
||||
def test_simplex_allowlist_denies_unlisted(monkeypatch):
|
||||
"""Sanity check: an unrelated SimpleX user is still rejected."""
|
||||
_clear_auth_env(monkeypatch)
|
||||
monkeypatch.delenv("SIMPLEX_ALLOWED_USERS", raising=False)
|
||||
monkeypatch.setenv("SIMPLEX_ALLOWED_USERS", "hujikuji")
|
||||
|
||||
from gateway.platform_registry import platform_registry, PlatformEntry
|
||||
platform_registry.register(PlatformEntry(
|
||||
name="simplex",
|
||||
label="SimpleX Chat",
|
||||
adapter_factory=lambda cfg: None,
|
||||
check_fn=lambda: True,
|
||||
allowed_users_env="SIMPLEX_ALLOWED_USERS",
|
||||
allow_all_env="SIMPLEX_ALLOW_ALL_USERS",
|
||||
))
|
||||
|
||||
simplex = Platform("simplex")
|
||||
runner, _adapter = _make_runner(
|
||||
simplex,
|
||||
GatewayConfig(platforms={simplex: PlatformConfig(enabled=True)}),
|
||||
)
|
||||
|
||||
source = SessionSource(
|
||||
platform=simplex,
|
||||
user_id="7",
|
||||
chat_id="stranger",
|
||||
user_name="stranger",
|
||||
chat_type="dm",
|
||||
)
|
||||
assert runner._is_user_authorized(source) is False
|
||||
|
||||
|
||||
def test_star_wildcard_in_allowlist_authorizes_any_user(monkeypatch):
|
||||
"""WHATSAPP_ALLOWED_USERS=* should act as allow-all wildcard."""
|
||||
_clear_auth_env(monkeypatch)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue