Password dialog rebuilt: a separate polkit agent, one state machine, explicit errors
CI / test (push) Canceled after 21m14s
CI / test (push) Canceled after 21m14s
The first version ran polkit registration, polkit-agent-helper-1, the PAM conversation and the drawing inside the compositor's frame loop, with overlapping state in two layers. A helper that quit before asking was taken for a wrong password and restarted in a loop that wiped the field (typing seemed dead), a refused registration quietly started a third-party agent, and the dialog and the Face unlock window each grabbed the keyboard. Now: - chandra-polkit-agent (compositor/authagent, /usr/local/lib/chandra) does polkit and PAM. Each request runs one state machine (polkit/machine.mbt: starting, asking, checking, failed, done). A check that quits or can't start is Failed with the reason and waits for Try again; only a wrong password starts the next check by itself. It logs each step to stderr (the session log), never the typed text. - The compositor starts it on a socket pair and only draws what it says (host/auth.mbt, auth_draw.mbt; line protocol in polkit/wire.mbt). One input owner (grab_input): the dialog, else the Face unlock window. - No silent fallback: if the agent can't run, polkit refuses it, polkit doesn't answer in 10 s, or it dies, a notice on screen says why (a crash after it ran restarts it, up to 3 times, and says so). The third-party agent runs only when the Settings switch is off. - chandra-ctl auth-demo [password|face|face-ok|die|slow|users] shows the real dialog with a pretend check (password "demo"), no root needed; chandra-ctl auth-status says whether the agent is registered. - just install builds and installs the agent (just auth-agent). Tests: polkit_test (link, machine, view, helper Gone) and auth_test end to end through handle_input: the agent loop in-process against a mock polkit on a private dbus-daemon plus a mock helper, and the real agent program spawned by the compositor (demo, and registered with the mock polkit). Typing on a real xkb keymap, wrong password, cancel, withdrawal, helper quitting early or missing, polkit refusing, agent not starting or crashing, demo modes, Face unlock Apply. 170/170 host and 20/20 polkit tests pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hgkRPrAzXECBUGmNEE
This commit is contained in:
22 files changed
+3462
-1806
No files matched your search
+499
-222
@@ -1,7 +1,8 @@
|
||||
///| Chandra's polkit agent and its dialog, against a mock polkit Authority on a private bus
|
||||
/// (a real dbus-daemon) and a mock polkit-agent-helper-1 on a socket (the protocol polkit 126's
|
||||
/// socket-activated helper speaks). Set CHANDRA_AUTH_SHOTS to a folder to get a PNG of each
|
||||
/// dialog state.
|
||||
///| Chandra's password dialog end to end: the compositor, chandra-polkit-agent's loop (run
|
||||
/// in-process on a socket pair, and as the real program), a mock polkit Authority on a private
|
||||
/// bus (a real dbus-daemon) and a mock polkit-agent-helper-1 on a socket (the protocol polkit
|
||||
/// 126's socket-activated helper speaks). Set CHANDRA_AUTH_SHOTS to a folder to get a PNG of
|
||||
/// each dialog state.
|
||||
|
||||
///| A private message bus for the test (dbus-daemon's session config), its socket path.
|
||||
fn auth_bus(tag : String) -> String? {
|
||||
@@ -72,9 +73,9 @@ fn MockAuthority::new(path : String) -> MockAuthority {
|
||||
}
|
||||
|
||||
///| Ask the agent to authenticate, like polkitd does for run0.
|
||||
fn MockAuthority::begin(self : MockAuthority, cookie : String, details : Array[(String, String)]) -> Unit {
|
||||
fn MockAuthority::begin(self : MockAuthority, cookie : String, details : Array[(String, String)], uid? : UInt = 1000) -> Unit {
|
||||
let ids : Array[@network.DValue] = [
|
||||
Struct([Str("unix-user"), @network.dict("v", [("uid", Variant(U32(1000)))])]),
|
||||
Struct([Str("unix-user"), @network.dict("v", [("uid", Variant(U32(uid)))])]),
|
||||
Struct([Str("unix-group"), @network.dict("v", [("gid", Variant(U32(10)))])]),
|
||||
]
|
||||
ignore(
|
||||
@@ -112,28 +113,85 @@ fn fake_request(args : Array[@network.DValue]) -> @polkit.AuthRequest? {
|
||||
}
|
||||
}
|
||||
|
||||
///| A compositor with the agent on `bus` and the helper at `helper` (a socket we listen on).
|
||||
fn auth_comp(tag : String, bus : String, helper : String) -> @host.ChandraCompositor {
|
||||
let comp = new_comp("auth-" + tag)
|
||||
comp.auth_routes = [Socket(helper)]
|
||||
comp.auth_describe = Some(fn(req) {
|
||||
@polkit.describe(
|
||||
req,
|
||||
cmdline=pid => if pid == 15802 { ["run0", "gparted", "/dev/nvme0n1"] } else { [] },
|
||||
who=pid => "run0 (pid " + pid.to_string() + "), started from konsole",
|
||||
)
|
||||
})
|
||||
let subject = @network.DValue::Struct([Str("unix-session"), @network.dict("v", [("session-id", Variant(Str("2")))])])
|
||||
comp.polkit = Some(@polkit.PolkitAgent::new(bus_path=bus, subject~, make_request=fake_request))
|
||||
comp.start_auth_agent()
|
||||
comp
|
||||
///| A connected pair of stream sockets: (the compositor's end, the agent's end).
|
||||
fn sock_pair(tag : String) -> (Int, Int) {
|
||||
let path = "/tmp/chandra-auth-link-" + tag + "-" + @sys.getpid().to_string()
|
||||
@sys.unlink(path)
|
||||
let l = @sys.unix_listen(path)
|
||||
let c = @sys.unix_connect(path)
|
||||
let mut s = -1
|
||||
for i = 0; i < 100 && s < 0; i = i + 1 {
|
||||
s = @sys.unix_accept(l)
|
||||
if s < 0 {
|
||||
@sys.sleep_ms(5)
|
||||
}
|
||||
}
|
||||
@sys.close_fd(l)
|
||||
@sys.unlink(path)
|
||||
(c, s)
|
||||
}
|
||||
|
||||
///| Run both ends until `cond` holds (or about two seconds pass).
|
||||
fn settle(comp : @host.ChandraCompositor, a : MockAuthority, cond : () -> Bool) -> Bool {
|
||||
for i = 0; i < 200; i = i + 1 {
|
||||
a.bus.pump()
|
||||
comp.step()
|
||||
///| A compositor, the mock polkitd (when there is a bus), and the agents it started in-process.
|
||||
struct Rig {
|
||||
comp : @host.ChandraCompositor
|
||||
a : MockAuthority?
|
||||
agents : Array[@polkit.AgentLoop]
|
||||
}
|
||||
|
||||
///| A compositor whose agents run in this process: the session's on `bus` with the helper at
|
||||
/// `helper` (a socket the test listens on), demos as `chandra-ctl auth-demo` starts them.
|
||||
fn rig(tag : String, bus : String?, helper : String) -> Rig {
|
||||
let comp = new_comp("auth-" + tag)
|
||||
comp.login_session = true
|
||||
let a = bus.map(b => MockAuthority::new(b))
|
||||
let agents : Array[@polkit.AgentLoop] = []
|
||||
let n : Ref[Int] = { val: 0 }
|
||||
comp.auth_spawner = Some(fn(args) {
|
||||
n.val = n.val + 1
|
||||
let (mine, theirs) = sock_pair(tag + "-" + n.val.to_string())
|
||||
let ag = match args {
|
||||
["--demo", mode] => @polkit.AgentLoop::new_demo(theirs, mode)
|
||||
_ => {
|
||||
let subject = @network.DValue::Struct([Str("unix-session"), @network.dict("v", [("session-id", Variant(Str("2")))])])
|
||||
@polkit.AgentLoop::new(
|
||||
theirs,
|
||||
@polkit.PolkitAgent::new(bus_path=bus.unwrap_or("/nonexistent/bus"), subject~, make_request=fake_request),
|
||||
routes=[Socket(helper)],
|
||||
describer=fn(req) {
|
||||
@polkit.describe(
|
||||
req,
|
||||
cmdline=pid => if pid == 15802 { ["run0", "gparted", "/dev/nvme0n1"] } else { [] },
|
||||
who=pid => "run0 (pid " + pid.to_string() + "), started from konsole",
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
ag.start()
|
||||
agents.push(ag)
|
||||
mine
|
||||
})
|
||||
{ comp, a, agents }
|
||||
}
|
||||
|
||||
///| One pass of everything: polkitd, the agents, the compositor.
|
||||
fn Rig::pass(self : Rig) -> Unit {
|
||||
match self.a {
|
||||
Some(a) => a.bus.pump()
|
||||
None => ()
|
||||
}
|
||||
for ag in self.agents {
|
||||
if !ag.finished() {
|
||||
ag.step()
|
||||
}
|
||||
}
|
||||
self.comp.step()
|
||||
}
|
||||
|
||||
///| Run everything until `cond` holds (or about six seconds pass).
|
||||
fn Rig::settle(self : Rig, cond : () -> Bool) -> Bool {
|
||||
for i = 0; i < 600; i = i + 1 {
|
||||
self.pass()
|
||||
if cond() {
|
||||
return true
|
||||
}
|
||||
@@ -142,10 +200,25 @@ fn settle(comp : @host.ChandraCompositor, a : MockAuthority, cond : () -> Bool)
|
||||
false
|
||||
}
|
||||
|
||||
///| The mock helper's side of one session: accept, read the user and cookie lines.
|
||||
fn helper_accept(listen : Int, comp : @host.ChandraCompositor, a : MockAuthority) -> (Int, String) {
|
||||
///| The session's agent registered with polkit.
|
||||
fn Rig::ready(self : Rig) -> Bool {
|
||||
self.comp.auth_agent.map(l => l.ready).unwrap_or(false)
|
||||
}
|
||||
|
||||
///| The mock polkitd.
|
||||
fn Rig::authority(self : Rig) -> MockAuthority {
|
||||
self.a.unwrap()
|
||||
}
|
||||
|
||||
///| The dialog's view (aborts when none is up).
|
||||
fn Rig::view(self : Rig) -> @polkit.AuthView {
|
||||
self.comp.auth_view().unwrap()
|
||||
}
|
||||
|
||||
///| The mock helper's side of one check: accept, read the user and cookie lines.
|
||||
fn Rig::helper_accept(self : Rig, listen : Int) -> (Int, String) {
|
||||
let fd : Ref[Int] = { val: -1 }
|
||||
ignore(settle(comp, a, fn() {
|
||||
ignore(self.settle(fn() {
|
||||
if fd.val < 0 {
|
||||
fd.val = @sys.unix_accept(listen)
|
||||
}
|
||||
@@ -157,7 +230,7 @@ fn helper_accept(listen : Int, comp : @host.ChandraCompositor, a : MockAuthority
|
||||
(fd.val, helper_lines(fd.val, 2))
|
||||
}
|
||||
|
||||
///| Read `n` lines from the agent (joined with '|').
|
||||
///| Read `n` lines (joined with '|').
|
||||
fn helper_lines(fd : Int, n : Int) -> String {
|
||||
let buf : FixedArray[Byte] = FixedArray::make(1024, b'\x00')
|
||||
let got : Array[Byte] = []
|
||||
@@ -216,14 +289,30 @@ fn auth_press(comp : @host.ChandraCompositor, code : UInt) -> Unit {
|
||||
comp.handle_input(@nested.InputEvent::Key(code, false), 1U)
|
||||
}
|
||||
|
||||
///| Alt+key.
|
||||
fn auth_alt(comp : @host.ChandraCompositor, code : UInt) -> Unit {
|
||||
comp.handle_input(@nested.InputEvent::Modifiers(8U, 0U, 0U, 0U), 1U)
|
||||
auth_press(comp, code)
|
||||
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
|
||||
}
|
||||
|
||||
///| Click the dialog's control `f`.
|
||||
fn auth_click(comp : @host.ChandraCompositor, f : @polkit.Focus) -> Unit {
|
||||
ignore(comp.compose_frame())
|
||||
let r = comp.auth.unwrap().hits.filter(x => x.1 == f)[0].0
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((r.x + 4).to_double(), (r.y + 4).to_double()), 1U)
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 3U)
|
||||
}
|
||||
|
||||
///| Save the screen as `<CHANDRA_AUTH_SHOTS>/<name>.png` when that is set.
|
||||
fn auth_shot(comp : @host.ChandraCompositor, name : String) -> Unit {
|
||||
let dir = @sys.getenv("CHANDRA_AUTH_SHOTS")
|
||||
if dir == "" {
|
||||
return
|
||||
}
|
||||
match comp.auth_dialog() {
|
||||
Some(d) => d.shake_at = 0UL // the card at rest
|
||||
match comp.auth_view() {
|
||||
Some(v) => v.shake_at = 0UL // the card at rest
|
||||
None => ()
|
||||
}
|
||||
comp.damage.mark_full()
|
||||
@@ -240,87 +329,90 @@ let run0_details : Array[(String, String)] = [
|
||||
("polkit.caller-pid", "1"),
|
||||
]
|
||||
|
||||
///| A private bus and a listening mock helper socket for test `tag`.
|
||||
fn helper_socket(tag : String) -> (String, Int) {
|
||||
let hpath = "/tmp/chandra-auth-helper-" + tag + "-" + @sys.getpid().to_string()
|
||||
@sys.unlink(hpath)
|
||||
(hpath, @sys.unix_listen(hpath))
|
||||
}
|
||||
|
||||
///|
|
||||
test "polkit asks for run0: the dialog shows the command, a wrong password shakes, the right one authorizes" {
|
||||
let bus = match auth_bus("ok") {
|
||||
Some(b) => b
|
||||
None => return // no dbus-daemon here
|
||||
}
|
||||
let a = MockAuthority::new(bus)
|
||||
let hpath = "/tmp/chandra-auth-helper-ok-" + @sys.getpid().to_string()
|
||||
let listen = @sys.unix_listen(hpath)
|
||||
let comp = auth_comp("ok", bus, hpath)
|
||||
assert_true(settle(comp, a, fn() { comp.polkit.map(p => p.registered()).unwrap_or(false) }))
|
||||
let (hpath, listen) = helper_socket("ok")
|
||||
let r = rig("ok", Some(bus), hpath)
|
||||
r.comp.start_auth_agent()
|
||||
assert_true(r.settle(fn() { r.ready() }))
|
||||
let a = r.authority()
|
||||
assert_true(a.agent != "")
|
||||
a.begin("cookie-1", run0_details)
|
||||
assert_true(settle(comp, a, fn() { comp.auth_dialog() is Some(_) }))
|
||||
let d = comp.auth_dialog().unwrap()
|
||||
assert_eq(d.desc.title, "Run a command as root")
|
||||
assert_eq(d.desc.command, "gparted /dev/nvme0n1")
|
||||
assert_true(r.settle(fn() { r.comp.auth_view() is Some(_) }))
|
||||
let d = r.view()
|
||||
assert_eq(d.title, "Run a command as root")
|
||||
assert_eq(d.command, "gparted /dev/nvme0n1")
|
||||
// The user at the screen comes first; the wheel group adds ada.
|
||||
assert_eq(d.req.users.map(u => u.name), ["nandi", "ada"])
|
||||
assert_eq(d.users.map(u => u.name), ["nandi", "ada"])
|
||||
// The helper is asked for nandi with polkit's cookie.
|
||||
let (h, hello) = helper_accept(listen, comp, a)
|
||||
let (h, hello) = r.helper_accept(listen)
|
||||
assert_eq(hello, "nandi|cookie-1")
|
||||
auth_shot(comp, "01-starting")
|
||||
auth_shot(r.comp, "01-starting")
|
||||
helper_say(h, "PAM_PROMPT_ECHO_OFF Password: ")
|
||||
assert_true(settle(comp, a, fn() { d.phase == Prompt }))
|
||||
auth_shot(comp, "02-idle")
|
||||
auth_type(comp, "Hunter2")
|
||||
assert_true(r.settle(fn() { d.phase == Asking }))
|
||||
auth_shot(r.comp, "02-idle")
|
||||
auth_type(r.comp, "Hunter2")
|
||||
assert_eq(d.typed(), 7)
|
||||
auth_shot(comp, "03-typing")
|
||||
auth_shot(r.comp, "03-typing")
|
||||
// Caps Lock on shows a warning.
|
||||
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 2U, 0U), 1U)
|
||||
r.comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 2U, 0U), 1U)
|
||||
assert_true(d.caps)
|
||||
auth_shot(comp, "04-caps-lock")
|
||||
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
|
||||
auth_press(comp, 28U) // Enter
|
||||
auth_shot(r.comp, "04-caps-lock")
|
||||
r.comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
|
||||
auth_press(r.comp, 28U) // Enter
|
||||
assert_eq(d.typed(), 0) // wiped once sent
|
||||
assert_true(r.settle(fn() { d.phase == Checking }))
|
||||
assert_eq(helper_lines(h, 1), "Hunter2")
|
||||
assert_eq(d.phase, Checking)
|
||||
auth_shot(comp, "05-busy")
|
||||
// Wrong: the helper fails and exits; the dialog says so and starts a new session.
|
||||
auth_shot(r.comp, "05-busy")
|
||||
// Wrong: the helper fails and exits; the dialog shakes, says so, and a new check starts.
|
||||
helper_say(h, "FAILURE")
|
||||
@sys.close_fd(h)
|
||||
assert_true(settle(comp, a, fn() { d.failures == 1 }))
|
||||
assert_true(r.settle(fn() { d.failures == 1 }))
|
||||
assert_eq(d.error, "Wrong password. Try again.")
|
||||
let (h2, hello2) = helper_accept(listen, comp, a)
|
||||
assert_true(d.shake_at != 0UL)
|
||||
let (h2, hello2) = r.helper_accept(listen)
|
||||
assert_eq(hello2, "nandi|cookie-1")
|
||||
helper_say(h2, "PAM_PROMPT_ECHO_OFF Password: ")
|
||||
assert_true(settle(comp, a, fn() { d.phase == Prompt }))
|
||||
auth_shot(comp, "06-wrong-password")
|
||||
assert_true(r.settle(fn() { d.phase == Asking }))
|
||||
auth_shot(r.comp, "06-wrong-password")
|
||||
// Details, then the right password.
|
||||
comp.handle_input(@nested.InputEvent::Modifiers(8U, 0U, 0U, 0U), 1U)
|
||||
auth_press(comp, 32U) // Alt+D
|
||||
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
|
||||
auth_alt(r.comp, 32U) // Alt+D
|
||||
assert_true(d.details_open)
|
||||
auth_type(comp, "hunter2")
|
||||
auth_shot(comp, "07-details")
|
||||
// Revealed text, then the light theme.
|
||||
comp.handle_input(@nested.InputEvent::Modifiers(8U, 0U, 0U, 0U), 1U)
|
||||
auth_press(comp, 19U) // Alt+R
|
||||
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
|
||||
auth_type(r.comp, "hunter2")
|
||||
auth_shot(r.comp, "07-details")
|
||||
auth_alt(r.comp, 19U) // Alt+R: show it
|
||||
assert_true(d.reveal)
|
||||
auth_shot(comp, "08-revealed")
|
||||
comp.theme = @scene.ThemeTokens::moon_day()
|
||||
auth_shot(comp, "09-light")
|
||||
comp.handle_input(@nested.InputEvent::Modifiers(8U, 0U, 0U, 0U), 1U)
|
||||
auth_press(comp, 19U)
|
||||
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
|
||||
auth_press(comp, 32U) // Alt is up: 'd' goes into the field
|
||||
auth_press(comp, 14U) // and Backspace takes it out
|
||||
auth_shot(comp, "10-light-details")
|
||||
auth_press(comp, 96U) // keypad Enter
|
||||
auth_shot(r.comp, "08-revealed")
|
||||
r.comp.theme = @scene.ThemeTokens::moon_day()
|
||||
auth_shot(r.comp, "09-light")
|
||||
auth_alt(r.comp, 19U)
|
||||
auth_press(r.comp, 32U) // Alt is up: 'd' goes into the field
|
||||
auth_press(r.comp, 14U) // and Backspace takes it out
|
||||
auth_shot(r.comp, "10-light-details")
|
||||
auth_press(r.comp, 96U) // keypad Enter
|
||||
assert_true(r.settle(fn() { d.phase == Checking }))
|
||||
assert_eq(helper_lines(h2, 1), "hunter2")
|
||||
helper_say(h2, "SUCCESS")
|
||||
assert_true(settle(comp, a, fn() { comp.auth_dialog() is None }))
|
||||
assert_true(settle(comp, a, fn() { a.answers.length() == 1 }))
|
||||
assert_true(r.settle(fn() { r.comp.auth_view() is None && a.answers.length() == 1 }))
|
||||
assert_eq(a.answers, ["ok"])
|
||||
// Key releases after the dialog closed don't leak to clients (nothing swallowed is left).
|
||||
assert_eq(comp.auth_swallow.length(), 0)
|
||||
assert_eq(r.comp.auth_swallow.length(), 0)
|
||||
assert_true(r.comp.auth_notice_text() is None)
|
||||
@sys.close_fd(h2)
|
||||
@sys.close_fd(listen)
|
||||
@sys.unlink(hpath)
|
||||
comp.close()
|
||||
r.comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -329,89 +421,339 @@ test "Escape dismisses: polkitd hears Cancelled; polkitd withdrawing a request c
|
||||
Some(b) => b
|
||||
None => return
|
||||
}
|
||||
let a = MockAuthority::new(bus)
|
||||
let hpath = "/tmp/chandra-auth-helper-cancel-" + @sys.getpid().to_string()
|
||||
let listen = @sys.unix_listen(hpath)
|
||||
let comp = auth_comp("cancel", bus, hpath)
|
||||
assert_true(settle(comp, a, fn() { comp.polkit.map(p => p.registered()).unwrap_or(false) }))
|
||||
let (hpath, listen) = helper_socket("cancel")
|
||||
let r = rig("cancel", Some(bus), hpath)
|
||||
r.comp.start_auth_agent()
|
||||
assert_true(r.settle(fn() { r.ready() }))
|
||||
let a = r.authority()
|
||||
a.begin("c1", run0_details)
|
||||
a.begin("c2", [])
|
||||
assert_true(settle(comp, a, fn() { comp.auth_dialog() is Some(_) }))
|
||||
let (h, _) = helper_accept(listen, comp, a)
|
||||
assert_true(r.settle(fn() { r.comp.auth_view() is Some(_) }))
|
||||
let (h, _) = r.helper_accept(listen)
|
||||
// A fingerprint reader: PAM informs and waits.
|
||||
helper_say(h, "PAM_TEXT_INFO Place your finger on the fingerprint reader")
|
||||
assert_true(settle(comp, a, fn() { comp.auth_dialog().map(d => d.phase == Waiting).unwrap_or(false) }))
|
||||
auth_shot(comp, "11-fingerprint")
|
||||
// Two accounts can answer: Tab to the picker, Right picks ada and restarts the helper.
|
||||
auth_press(comp, 15U)
|
||||
auth_press(comp, 106U)
|
||||
assert_eq(comp.auth_dialog().unwrap().user().map(u => u.name), Some("ada"))
|
||||
let (h2, hello) = helper_accept(listen, comp, a)
|
||||
assert_true(r.settle(fn() { r.view().info != "" }))
|
||||
assert_eq(r.view().phase, Starting)
|
||||
auth_shot(r.comp, "11-fingerprint")
|
||||
// Two accounts can answer: Tab to the picker, Right picks ada and starts a check for her.
|
||||
auth_press(r.comp, 15U)
|
||||
auth_press(r.comp, 106U)
|
||||
let (h2, hello) = r.helper_accept(listen)
|
||||
assert_eq(hello, "ada|c1")
|
||||
assert_true(r.settle(fn() { r.view().user().map(u => u.name) == Some("ada") }))
|
||||
// Face unlock (pam_chandra_face.so): the face row scans, then gives way to the password.
|
||||
helper_say(h2, "PAM_TEXT_INFO Face unlock: looking for ada…")
|
||||
assert_true(settle(comp, a, fn() { comp.auth_dialog().map(d => d.face == Scanning).unwrap_or(false) }))
|
||||
assert_eq(comp.auth_dialog().unwrap().info, "") // the fingerprint message went with nandi's attempt
|
||||
auth_shot(comp, "14-face-scanning")
|
||||
assert_true(r.settle(fn() { r.view().face == Scanning }))
|
||||
assert_eq(r.view().info, "") // the fingerprint message went with nandi's attempt
|
||||
auth_shot(r.comp, "14-face-scanning")
|
||||
helper_say(h2, "PAM_ERROR_MSG Face unlock: face not recognized")
|
||||
helper_say(h2, "PAM_PROMPT_ECHO_OFF Password: ")
|
||||
assert_true(settle(comp, a, fn() { comp.auth_dialog().map(d => d.phase == Prompt).unwrap_or(false) }))
|
||||
assert_eq(comp.auth_dialog().unwrap().face, FaceFailed("Face not recognized"))
|
||||
auth_shot(comp, "15-face-failed")
|
||||
auth_shot(comp, "12-other-account")
|
||||
auth_press(comp, 1U) // Escape
|
||||
assert_true(settle(comp, a, fn() { a.answers.length() == 1 }))
|
||||
assert_true(r.settle(fn() { r.view().phase == Asking }))
|
||||
assert_eq(r.view().face, FaceFailed("Face not recognized"))
|
||||
auth_shot(r.comp, "15-face-failed")
|
||||
auth_shot(r.comp, "12-other-account")
|
||||
auth_press(r.comp, 1U) // Escape
|
||||
assert_true(r.comp.auth_view() is None || r.view().id != "1")
|
||||
assert_true(r.settle(fn() { a.answers.length() == 1 }))
|
||||
assert_eq(a.answers, ["org.freedesktop.PolicyKit1.Error.Cancelled"])
|
||||
// The second request comes up next; polkitd withdraws it.
|
||||
assert_true(settle(comp, a, fn() { comp.auth_dialog().map(d => d.req.cookie == "c2").unwrap_or(false) }))
|
||||
let d2 = comp.auth_dialog().unwrap()
|
||||
assert_eq(d2.desc.title, "Run a command as root") // the unit name in the message still finds run0
|
||||
assert_true(r.settle(fn() { r.comp.auth_view().map(v => v.id == "2").unwrap_or(false) }))
|
||||
assert_eq(r.view().title, "Run a command as root") // the unit name in the message still finds run0
|
||||
ignore(a.bus.call(@network.DMessage::call(a.agent, @polkit.agent_path, @polkit.agent_iface, "CancelAuthentication", [Str("c2")])))
|
||||
assert_true(settle(comp, a, fn() { comp.auth_dialog() is None }))
|
||||
assert_true(settle(comp, a, fn() { a.answers.length() == 2 }))
|
||||
assert_true(r.settle(fn() { r.comp.auth_view() is None }))
|
||||
assert_true(r.settle(fn() { a.answers.length() == 2 }))
|
||||
assert_eq(a.answers[1], "org.freedesktop.PolicyKit1.Error.Cancelled")
|
||||
@sys.close_fd(h)
|
||||
@sys.close_fd(h2)
|
||||
@sys.close_fd(listen)
|
||||
@sys.unlink(hpath)
|
||||
comp.close()
|
||||
r.comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
test "another agent already has the session: ours steps aside" {
|
||||
test "polkit refuses the agent: a notice says why, and no other agent takes over" {
|
||||
let bus = match auth_bus("refuse") {
|
||||
Some(b) => b
|
||||
None => return
|
||||
}
|
||||
let a = MockAuthority::new(bus)
|
||||
a.refuse = "An authentication agent already exists for the given subject"
|
||||
let comp = auth_comp("refuse", bus, "/nonexistent")
|
||||
assert_true(settle(comp, a, fn() { comp.polkit is None }))
|
||||
comp.close()
|
||||
let r = rig("refuse", Some(bus), "/nonexistent")
|
||||
r.authority().refuse = "An authentication agent already exists for the given subject"
|
||||
r.comp.start_auth_agent()
|
||||
assert_true(r.settle(fn() { r.comp.auth_notice_text() is Some(_) }))
|
||||
assert_eq(
|
||||
r.comp.auth_notice_text().unwrap(),
|
||||
"Chandra's password dialog couldn't start: polkit refused the agent: An authentication agent already exists for the given subject.",
|
||||
)
|
||||
assert_true(r.comp.auth_agent is None)
|
||||
assert_false(r.comp.fallback_agent_started)
|
||||
let (out, ok) = r.comp.control_command("auth-status")
|
||||
assert_true(ok)
|
||||
assert_eq(out[0], "agent: not running")
|
||||
auth_shot(r.comp, "16-notice")
|
||||
// A click on it dismisses it.
|
||||
ignore(r.comp.compose_frame())
|
||||
r.comp.handle_input(@nested.InputEvent::PointerMove(640.0, 40.0), 1U)
|
||||
r.comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
|
||||
r.comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 3U)
|
||||
assert_true(r.comp.auth_notice_text() is None)
|
||||
r.comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
test "the helper can't be reached: the dialog says so instead of hanging" {
|
||||
test "the agent can't be started, or quits at start: a notice says so" {
|
||||
// No program to run.
|
||||
let r = rig("nostart", None, "")
|
||||
r.comp.auth_spawner = Some(fn(_) { -1 })
|
||||
r.comp.start_auth_agent()
|
||||
assert_eq(r.comp.auth_notice_text(), Some("Chandra's password dialog couldn't start: could not run chandra-polkit-agent."))
|
||||
r.comp.close()
|
||||
// Started, but polkit can't even be asked (no system bus): its error is the notice.
|
||||
let r2 = rig("nobus", None, "")
|
||||
r2.comp.start_auth_agent()
|
||||
assert_true(r2.settle(fn() { r2.comp.auth_notice_text() is Some(_) }))
|
||||
assert_true(r2.comp.auth_notice_text().unwrap().has_prefix("Chandra's password dialog couldn't start: polkit could not be asked: no system bus at /nonexistent/bus"))
|
||||
r2.comp.close()
|
||||
// It crashes before saying anything.
|
||||
let r3 = rig("crash", None, "")
|
||||
r3.comp.auth_spawner = Some(fn(_) {
|
||||
let (mine, theirs) = sock_pair("crash")
|
||||
@sys.close_fd(theirs)
|
||||
mine
|
||||
})
|
||||
r3.comp.start_auth_agent()
|
||||
assert_true(r3.settle(fn() { r3.comp.auth_notice_text() is Some(_) }))
|
||||
assert_eq(
|
||||
r3.comp.auth_notice_text().unwrap(),
|
||||
"Chandra's password dialog couldn't start: chandra-polkit-agent stopped unexpectedly (see ~/.local/state/chandra/session.log).",
|
||||
)
|
||||
r3.comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
test "the agent stops after it was registered: it is started again, and a notice says so" {
|
||||
let bus = match auth_bus("restart") {
|
||||
Some(b) => b
|
||||
None => return
|
||||
}
|
||||
let r = rig("restart", Some(bus), "/nonexistent")
|
||||
r.comp.start_auth_agent()
|
||||
assert_true(r.settle(fn() { r.ready() }))
|
||||
let first = r.agents[0]
|
||||
first.shutdown() // as if it crashed: its end of the link closes
|
||||
assert_true(r.settle(fn() { r.comp.auth_notice_text() is Some(_) }))
|
||||
assert_true(r.comp.auth_notice_text().unwrap().has_prefix("Chandra's password dialog stopped and was restarted"))
|
||||
assert_true(r.settle(fn() { r.ready() }))
|
||||
assert_eq(r.agents.length(), 2)
|
||||
r.comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
test "polkit's helper can't be reached: the dialog says why and waits; Try again, then Cancel" {
|
||||
let bus = match auth_bus("nohelper") {
|
||||
Some(b) => b
|
||||
None => return
|
||||
}
|
||||
let a = MockAuthority::new(bus)
|
||||
let comp = auth_comp("nohelper", bus, "/nonexistent/helper.socket")
|
||||
assert_true(settle(comp, a, fn() { comp.polkit.map(p => p.registered()).unwrap_or(false) }))
|
||||
let r = rig("nohelper", Some(bus), "/nonexistent/helper.socket")
|
||||
r.comp.start_auth_agent()
|
||||
assert_true(r.settle(fn() { r.ready() }))
|
||||
let a = r.authority()
|
||||
a.begin("c1", run0_details)
|
||||
assert_true(settle(comp, a, fn() { comp.auth_dialog() is Some(_) }))
|
||||
assert_eq(comp.auth_dialog().unwrap().error, "polkit's authentication helper could not be started.")
|
||||
assert_true(r.settle(fn() { r.comp.auth_view() is Some(_) }))
|
||||
let d = r.view()
|
||||
assert_eq(d.phase, Failed)
|
||||
assert_eq(d.error, "polkit's password checker could not be started (tried socket /nonexistent/helper.socket)")
|
||||
assert_eq(d.main_label(), "Try again")
|
||||
auth_shot(r.comp, "17-failed")
|
||||
// Enter tries again (and says the same).
|
||||
auth_press(r.comp, 28U)
|
||||
assert_true(r.settle(fn() { d.phase == Failed }))
|
||||
// Clicking Cancel dismisses it.
|
||||
ignore(comp.compose_frame())
|
||||
let ui = comp.auth.unwrap()
|
||||
let cancel = ui.hits.filter(h => h.1 == Cancel)[0].0
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((cancel.x + 5).to_double(), (cancel.y + 5).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 }))
|
||||
assert_true(comp.auth_dialog() is None)
|
||||
auth_click(r.comp, Cancel)
|
||||
assert_true(r.comp.auth_view() is None)
|
||||
assert_true(r.settle(fn() { a.answers.length() == 1 }))
|
||||
r.comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
test "typing reaches the dialog through handle_input on a real keymap; a check that quits early is not retried behind the user's back" {
|
||||
let bus = match auth_bus("typing") {
|
||||
Some(b) => b
|
||||
None => return
|
||||
}
|
||||
let (hpath, listen) = helper_socket("typing")
|
||||
let r = rig("typing", Some(bus), hpath)
|
||||
// The keymap the real session hands clients (xkbcommon's text format), not the US fallback.
|
||||
r.comp.server.set_keymap(@utf8.encode(real_keymap))
|
||||
r.comp.start_auth_agent()
|
||||
assert_true(r.settle(fn() { r.ready() }))
|
||||
let a = r.authority()
|
||||
a.begin("t1", run0_details)
|
||||
assert_true(r.settle(fn() { r.comp.auth_view() is Some(_) }))
|
||||
let d = r.view()
|
||||
// The helper goes away without a word (socket helper refusing, account locked, ...).
|
||||
let (h, _) = r.helper_accept(listen)
|
||||
@sys.close_fd(h)
|
||||
assert_true(r.settle(fn() { d.phase == Failed }))
|
||||
assert_eq(d.error, "The password check quit before asking for a password.")
|
||||
assert_eq(d.failures, 0) // not a wrong password
|
||||
// Nothing starts another check on its own.
|
||||
for i = 0; i < 30; i = i + 1 {
|
||||
r.pass()
|
||||
@sys.sleep_ms(10)
|
||||
}
|
||||
assert_true(@sys.unix_accept(listen) < 0)
|
||||
// Typing lands in the field and stays there.
|
||||
auth_type(r.comp, "Secret9")
|
||||
assert_eq(d.typed(), 7)
|
||||
// Shift+digit through the real keymap: '(' on 9.
|
||||
r.comp.handle_input(@nested.InputEvent::Modifiers(1U, 0U, 0U, 0U), 1U)
|
||||
auth_press(r.comp, 10U)
|
||||
r.comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
|
||||
assert_eq(d.typed(), 8)
|
||||
// Enter starts a new check, which gets the password when it asks.
|
||||
auth_press(r.comp, 28U)
|
||||
let (h2, hello) = r.helper_accept(listen)
|
||||
assert_eq(hello, "nandi|t1")
|
||||
helper_say(h2, "PAM_PROMPT_ECHO_OFF Password: ")
|
||||
assert_true(r.settle(fn() { d.phase == Checking }))
|
||||
assert_eq(helper_lines(h2, 1), "Secret9(")
|
||||
helper_say(h2, "SUCCESS")
|
||||
assert_true(r.settle(fn() { a.answers == ["ok"] }))
|
||||
@sys.close_fd(h2)
|
||||
@sys.close_fd(listen)
|
||||
@sys.unlink(hpath)
|
||||
r.comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
test "chandra-ctl auth-demo: the dialog without root; wrong, then the demo password" {
|
||||
let r = rig("demo", None, "")
|
||||
let (out, ok) = r.comp.control_command("auth-demo")
|
||||
assert_true(ok)
|
||||
assert_eq(out, ["ok the demo dialog opens; the password is \"demo\""])
|
||||
assert_true(r.settle(fn() { r.comp.auth_view().map(v => v.phase == Asking).unwrap_or(false) }))
|
||||
let d = r.view()
|
||||
assert_eq(d.command, "run0 systemctl restart chandra-demo.service")
|
||||
auth_type(r.comp, "nope")
|
||||
auth_press(r.comp, 28U)
|
||||
assert_true(r.settle(fn() { d.failures == 1 }))
|
||||
assert_eq(d.error, "Wrong password. Try again.")
|
||||
assert_true(r.settle(fn() { d.phase == Asking }))
|
||||
auth_type(r.comp, "demo")
|
||||
auth_click(r.comp, Allow)
|
||||
assert_true(r.settle(fn() { r.comp.auth_view() is None && r.comp.auth_demos.length() == 0 }))
|
||||
assert_true(r.comp.auth_notice_text() is None)
|
||||
assert_eq(r.comp.control_command("auth-demo bogus").1, false)
|
||||
r.comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
test "auth-demo die and face: a check that quits shows why until Try again; the face row" {
|
||||
let r = rig("demo-die", None, "")
|
||||
ignore(r.comp.control_command("auth-demo die"))
|
||||
assert_true(r.settle(fn() { r.comp.auth_view().map(v => v.phase == Failed).unwrap_or(false) }))
|
||||
let d = r.view()
|
||||
assert_eq(d.error, "The password check quit before asking for a password.")
|
||||
auth_click(r.comp, Allow) // "Try again"
|
||||
assert_true(r.settle(fn() { d.phase == Asking }))
|
||||
assert_eq(d.error, "")
|
||||
auth_press(r.comp, 1U) // Escape
|
||||
assert_true(r.settle(fn() { r.comp.auth_demos.length() == 0 }))
|
||||
ignore(r.comp.control_command("auth-demo face"))
|
||||
assert_true(r.settle(fn() { r.comp.auth_view().map(v => v.face == Scanning).unwrap_or(false) }))
|
||||
// Typed while it looks: goes in when PAM asks.
|
||||
auth_type(r.comp, "demo")
|
||||
auth_press(r.comp, 28U)
|
||||
assert_true(r.settle(fn() { r.comp.auth_view() is None && r.comp.auth_demos.length() == 0 }))
|
||||
r.comp.close()
|
||||
}
|
||||
|
||||
///| The agent program the build made (release or debug), "" when it wasn't built.
|
||||
fn built_agent() -> String {
|
||||
for p in ["_build/native/release/build/compositor/authagent/authagent.exe", "_build/native/debug/build/compositor/authagent/authagent.exe"] {
|
||||
if @sys.has_exe(p) {
|
||||
return p
|
||||
}
|
||||
}
|
||||
""
|
||||
}
|
||||
|
||||
///| Run everything with the agent out of process: polkitd and the compositor.
|
||||
fn settle_out(comp : @host.ChandraCompositor, a : MockAuthority?, cond : () -> Bool) -> Bool {
|
||||
for i = 0; i < 500; i = i + 1 {
|
||||
match a {
|
||||
Some(a) => a.bus.pump()
|
||||
None => ()
|
||||
}
|
||||
ignore(@sys.wait_readable(comp.auth_fds(), 10))
|
||||
comp.step()
|
||||
if cond() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
///|
|
||||
test "the real chandra-polkit-agent program: demo, and registered with (mock) polkit through its own process" {
|
||||
let bin = built_agent()
|
||||
if bin == "" {
|
||||
println("skipped: build compositor/authagent first (just auth-agent)")
|
||||
return
|
||||
}
|
||||
// The demo, started by the compositor itself through spawn_socket.
|
||||
let comp = new_comp("auth-real-demo")
|
||||
assert_true(comp.start_auth_demo("password") is Ok(_))
|
||||
assert_true(settle_out(comp, None, fn() { comp.auth_view().map(v => v.phase == Asking).unwrap_or(false) }))
|
||||
auth_type(comp, "demo")
|
||||
auth_press(comp, 28U)
|
||||
assert_true(settle_out(comp, None, fn() { comp.auth_view() is None && comp.auth_demos.length() == 0 }))
|
||||
comp.close()
|
||||
// The session agent: the system bus, session and helper socket point at the test's mocks.
|
||||
let bus = match auth_bus("real") {
|
||||
Some(b) => b
|
||||
None => return
|
||||
}
|
||||
let a = MockAuthority::new(bus)
|
||||
let (hpath, listen) = helper_socket("real")
|
||||
let comp2 = new_comp("auth-real")
|
||||
comp2.login_session = true
|
||||
comp2.auth_spawner = Some(fn(args) {
|
||||
@sys.spawn_socket(
|
||||
[
|
||||
"/usr/bin/env", "DBUS_SYSTEM_BUS_ADDRESS=unix:path=" + bus, "XDG_SESSION_ID=2", "CHANDRA_POLKIT_HELPER=socket:" + hpath,
|
||||
bin, ..args,
|
||||
],
|
||||
)
|
||||
})
|
||||
comp2.start_auth_agent()
|
||||
assert_true(settle_out(comp2, Some(a), fn() { comp2.auth_agent.map(l => l.ready).unwrap_or(false) }))
|
||||
a.begin("r1", run0_details, uid=@polkit.own_uid().reinterpret_as_uint())
|
||||
assert_true(settle_out(comp2, Some(a), fn() { comp2.auth_view() is Some(_) }))
|
||||
let fd : Ref[Int] = { val: -1 }
|
||||
assert_true(settle_out(comp2, Some(a), fn() {
|
||||
if fd.val < 0 {
|
||||
fd.val = @sys.unix_accept(listen)
|
||||
}
|
||||
fd.val >= 0
|
||||
}))
|
||||
ignore(helper_lines(fd.val, 2))
|
||||
helper_say(fd.val, "PAM_PROMPT_ECHO_OFF Password: ")
|
||||
assert_true(settle_out(comp2, Some(a), fn() { comp2.auth_view().map(v => v.phase == Asking).unwrap_or(false) }))
|
||||
auth_type(comp2, "Right1")
|
||||
auth_press(comp2, 28U)
|
||||
assert_true(settle_out(comp2, Some(a), fn() { comp2.auth_view().map(v => v.phase == Checking).unwrap_or(false) }))
|
||||
assert_eq(helper_lines(fd.val, 1), "Right1")
|
||||
helper_say(fd.val, "SUCCESS")
|
||||
assert_true(settle_out(comp2, Some(a), fn() { a.answers == ["ok"] }))
|
||||
// Turning the switch off stops it (it unregisters and exits) and says there's no other agent.
|
||||
comp2.shell.set_session_setting(3, false)
|
||||
comp2.auth_agent_setting_changed()
|
||||
assert_true(comp2.auth_agent is None)
|
||||
@sys.close_fd(fd.val)
|
||||
@sys.close_fd(listen)
|
||||
@sys.unlink(hpath)
|
||||
comp2.close()
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -431,61 +773,6 @@ test "Settings > Session lists the password dialog switch, saved as :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 {
|
||||
@@ -564,19 +851,7 @@ let real_keymap : String =
|
||||
#|
|
||||
#|};
|
||||
|
||||
///| `settle`, composing frames too (the Face unlock window and Settings follow their tool there).
|
||||
fn fsettle(comp : @host.ChandraCompositor, a : MockAuthority, cond : () -> Bool) -> Bool {
|
||||
for i = 0; i < 300; i = i + 1 {
|
||||
a.bus.pump()
|
||||
comp.step()
|
||||
ignore(comp.compose_frame())
|
||||
if cond() {
|
||||
return true
|
||||
}
|
||||
@sys.sleep_ms(10)
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
|
||||
///|
|
||||
test "Face unlock window: snaps, Apply, then the password dialog gets the keyboard and the click" {
|
||||
@@ -584,27 +859,33 @@ test "Face unlock window: snaps, Apply, then the password dialog gets the keyboa
|
||||
Some(b) => b
|
||||
None => return
|
||||
}
|
||||
let a = MockAuthority::new(bus)
|
||||
let hpath = "/tmp/chandra-auth-helper-faceapply-" + @sys.getpid().to_string()
|
||||
let listen = @sys.unix_listen(hpath)
|
||||
let comp = auth_comp("faceapply", bus, hpath)
|
||||
let (hpath, listen) = helper_socket("faceapply")
|
||||
let r = rig("faceapply", Some(bus), hpath)
|
||||
let comp = r.comp
|
||||
comp.server.set_keymap(@utf8.encode(real_keymap))
|
||||
assert_true(fsettle(comp, a, fn() { comp.polkit.map(p => p.registered()).unwrap_or(false) }))
|
||||
comp.start_auth_agent()
|
||||
let fsettle = fn(cond : () -> Bool) {
|
||||
r.settle(fn() {
|
||||
ignore(comp.compose_frame())
|
||||
cond()
|
||||
})
|
||||
}
|
||||
assert_true(fsettle(fn() { r.ready() }))
|
||||
let a = r.authority()
|
||||
let dir = "/tmp/chandra-face-apply-" + @sys.getpid().to_string()
|
||||
let tool = fake_face_tool(dir)
|
||||
ignore(@sys.write_file_bytes(dir + "/wait", b""))
|
||||
comp.shell.set_face_tool(["/bin/sh", tool])
|
||||
assert_true(comp.shell.open_settings(Session))
|
||||
assert_true(fsettle(comp, a, fn() { face_texts(comp).contains("Desk") }))
|
||||
assert_true(fsettle(fn() { face_texts(comp).contains("Desk") }))
|
||||
face_click(comp, "Add or remove faces…", 10U)
|
||||
assert_true(fsettle(comp, a, fn() { comp.shell.face.window.map(w => w.picture != 0U).unwrap_or(false) }))
|
||||
assert_true(fsettle(fn() { comp.shell.face.window.map(w => w.picture != 0U).unwrap_or(false) }))
|
||||
let w = comp.shell.face.window.unwrap()
|
||||
face_key(comp, 57U, 20U)
|
||||
assert_true(fsettle(comp, a, fn() { w.snaps.length() == 1 }))
|
||||
assert_true(fsettle(fn() { w.snaps.length() == 1 }))
|
||||
face_key(comp, 57U, 30U)
|
||||
assert_true(fsettle(comp, a, fn() { w.snaps.length() == 2 }))
|
||||
// Enter: Apply; the root step asks polkit, which asks us. Meanwhile the window steps aside:
|
||||
// no dimming card, no input of its own (another agent's password window must be reachable).
|
||||
assert_true(fsettle(fn() { w.snaps.length() == 2 }))
|
||||
// Enter: Apply; the root step asks polkit, which asks us. Meanwhile the window steps aside.
|
||||
face_key(comp, 28U, 40U)
|
||||
assert_true(w.applying)
|
||||
ignore(comp.compose_frame())
|
||||
@@ -612,11 +893,11 @@ test "Face unlock window: snaps, Apply, then the password dialog gets the keyboa
|
||||
comp.handle_input(@nested.InputEvent::Key(57U, false), 1U)
|
||||
assert_eq(w.snaps.length(), 2)
|
||||
a.begin("f1", run0_details)
|
||||
assert_true(fsettle(comp, a, fn() { comp.auth_dialog() is Some(_) }))
|
||||
let d = comp.auth_dialog().unwrap()
|
||||
let (h, _) = helper_accept(listen, comp, a)
|
||||
assert_true(fsettle(fn() { comp.auth_view() is Some(_) }))
|
||||
let d = r.view()
|
||||
let (h, _) = r.helper_accept(listen)
|
||||
helper_say(h, "PAM_PROMPT_ECHO_OFF Password: ")
|
||||
assert_true(fsettle(comp, a, fn() { d.phase == Prompt }))
|
||||
assert_true(fsettle(fn() { d.phase == Asking }))
|
||||
auth_shot(comp, "18-face-apply-password")
|
||||
// Typing goes to the password dialog, not to the window under it (Space would snap).
|
||||
auth_type(comp, "Secret9")
|
||||
@@ -625,18 +906,14 @@ test "Face unlock window: snaps, Apply, then the password dialog gets the keyboa
|
||||
assert_eq(d.typed(), 8)
|
||||
assert_eq(w.snaps.length(), 2)
|
||||
// The Authenticate button takes the click.
|
||||
ignore(comp.compose_frame())
|
||||
let allow = comp.auth.unwrap().hits.filter(x => x.1 == Allow)[0].0
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((allow.x + 4).to_double(), (allow.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(fsettle(comp, a, fn() { d.phase == Checking }))
|
||||
auth_click(comp, Allow)
|
||||
assert_true(fsettle(fn() { d.phase == Checking }))
|
||||
assert_eq(helper_lines(h, 1), "Secret9 ")
|
||||
helper_say(h, "SUCCESS")
|
||||
assert_true(fsettle(comp, a, fn() { comp.auth_dialog() is None && a.answers.length() == 1 }))
|
||||
assert_true(fsettle(fn() { comp.auth_view() is None && a.answers.length() == 1 }))
|
||||
// The root step goes on; the window closes with what it said.
|
||||
ignore(@sys.write_file_bytes(dir + "/go", b""))
|
||||
assert_true(fsettle(comp, a, fn() { comp.shell.face.window is None }))
|
||||
assert_true(fsettle(fn() { comp.shell.face.window is None }))
|
||||
assert_eq(comp.shell.face.message, "Added Face 2 and removed 1 face")
|
||||
@sys.close_fd(h)
|
||||
@sys.close_fd(listen)
|
||||
|
||||
Reference in new issue
Block a user