Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gateway/whatsapp_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# full-width digits / Unicode word chars can't sneak through.
_SAFE_IDENTIFIER_RE = re.compile(r"^[A-Za-z0-9@.+\-]+$")

from hermes_constants import get_hermes_home
from hermes_constants import get_hermes_dir


def normalize_whatsapp_identifier(value: str) -> str:
Expand Down Expand Up @@ -133,7 +133,7 @@ def expand_whatsapp_aliases(identifier: str) -> Set[str]:
if not normalized:
return set()

session_dir = get_hermes_home() / "whatsapp" / "session"
session_dir = get_hermes_dir("platforms/whatsapp/session", "whatsapp/session")
resolved: Set[str] = set()
queue = [normalized]

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions tests/gateway/test_unauthorized_dm_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,42 @@ def test_whatsapp_lid_user_matches_phone_allowlist_via_session_mapping(monkeypat
assert runner._is_user_authorized(source) is True


def test_whatsapp_lid_user_matches_phone_allowlist_via_modern_session_mapping(
monkeypatch, tmp_path,
):
"""Modern ``platforms/`` installs store bridge mappings under
``platforms/whatsapp/session`` — the LID→phone resolution (and therefore
the allowlist match) must work there too, not just the legacy layout.
Regression guard for the silently-dropped-LID-sender bug (#36664)."""
_clear_auth_env(monkeypatch)
monkeypatch.setenv("WHATSAPP_ALLOWED_USERS", "15550000001")
monkeypatch.setenv("HERMES_HOME", str(tmp_path))

session_dir = tmp_path / "platforms" / "whatsapp" / "session"
session_dir.mkdir(parents=True)
(session_dir / "lid-mapping-15550000001.json").write_text(
'"900000000000001"', encoding="utf-8",
)
(session_dir / "lid-mapping-900000000000001_reverse.json").write_text(
'"15550000001"', encoding="utf-8",
)

runner, _adapter = _make_runner(
Platform.WHATSAPP,
GatewayConfig(platforms={Platform.WHATSAPP: PlatformConfig(enabled=True)}),
)

source = SessionSource(
platform=Platform.WHATSAPP,
user_id="900000000000001@lid",
chat_id="900000000000001@lid",
user_name="tester",
chat_type="dm",
)

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
Expand Down
37 changes: 37 additions & 0 deletions tests/gateway/test_whatsapp_identity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Tests for gateway.whatsapp_identity alias resolution path."""

import json

from gateway.whatsapp_identity import expand_whatsapp_aliases


def test_aliases_resolve_on_modern_platforms_layout(tmp_path, monkeypatch):
tmp_home = tmp_path / "hermes-home"
mapping_dir = tmp_home / "platforms" / "whatsapp" / "session"
mapping_dir.mkdir(parents=True, exist_ok=True)
(mapping_dir / "lid-mapping-999999999999999.json").write_text(
json.dumps("15551234567@s.whatsapp.net"),
encoding="utf-8",
)
monkeypatch.setenv("HERMES_HOME", str(tmp_home))

assert expand_whatsapp_aliases("999999999999999@lid") == {
"999999999999999",
"15551234567",
}


def test_aliases_resolve_on_legacy_layout(tmp_path, monkeypatch):
tmp_home = tmp_path / "hermes-home"
mapping_dir = tmp_home / "whatsapp" / "session"
mapping_dir.mkdir(parents=True, exist_ok=True)
(mapping_dir / "lid-mapping-999999999999999.json").write_text(
json.dumps("15551234567@s.whatsapp.net"),
encoding="utf-8",
)
monkeypatch.setenv("HERMES_HOME", str(tmp_home))

assert expand_whatsapp_aliases("999999999999999@lid") == {
"999999999999999",
"15551234567",
}
Loading