#!/usr/bin/env python3 """Smoke-test client for the fprintd shim; mimics pam_fprintd's call flow. GetDevices -> ListEnrolledFingers -> Claim -> VerifyStart('any') waits for VerifyStatus (touch the sensor) until --timeout -> VerifyStop -> Release Exits 0 when a verify outcome (match/no-match) or a clean timeout was seen. Usage: # on the system bus (installed service): work/fprintd-shim/selftest.py [--user nebulon] [--timeout 12] # on a private session bus (no root needed): dbus-run-session -- bash -c ' python3 work/fprintd-shim/fprintd-shim.py --session & sleep 1 python3 work/fprintd-shim/selftest.py --session --user nebulon --timeout 12 kill %1' """ import argparse import sys import gi gi.require_version('Gio', '2.0') gi.require_version('GLib', '2.0') from gi.repository import Gio, GLib # noqa: E402 BUS_NAME = 'net.reactivated.Fprint' MANAGER_PATH = '/net/reactivated/Fprint/Manager' IFACE_MANAGER = 'net.reactivated.Fprint.Manager' IFACE_DEVICE = 'net.reactivated.Fprint.Device' def main(): parser = argparse.ArgumentParser() parser.add_argument('--session', action='store_true') parser.add_argument('--user', default='nebulon') parser.add_argument('--timeout', type=float, default=12.0, help='seconds to wait for a verify result') args = parser.parse_args() bus_type = Gio.BusType.SESSION if args.session else Gio.BusType.SYSTEM bus = Gio.bus_get_sync(bus_type, None) manager = Gio.DBusProxy.new_sync( bus, Gio.DBusProxyFlags.NONE, None, BUS_NAME, MANAGER_PATH, IFACE_MANAGER, None) devices = manager.call_sync('GetDevices', None, Gio.DBusCallFlags.NONE, 5000, None).unpack()[0] print(f'GetDevices -> {list(devices)}') if not devices: print('FAIL: no devices') return 1 default = manager.call_sync('GetDefaultDevice', None, Gio.DBusCallFlags.NONE, 5000, None).unpack()[0] print(f'GetDefaultDevice -> {default}') device = Gio.DBusProxy.new_sync( bus, Gio.DBusProxyFlags.NONE, None, BUS_NAME, default, IFACE_DEVICE, None) print(f'properties -> name={device.get_cached_property("name")!r} ' f'scan-type={device.get_cached_property("scan-type")!r} ' f'num-enroll-stages={device.get_cached_property("num-enroll-stages")!r}') result = {'status': None, 'reason': 'timeout before any verify result'} loop = GLib.MainLoop() def on_signal(_conn, _sender, _path, iface, signal, params): if iface != IFACE_DEVICE: return if signal == 'VerifyFingerSelected': print(f'VerifyFingerSelected -> {params.unpack()[0]}') elif signal == 'VerifyStatus': status, done = params.unpack() print(f'VerifyStatus -> {status} (done={done})') result['status'] = status result['reason'] = 'terminal verify status' if done: loop.quit() bus.signal_subscribe(BUS_NAME, IFACE_DEVICE, None, default, None, Gio.DBusSignalFlags.NONE, on_signal) try: fingers = device.call_sync('ListEnrolledFingers', GLib.Variant('(s)', (args.user,)), Gio.DBusCallFlags.NONE, 5000, None).unpack()[0] print(f'ListEnrolledFingers -> {list(fingers)}') except GLib.Error as e: print(f'ListEnrolledFingers -> error {e.message}') fingers = [] if not fingers: print('FAIL: no enrolled fingers reported') return 1 device.call_sync('Claim', GLib.Variant('(s)', (args.user,)), Gio.DBusCallFlags.NONE, 5000, None) print('Claim -> ok') print(f' (touch the sensor, waiting {args.timeout:.0f}s)') device.call_sync('VerifyStart', GLib.Variant('(s)', ('any',)), Gio.DBusCallFlags.NONE, 5000, None) def give_up(): result['reason'] = 'timeout waiting for a verify result' loop.quit() return GLib.SOURCE_REMOVE GLib.timeout_add(int(args.timeout * 1000), give_up) loop.run() try: device.call_sync('VerifyStop', None, Gio.DBusCallFlags.NONE, 5000, None) print('VerifyStop -> ok') except GLib.Error as e: print(f'VerifyStop -> {e.message}') device.call_sync('Release', None, Gio.DBusCallFlags.NONE, 5000, None) print('Release -> ok') print(f'result: {result["reason"]}' + (f' ({result["status"]})' if result['status'] else '')) if result['status'] == 'verify-match': return 0 if result['status'] == 'verify-no-match': return 1 return 2 if __name__ == '__main__': sys.exit(main())