auth dialog: keep typed text when the polkit helper ends before asking
CI / test (push) Successful in 2m1s

If polkit-agent-helper-1 exited (or the socket service refused) before
sending a PAM prompt, the dialog counted it as a wrong password, wiped the
field and restarted the helper immediately, in a tight loop, so typing
seemed to do nothing. Now such an early end keeps what was typed, shows
why, and retries after 1s/2s/4s (then on Enter). Every helper event and
route is logged as "chandra: polkit helper ..." (never the typed text).

Adds an end-to-end test that types through handle_input with a real
xkbcommon keymap, including Shift, across a helper that dies at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hgkRPrAzXECBUGmNEE
This commit is contained in:
Claude committed 2026-11-26 01:31:59 +00:00
1 parent ac2d0fa205
commit fa634956cc
4 files changed
+237 -4

No files matched your search

+133
View File
@@ -430,3 +430,136 @@ test "Settings > Session lists the password dialog switch, saved as :auth-agent
assert_false(comp.shell.native_auth_agent)
comp.close()
}
///|
test "typing reaches the dialog through handle_input, and a helper that dies at once doesn't wipe it in a loop" {
let bus = match auth_bus("typing") {
Some(b) => b
None => return
}
let a = MockAuthority::new(bus)
let hpath = "/tmp/chandra-auth-helper-typing-" + @sys.getpid().to_string()
let listen = @sys.unix_listen(hpath)
let comp = auth_comp("typing", bus, hpath)
// The keymap the real session hands clients (xkbcommon's text format), not the US fallback.
comp.server.set_keymap(@utf8.encode(real_keymap))
assert_true(settle(comp, a, fn() { comp.polkit.map(p => p.registered()).unwrap_or(false) }))
a.begin("t1", run0_details)
assert_true(settle(comp, a, fn() { comp.auth_dialog() is Some(_) }))
let d = comp.auth_dialog().unwrap()
// The helper goes away without a word (socket helper refusing, account locked, ...).
let (h, _) = helper_accept(listen, comp, a)
@sys.close_fd(h)
assert_true(settle(comp, a, fn() { d.error != "" }))
assert_eq(d.failures, 0) // not a wrong password
// Typing still lands in the field and stays there.
auth_type(comp, "Secret9")
for i = 0; i < 20; i = i + 1 {
a.bus.pump()
comp.step()
}
assert_eq(d.typed(), 7)
// Shift+digit through the real keymap: '(' on 9.
comp.handle_input(@nested.InputEvent::Modifiers(1U, 0U, 0U, 0U), 1U)
auth_press(comp, 10U)
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
assert_eq(d.typed(), 8)
auth_press(comp, 28U) // Enter: kept until PAM asks
// A second later the helper is started again; this time it asks.
let (h2, hello) = helper_accept(listen, comp, a)
assert_eq(hello, "nandi|t1")
helper_say(h2, "PAM_PROMPT_ECHO_OFF Password: ")
assert_true(settle(comp, a, fn() { d.phase == Checking }))
assert_eq(helper_lines(h2, 1), "Secret9(")
// The pointer works too: a click on Cancel dismisses it.
helper_say(h2, "FAILURE")
assert_true(settle(comp, a, fn() { d.failures == 1 }))
ignore(comp.compose_frame())
let cancel = comp.auth.unwrap().hits.filter(x => x.1 == Cancel)[0].0
comp.handle_input(@nested.InputEvent::PointerMove((cancel.x + 4).to_double(), (cancel.y + 4).to_double()), 1U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 3U)
assert_true(settle(comp, a, fn() { a.answers.length() == 1 }))
@sys.close_fd(h2)
@sys.close_fd(listen)
@sys.unlink(hpath)
comp.close()
}
///| An xkbcommon 1.6 keymap (xkbcli compile-keymap --layout us), cut down to what typing needs.
let real_keymap : String =
#|xkb_keymap {
#|xkb_keycodes "(unnamed)" {
#| minimum = 8;
#| maximum = 708;
#| <ESC> = 9;
#| <AE01> = 10;
#| <AE02> = 11;
#| <AE09> = 18;
#| <AE10> = 19;
#| <AD01> = 24;
#| <AD02> = 25;
#| <AD03> = 26;
#| <AD04> = 27;
#| <AD05> = 28;
#| <AC01> = 38;
#| <AC02> = 39;
#| <AB03> = 54;
#| <AB07> = 58;
#| <AB06> = 57;
#| <SPCE> = 65;
#| indicator 1 = "Caps Lock";
#| alias <AC12> = <BKSL>;
#|};
#|
#|xkb_types "(unnamed)" {
#| virtual_modifiers NumLock,Alt,LevelThree,LevelFive,Meta,Super,Hyper,ScrollLock;
#| type "ONE_LEVEL" {
#| modifiers= none;
#| level_name[1]= "Any";
#| };
#| type "ALPHABETIC" {
#| modifiers= Shift+Lock;
#| map[Shift]= 2;
#| map[Lock]= 2;
#| level_name[1]= "Base";
#| level_name[2]= "Caps";
#| };
#|};
#|
#|xkb_compatibility "(unnamed)" {
#| virtual_modifiers NumLock,Alt,LevelThree,LevelFive,Meta,Super,Hyper,ScrollLock;
#| interpret.useModMapMods= AnyLevel;
#| interpret Shift_L+AnyOf(all) {
#| action= SetMods(modifiers=Shift,clearLocks);
#| };
#| indicator "Caps Lock" {
#| whichModState= locked;
#| modifiers= Lock;
#| };
#|};
#|
#|xkb_symbols "(unnamed)" {
#| name[Group1]="English (US)";
#|
#| key <ESC> { [ Escape ] };
#| key <AE01> { [ 1, exclam ] };
#| key <AE02> { [ 2, at ] };
#| key <AE09> { [ 9, parenleft ] };
#| key <AE10> { [ 0, parenright ] };
#| key <AD01> { [ q, Q ] };
#| key <AD02> { [ w, W ] };
#| key <AD03> { [ e, E ] };
#| key <AD04> { [ r, R ] };
#| key <AD05> { [ t, T ] };
#| key <AC01> { [ a, A ] };
#| key <AC02> { [ s, S ] };
#| key <AB03> { [ c, C ] };
#| key <AB06> { [ n, N ] };
#| key <AB07> { [ m, M ] };
#| key <SPCE> { [ space ] };
#| modifier_map Shift { <LFSH>, <RTSH> };
#| modifier_map Lock { <CAPS> };
#|};
#|
#|};