The simulator answers a wrong admin password with silence

A stock repeater sends no reply for a wrong password: handleLoginReq returns 0,
and the companion pushes LOGIN_FAILED only when a reply arrives that is not "OK".
The simulator refused a wrong password instead, so --mock and the tests never
walked the path of #28. Now a wrong password gets NO_REPLY from the simulator,
and only a node in its new _refusing set refuses, as other firmware can.

The comments that said the firmware sends a refusal now say what it does. A new
test walks #28 from end to end on the simulator: the stored password gets
silence, the user selects "New password…", and the repeater accepts the new one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5.5 committed 2026-11-03 23:57:32 -05:00
1 parent bde5ee19f5
commit e8a3b439cd
5 files changed
+106 -19

No files matched your search

+5
View File
@@ -152,6 +152,11 @@ class AdminStore:
down at that time, MeshTerm deleted its password. The node sent nothing at all, and
MeshTerm read that silence as a refusal.
A stock node never refuses: it does not answer a wrong password. Thus a password
that the owner changed also stays here after its silence. The caller then offers a
new password, which replaces this one when the node accepts it (refer to
:mod:`meshterm.ui.admin_login`).
The callers still write their own messages (the sweep says "sweep again", the CLI
says "re-run"), but no caller makes this decision.
+18 -6
View File
@@ -1408,7 +1408,10 @@ class Device(ABC):
``if not await device.admin_login(...)``. A caller that acts on the failure
must tell :attr:`~LoginResult.REFUSED` (the node said no: the password is
wrong) from :attr:`~LoginResult.NO_REPLY` (nothing came back: the password is
not proved correct, and not proved wrong).
not proved correct, and not proved wrong). A stock repeater or room server
never says no: it does not answer a wrong password. Thus a wrong password
is usually :attr:`~LoginResult.NO_REPLY` (refer to
:mod:`meshterm.ui.admin_login`).
"""
@abstractmethod
@@ -3616,10 +3619,12 @@ class MeshCoreDevice(Device):
# ``send_login_sync`` waits for LOGIN_SUCCESS and *only* LOGIN_SUCCESS, and it does
# not start to wait until its own send has returned. Thus:
#
# * It never waits for a refusal. (The firmware does send a refusal, as a
# LOGIN_FAILED frame that the library parses and dispatches like any other
# event.) The refusal times out exactly like a node that MeshTerm cannot reach.
# Both types of failure came back as the same ``None``.
# * It never waits for a refusal. (The companion sends a refusal as a LOGIN_FAILED
# frame, which the library parses and dispatches like any other event. The
# companion sends it when a reply arrives that is not "OK". A stock repeater
# sends no reply at all for a wrong password, but other firmware can refuse.)
# The refusal times out exactly like a node that MeshTerm cannot reach. Both
# types of failure came back as the same ``None``.
# * A worse case, for a node that MeshTerm can reach with no problem: the send
# itself blocks until a MSG_SENT arrives. The library correlates that
# acknowledgement only by its event type. Thus a scheduled advert, a telemetry
@@ -4904,6 +4909,11 @@ class MockDevice(Device):
# down. There, a login comes back NO_REPLY, and the remembered credential must
# survive it.
self._unreachable: set[str] = set()
# Nodes that answer a wrong password with a refusal. A stock repeater sends no reply
# for a wrong password (``handleLoginReq`` returns 0), so a wrong password gets
# NO_REPLY from the simulator by default, as on a real mesh (GitHub issue 28). Put
# the name of a contact here to walk the path of firmware that refuses.
self._refusing: set[str] = set()
self._remote_tx: dict[str, int] = {}
self._default_remote_tx = 20
# The settings of each simulated repeater, as its CLI shows them. MeshTerm fills
@@ -5146,7 +5156,9 @@ class MockDevice(Device):
if node.name in self._unreachable:
return LoginResult.NO_REPLY # simulates a node that is down or out of range
if password != self._admin_password:
return LoginResult.REFUSED
# Stock firmware sends nothing for a wrong password, so the simulator does the
# same. A node in ``_refusing`` runs firmware that says no.
return LoginResult.REFUSED if node.name in self._refusing else LoginResult.NO_REPLY
self._admin_sessions.add(self._mock_key(node))
return LoginResult.ACCEPTED
+9 -3
View File
@@ -82,6 +82,11 @@ class LoginResult(Enum):
tells nothing about the password: the node may be asleep or out of range, or the reply
may be lost on its way back. Thus the credential must stay after a silence.
But a stock repeater or room server never refuses. It sends no reply at all for a
wrong password. Thus a password that the owner changed also comes back as silence, and
the menu offers the user a new password when a stored one gets no reply (refer to
:mod:`meshterm.ui.admin_login`).
The value is truthy only when the session opened. Thus the old idiom
``if not await device.admin_login(...)`` still means "we are not logged in". The code
tells the two failures apart by identity. Thus each call site must say which failure
@@ -90,10 +95,11 @@ class LoginResult(Enum):
#: The node accepted the password. An admin session is open.
ACCEPTED = "accepted"
#: The node answered and said no. The stored password is wrong. Forget it.
#: The node answered and said no. The stored password is wrong. Forget it. Only
#: firmware other than stock MeshCore gives this result.
REFUSED = "refused"
#: No reply came back. The node is out of range or asleep, or the reply was lost. Keep
#: the password.
#: No reply came back. The node is out of range or asleep, the reply was lost, or the
#: password is wrong (a stock node does not answer a wrong password). Keep the password.
NO_REPLY = "no_reply"
def __bool__(self) -> bool:
+66 -9
View File
@@ -6,10 +6,15 @@ password of that repeater. The login returned ``False``. Each caller read ``Fals
"wrong password", and MeshTerm deleted the credential for a node that never answered.
Two faults caused this. First, the ``meshcore`` library function ``send_login_sync`` waits
for ``LOGIN_SUCCESS`` and for nothing else. The firmware does send a refusal (a
``LOGIN_FAILED`` frame), but the function times out on it in the same way as on silence,
and returns the same ``None``. Second, the credential policy was in five places, at the
call sites.
for ``LOGIN_SUCCESS`` and for nothing else. The companion does send a refusal (a
``LOGIN_FAILED`` frame) when a node says no, but the function times out on it in the same
way as on silence, and returns the same ``None``. Second, the credential policy was in five
places, at the call sites.
A stock repeater never says no: it sends no reply for a wrong password. Thus a password
that the owner changed is also a silence, and the menu offers a new password when a stored
one gets no reply (GitHub issue 28). The simulator does the same, and only a node in its
``_refusing`` set refuses.
Now the device listens for the refusal frame itself and returns a three-way
:class:`~meshterm.core.models.LoginResult`. One method,
@@ -420,6 +425,23 @@ def test_a_known_short_route_never_buys_less_patience_than_no_route_at_all() ->
# --- the simulator gives the same three results ---------------------------------------
async def test_the_simulator_answers_a_wrong_password_as_stock_firmware_does() -> None:
"""A stock repeater sends nothing for a wrong password. Only a ``_refusing`` node says no.
The simulator once refused a wrong password. Thus ``--mock`` and the tests never walked
the path of GitHub issue 28: a password that the owner changed, which comes back as
silence on a real mesh.
"""
device = MockDevice(admin_password="secret")
await device.connect()
node = (await device.get_contacts())[0]
assert await device.admin_login(node, "wrong") is LoginResult.NO_REPLY
device._refusing.add(node.name)
assert await device.admin_login(node, "wrong") is LoginResult.REFUSED
assert await device.admin_login(node, "secret") is LoginResult.ACCEPTED
async def test_the_simulator_can_model_a_node_that_is_simply_down() -> None:
"""``--mock`` must be able to follow the path of a down repeater, or nobody sees the dialog."""
device = MockDevice(admin_password="secret")
@@ -450,12 +472,18 @@ def ctx(tmp_path: Path):
context.repo.close()
async def _mock_node(ctx, *, down: bool) -> Contact: # noqa: ANN001
"""The simulated repeater, unreachable if ``down`` is true, with a stored password."""
async def _mock_node(ctx, *, down: bool, refusing: bool = False) -> Contact: # noqa: ANN001
"""The simulated repeater, with a stored password.
It is unreachable if ``down`` is true. If ``refusing`` is true, it refuses a wrong
password, as firmware other than stock MeshCore can. Else it does not answer one.
"""
device = await ctx.device()
node = next(c for c in await device.get_contacts() if c.name == "Yagi-Repeater")
if down:
device._unreachable.add(node.name)
if refusing:
device._refusing.add(node.name)
ctx.admin_store.remember(node, "admin")
return node
@@ -517,7 +545,7 @@ async def test_the_scripted_tool_clears_the_password_the_node_rejected(ctx) -> N
"""The other half: a node that is reachable and says no has a bad password."""
from meshterm.tools.repeater_admin import RepeaterAdminTool
node = await _mock_node(ctx, down=False)
node = await _mock_node(ctx, down=False, refusing=True)
ctx.admin_store.remember(node, "not-the-password")
with pytest.raises(DeviceCommandError, match="wrong password"):
@@ -542,7 +570,7 @@ async def test_the_tx_optimizer_clears_the_password_the_node_rejected(ctx) -> No
"""The optimizer also forgets a password that the node refused."""
from meshterm.tools.tx_optimize import TxOptimizeTool
node = await _mock_node(ctx, down=False)
node = await _mock_node(ctx, down=False, refusing=True)
ctx.admin_store.remember(node, "not-the-password")
with pytest.raises(DeviceCommandError, match="wrong password"):
@@ -620,7 +648,7 @@ async def test_the_admin_flow_says_no_reply_and_keeps_the_password(ctx) -> None:
async def test_the_admin_flow_still_clears_a_password_the_node_rejected(ctx) -> None: # noqa: ANN001
"""This behaviour was always correct. The test makes sure that it stays correct."""
node = await _mock_node(ctx, down=False)
node = await _mock_node(ctx, down=False, refusing=True)
ctx.admin_store.remember(node, "not-the-password")
ok, shown = await _run_login(ctx, node)
@@ -753,6 +781,35 @@ def test_a_refusal_message_starts_its_sentences_with_a_capital() -> None:
assert saved.endswith("The saved password was cleared; try again to enter a new one.")
async def test_the_admin_flow_replaces_a_changed_password_on_the_simulator(ctx) -> None: # noqa: ANN001
"""GitHub issue 28 from end to end: the owner changed the password with a serial console.
The stored password gets silence from the simulated repeater, as from a real one. The
user selects "New password…", types the new password, and the repeater accepts it.
"""
from meshterm.ui.repeater_admin import _login
from meshterm.ui.surface import TuiUi
from meshterm.ui.tui.prompt import ButtonDialog, TextScreen
from meshterm.ui.tui.session import TuiSession
node = await _mock_node(ctx, down=False)
ctx.admin_store.remember(node, "before-the-change")
ctx.ui = TuiUi(TuiSession())
task = asyncio.ensure_future(_login(ctx, await ctx.device(), node))
try:
offer = await _top(ctx, ButtonDialog)
assert offer is not None and "password changed" in str(offer._prompt)
offer.resolve(True)
(await _top(ctx, TextScreen)).resolve("admin")
ok = await task
finally:
if not task.done():
task.cancel()
assert ok is True
assert ctx.admin_store.get(node) == "admin"
# --- no call site decides this locally again --------------------------------------------
+8 -1
View File
@@ -541,13 +541,20 @@ async def _setup_link(optimal_remote_tx: int = 20):
async def test_admin_login_rejects_wrong_password() -> None:
"""The device refuses a wrong admin password, and the node stays closed to tuning."""
"""A wrong admin password opens nothing, and the node stays closed to tuning.
A stock node does not answer a wrong password, so the simulator gives no reply. A node
whose firmware refuses (``_refusing``) says no.
"""
from meshterm.core.connection import LoginResult
device = MockDevice(admin_password="secret")
await device.connect()
admin = (await device.get_contacts())[0]
silent = await device.admin_login(admin, "nope")
assert silent is LoginResult.NO_REPLY and not silent
device._refusing.add(admin.name)
refused = await device.admin_login(admin, "nope")
assert refused is LoginResult.REFUSED and not refused
with pytest.raises(DeviceCommandError):