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.
This commit is contained in:
parent
c928d7bd8f
commit
3108ac3144
3 changed files with 19 additions and 36 deletions
|
@ -67,12 +67,17 @@ dev_identify (FpDevice *dev)
|
||||||
new_scan,
|
new_scan,
|
||||||
(GEqualFunc) fp_print_equal,
|
(GEqualFunc) fp_print_equal,
|
||||||
NULL))
|
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,
|
else if (g_ptr_array_find_with_equal_func (prints,
|
||||||
new_scan,
|
new_scan,
|
||||||
(GEqualFunc) fp_print_equal,
|
(GEqualFunc) fp_print_equal,
|
||||||
&idx))
|
&idx))
|
||||||
match = g_ptr_array_index (prints, idx);
|
{
|
||||||
|
match = g_ptr_array_index (prints, idx);
|
||||||
|
}
|
||||||
|
|
||||||
if (!self->match_reported)
|
if (!self->match_reported)
|
||||||
{
|
{
|
||||||
|
|
|
@ -543,7 +543,7 @@ dev_verify (FpDevice *dev)
|
||||||
|
|
||||||
if (self->prints_storage && !g_hash_table_contains (self->prints_storage, scan_id))
|
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;
|
success = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -322,7 +322,7 @@ class VirtualDeviceBase(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
self.assertFalse(match)
|
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)
|
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):
|
def test_enroll_verify_no_match(self):
|
||||||
matching = self.enroll_print('testprint', FPrint.Finger.LEFT_RING)
|
matching = self.enroll_print('testprint', FPrint.Finger.LEFT_RING)
|
||||||
|
|
||||||
if self.dev.has_storage():
|
self.check_verify(matching, 'not-testprint', match=False,
|
||||||
with self.assertRaises(GLib.Error) as error:
|
identify=self.dev.supports_identify())
|
||||||
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())
|
|
||||||
|
|
||||||
def test_enroll_verify_error(self):
|
def test_enroll_verify_error(self):
|
||||||
matching = self.enroll_print('testprint', FPrint.Finger.LEFT_RING)
|
matching = self.enroll_print('testprint', FPrint.Finger.LEFT_RING)
|
||||||
|
@ -597,14 +590,11 @@ class VirtualDevice(VirtualDeviceBase):
|
||||||
FPrint.DeviceRetry.TOO_SHORT))
|
FPrint.DeviceRetry.TOO_SHORT))
|
||||||
|
|
||||||
self.send_command('SCAN', 'another-id')
|
self.send_command('SCAN', 'another-id')
|
||||||
|
verify_match, verify_fp = self.dev.verify_sync(enrolled)
|
||||||
|
self.assertFalse(verify_match)
|
||||||
if self.dev.has_storage():
|
if self.dev.has_storage():
|
||||||
with self.assertRaises(GLib.GError) as error:
|
self.assertIsNone(verify_fp)
|
||||||
self.dev.verify_sync(enrolled)
|
|
||||||
self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(),
|
|
||||||
FPrint.DeviceError.DATA_NOT_FOUND))
|
|
||||||
else:
|
else:
|
||||||
verify_match, verify_fp = self.dev.verify_sync(enrolled)
|
|
||||||
self.assertFalse(verify_match)
|
|
||||||
self.assertFalse(verify_fp.equal(enrolled))
|
self.assertFalse(verify_fp.equal(enrolled))
|
||||||
|
|
||||||
self.send_auto(enrolled)
|
self.send_auto(enrolled)
|
||||||
|
@ -821,13 +811,7 @@ class VirtualDevice(VirtualDeviceBase):
|
||||||
self.wait_timeout(10)
|
self.wait_timeout(10)
|
||||||
self.assertFalse(self._verify_completed)
|
self.assertFalse(self._verify_completed)
|
||||||
|
|
||||||
if self.dev.has_storage():
|
self.complete_verify()
|
||||||
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.assertTrue(self._verify_reported)
|
self.assertTrue(self._verify_reported)
|
||||||
|
|
||||||
def test_close_error(self):
|
def test_close_error(self):
|
||||||
|
@ -1159,18 +1143,12 @@ class VirtualDeviceStorage(VirtualDevice):
|
||||||
FPrint.DeviceError.DATA_NOT_FOUND))
|
FPrint.DeviceError.DATA_NOT_FOUND))
|
||||||
|
|
||||||
def test_verify_missing_print(self):
|
def test_verify_missing_print(self):
|
||||||
with self.assertRaises(GLib.Error) as error:
|
self.check_verify(FPrint.Print.new(self.dev),
|
||||||
self.check_verify(FPrint.Print.new(self.dev),
|
'not-existing-print', False, identify=False)
|
||||||
'not-existing-print', False, identify=False)
|
|
||||||
self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(),
|
|
||||||
FPrint.DeviceError.DATA_NOT_FOUND))
|
|
||||||
|
|
||||||
def test_identify_missing_print(self):
|
def test_identify_missing_print(self):
|
||||||
with self.assertRaises(GLib.Error) as error:
|
self.check_verify(FPrint.Print.new(self.dev),
|
||||||
self.check_verify(FPrint.Print.new(self.dev),
|
'not-existing-print', False, identify=True)
|
||||||
'not-existing-print', False, identify=True)
|
|
||||||
self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(),
|
|
||||||
FPrint.DeviceError.DATA_NOT_FOUND))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue