From 3108ac3144948bd377f68335d8aaeaa5eb9c1097 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Fri, 30 Jul 2021 21:31:08 +0200 Subject: [PATCH] virtual-device: Return empty no-match if unknown SCAN id is passed This matches the expectation. i.e. we return no-match and we do not return a scanned print as we don't have anything for it. If we did indeed return a scanned print, then fprintd would try to delete it during enroll and would then fail. Note that we do *not* return a DATA_NOT_FOUND error in the storage device if the print does not exist. This is because not all devices support reporting this error. It is therefore more sensible to handle it gracefully and expect test setups to set the error explicitly for testing purposes. --- libfprint/drivers/virtual-device-storage.c | 9 ++++- libfprint/drivers/virtual-device.c | 2 +- tests/virtual-device.py | 44 ++++++---------------- 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/libfprint/drivers/virtual-device-storage.c b/libfprint/drivers/virtual-device-storage.c index 85e35ac..0f5a4b3 100644 --- a/libfprint/drivers/virtual-device-storage.c +++ b/libfprint/drivers/virtual-device-storage.c @@ -67,12 +67,17 @@ dev_identify (FpDevice *dev) new_scan, (GEqualFunc) fp_print_equal, NULL)) - error = fpi_device_error_new (FP_DEVICE_ERROR_DATA_NOT_FOUND); + { + match = FALSE; + g_clear_object (&new_scan); + } else if (g_ptr_array_find_with_equal_func (prints, new_scan, (GEqualFunc) fp_print_equal, &idx)) - match = g_ptr_array_index (prints, idx); + { + match = g_ptr_array_index (prints, idx); + } if (!self->match_reported) { diff --git a/libfprint/drivers/virtual-device.c b/libfprint/drivers/virtual-device.c index a9efb39..d21d94b 100644 --- a/libfprint/drivers/virtual-device.c +++ b/libfprint/drivers/virtual-device.c @@ -543,7 +543,7 @@ dev_verify (FpDevice *dev) if (self->prints_storage && !g_hash_table_contains (self->prints_storage, scan_id)) { - error = fpi_device_error_new (FP_DEVICE_ERROR_DATA_NOT_FOUND); + g_clear_object (&new_scan); success = FALSE; } else diff --git a/tests/virtual-device.py b/tests/virtual-device.py index 0a4e7dd..e15b432 100644 --- a/tests/virtual-device.py +++ b/tests/virtual-device.py @@ -322,7 +322,7 @@ class VirtualDeviceBase(unittest.TestCase): else: self.assertFalse(match) - if isinstance(scan_nick, str): + if isinstance(scan_nick, str) and not self.dev.has_storage(): self.assertEqual(self._verify_fp.props.fpi_data.get_string(), scan_nick) @@ -470,15 +470,8 @@ class VirtualDevice(VirtualDeviceBase): def test_enroll_verify_no_match(self): matching = self.enroll_print('testprint', FPrint.Finger.LEFT_RING) - if self.dev.has_storage(): - with self.assertRaises(GLib.Error) as error: - self.check_verify(matching, 'not-testprint', match=False, - identify=self.dev.supports_identify()) - self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), - FPrint.DeviceError.DATA_NOT_FOUND)) - else: - self.check_verify(matching, 'not-testprint', match=False, - identify=self.dev.supports_identify()) + self.check_verify(matching, 'not-testprint', match=False, + identify=self.dev.supports_identify()) def test_enroll_verify_error(self): matching = self.enroll_print('testprint', FPrint.Finger.LEFT_RING) @@ -597,14 +590,11 @@ class VirtualDevice(VirtualDeviceBase): FPrint.DeviceRetry.TOO_SHORT)) self.send_command('SCAN', 'another-id') + verify_match, verify_fp = self.dev.verify_sync(enrolled) + self.assertFalse(verify_match) if self.dev.has_storage(): - with self.assertRaises(GLib.GError) as error: - self.dev.verify_sync(enrolled) - self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), - FPrint.DeviceError.DATA_NOT_FOUND)) + self.assertIsNone(verify_fp) else: - verify_match, verify_fp = self.dev.verify_sync(enrolled) - self.assertFalse(verify_match) self.assertFalse(verify_fp.equal(enrolled)) self.send_auto(enrolled) @@ -821,13 +811,7 @@ class VirtualDevice(VirtualDeviceBase): self.wait_timeout(10) self.assertFalse(self._verify_completed) - if self.dev.has_storage(): - with self.assertRaises(GLib.Error) as error: - self.complete_verify() - self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), - FPrint.DeviceError.DATA_NOT_FOUND)) - else: - self.complete_verify() + self.complete_verify() self.assertTrue(self._verify_reported) def test_close_error(self): @@ -1159,18 +1143,12 @@ class VirtualDeviceStorage(VirtualDevice): FPrint.DeviceError.DATA_NOT_FOUND)) def test_verify_missing_print(self): - with self.assertRaises(GLib.Error) as error: - self.check_verify(FPrint.Print.new(self.dev), - 'not-existing-print', False, identify=False) - self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), - FPrint.DeviceError.DATA_NOT_FOUND)) + self.check_verify(FPrint.Print.new(self.dev), + 'not-existing-print', False, identify=False) def test_identify_missing_print(self): - with self.assertRaises(GLib.Error) as error: - self.check_verify(FPrint.Print.new(self.dev), - 'not-existing-print', False, identify=True) - self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), - FPrint.DeviceError.DATA_NOT_FOUND)) + self.check_verify(FPrint.Print.new(self.dev), + 'not-existing-print', False, identify=True) if __name__ == '__main__':