From 8da1b5e7f54ba0b943a7b5f8450abfd5c275b0fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 2 Mar 2021 17:07:40 +0100 Subject: [PATCH] device: Do not set the device in verification state if we've errored During VerifyStart we may return early if there are no enrolled prints. In such case we don't require the verification to be stopped if we're using identification, but in the verification case we may leave the device into the verification state. So ensure we only set the device current state only when we're about to start it. Add tests ensuring those cases --- src/device.c | 3 +-- tests/fprintd.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/device.c b/src/device.c index f39cee5..2fbf4f6 100644 --- a/src/device.c +++ b/src/device.c @@ -1494,8 +1494,6 @@ fprint_device_verify_start (FprintDBusDevice *dbus_dev, { g_autoptr(FpPrint) print = NULL; - priv->current_action = ACTION_VERIFY; - if (gallery) { print = g_ptr_array_steal_index_fast (gallery, 0); @@ -1518,6 +1516,7 @@ fprint_device_verify_start (FprintDBusDevice *dbus_dev, g_debug ("start verification device %d finger %s", priv->id, fp_finger_to_name (finger)); + priv->current_action = ACTION_VERIFY; priv->current_cancellable = g_cancellable_new (); priv->verify_data = g_object_ref (print); fp_device_verify (priv->dev, print, priv->current_cancellable, diff --git a/tests/fprintd.py b/tests/fprintd.py index fb74993..9408c8e 100644 --- a/tests/fprintd.py +++ b/tests/fprintd.py @@ -1780,6 +1780,25 @@ class FPrintdVirtualDeviceClaimedTest(FPrintdVirtualDeviceBaseTest): with self.assertFprintError('NoEnrolledPrints'): self.device.VerifyStart('(s)', 'right-thumb') + def test_verify_finger_not_enrolled_stops_verification(self): + self.enroll_image('whorl', finger='left-thumb') + with self.assertFprintError('NoEnrolledPrints'): + self.device.VerifyStart('(s)', 'right-thumb') + + with self.assertFprintError('NoActionInProgress'): + self.device.VerifyStop() + + def test_identify_finger_not_enrolled(self): + with self.assertFprintError('NoEnrolledPrints'): + self.device.VerifyStart('(s)', 'any') + + def test_identify_finger_not_enrolled_stops_verification(self): + with self.assertFprintError('NoEnrolledPrints'): + self.device.VerifyStart('(s)', 'any') + + with self.assertFprintError('NoActionInProgress'): + self.device.VerifyStop() + def test_unallowed_enroll_start(self): self._polkitd_obj.SetAllowed([''])