device: Throw a NoEnrolledPrints error if trying to delete a device with no prints

Adjust tests accordingly
This commit is contained in:
Marco Trevisan (Treviño)
2021-01-27 22:47:09 +01:00
parent 4b246d3ce2
commit 6f355797f8
4 changed files with 45 additions and 46 deletions

View File

@ -1985,9 +1985,14 @@ delete_enrolled_fingers (FprintDevice *rdev,
if (!user_has_print_enrolled (rdev, user, finger))
{
if (finger != FP_FINGER_UNKNOWN)
g_set_error (error, FPRINT_ERROR, FPRINT_ERROR_NO_ENROLLED_PRINTS,
"Fingerprint for finger %s is not enrolled",
fp_finger_to_name (finger));
else
g_set_error_literal (error, FPRINT_ERROR, FPRINT_ERROR_NO_ENROLLED_PRINTS,
"No fingerprint enrolled");
return FALSE;
}
@ -2192,11 +2197,8 @@ fprint_device_delete_enrolled_fingers (FprintDBusDevice *dbus_dev,
if (!opened && fp_device_has_storage (priv->dev))
fp_device_close_sync (priv->dev, NULL, NULL);
if (error &&
!g_error_matches (error, FPRINT_ERROR, FPRINT_ERROR_NO_ENROLLED_PRINTS))
if (error)
{
/* FIXME: We should probably expose NoEnrolledPrints as an actual error,
* but not changing the API for now */
g_dbus_method_invocation_return_gerror (invocation,
error);
return TRUE;
@ -2237,15 +2239,9 @@ fprint_device_delete_enrolled_fingers2 (FprintDBusDevice *dbus_dev,
if (!delete_enrolled_fingers (rdev, session->username, FP_FINGER_UNKNOWN, &error))
{
if (!g_error_matches (error, FPRINT_ERROR, FPRINT_ERROR_NO_ENROLLED_PRINTS))
{
/* FIXME: We should probably expose NoEnrolledPrints as an actual error,
* but not changing the API for now */
g_dbus_method_invocation_return_gerror (invocation,
error);
g_dbus_method_invocation_return_gerror (invocation, error);
return TRUE;
}
}
fprint_dbus_device_complete_delete_enrolled_fingers2 (dbus_dev,
invocation);

View File

@ -184,6 +184,11 @@ def DeleteEnrolledFingers2(device):
raise dbus.exceptions.DBusException(
'Device was not claimed before use',
name='net.reactivated.Fprint.Error.ClaimDevice')
if not device.fingers[device.claimed_user]:
raise dbus.exceptions.DBusException(
'No enrolled prints in device {} for user {}'.format(device.path,
device.claimed_user),
name='net.reactivated.Fprint.Error.NoEnrolledPrints')
device.fingers[device.claimed_user] = []
@dbus.service.method(DEVICE_IFACE,

View File

@ -1246,6 +1246,11 @@ class FPrintdVirtualDeviceTest(FPrintdVirtualDeviceBaseTest):
self.device.EnrollStop()
def test_unclaimed_delete_enrolled_fingers(self):
self.enroll_image('whorl', claim_user='foo-user')
self.device.DeleteEnrolledFingers('(s)', 'foo-user')
def test_unclaimed_delete_enrolled_fingers_no_prints(self):
with self.assertFprintError('NoEnrolledPrints'):
self.device.DeleteEnrolledFingers('(s)', 'testuser')
def test_unclaimed_delete_enrolled_finger(self):
@ -2044,11 +2049,7 @@ class FPrintdVirtualDeviceClaimedTest(FPrintdVirtualDeviceBaseTest):
self.wait_for_device_reply_relaxed(expected_replies=2,
accepted_exceptions=accepted_exceptions)
if self.device_driver == 'virtual_device_storage':
self.assertIn(GLib.Variant('()', ()), self.get_all_async_replies())
else:
self.assertEqual([GLib.Variant('()', ()), GLib.Variant('()', ())],
self.get_all_async_replies())
def test_concourrent_delete_enrolled_fingers_unclaimed(self):
self.enroll_image('whorl')
@ -2063,11 +2064,7 @@ class FPrintdVirtualDeviceClaimedTest(FPrintdVirtualDeviceBaseTest):
self.wait_for_device_reply_relaxed(expected_replies=2,
accepted_exceptions=accepted_exceptions)
if self.device_driver == 'virtual_device_storage':
self.assertIn(GLib.Variant('()', ()), self.get_all_async_replies())
else:
self.assertEqual([GLib.Variant('()', ()), GLib.Variant('()', ())],
self.get_all_async_replies())
def test_concourrent_delete_enrolled_fingers2(self):
self.enroll_image('whorl')
@ -2081,11 +2078,7 @@ class FPrintdVirtualDeviceClaimedTest(FPrintdVirtualDeviceBaseTest):
self.wait_for_device_reply_relaxed(expected_replies=2,
accepted_exceptions=accepted_exceptions)
if self.device_driver == 'virtual_device_storage':
self.assertIn(GLib.Variant('()', ()), self.get_all_async_replies())
else:
self.assertEqual([GLib.Variant('()', ()), GLib.Variant('()', ())],
self.get_all_async_replies())
def test_concourrent_delete_enrolled_finger(self):
self.enroll_image('whorl', finger='left-thumb')
@ -2115,6 +2108,24 @@ class FPrintdVirtualDeviceClaimedTest(FPrintdVirtualDeviceBaseTest):
self.assertIn(GLib.Variant('()', ()), self.get_all_async_replies())
def test_already_claimed_same_user_delete_enrolled_fingers(self):
self.enroll_image('whorl')
self.device.DeleteEnrolledFingers('(s)', 'testuser')
def test_already_claimed_same_user_delete_enrolled_fingers_no_prints(self):
with self.assertFprintError('NoEnrolledPrints'):
self.device.DeleteEnrolledFingers('(s)', 'testuser')
def test_already_claimed_other_user_delete_enrolled_fingers(self):
self.device.Release()
self.enroll_image('whorl', claim_user='nottestuser')
self.device.Claim('(s)', 'testuser')
self.device.DeleteEnrolledFingers('(s)', 'nottestuser')
def test_already_claimed_other_user_delete_enrolled_fingers_no_prints(self):
with self.assertFprintError('NoEnrolledPrints'):
self.device.DeleteEnrolledFingers('(s)', 'nottestuser')
class FPrintdVirtualDeviceEnrollTests(FPrintdVirtualDeviceBaseTest):
@ -2843,13 +2854,6 @@ class FPrintdUtilsTest(FPrintdVirtualDeviceBaseTest):
self.device.Claim('(s)', self.get_current_user())
self.device.Release()
def test_already_claimed_same_user_delete_enrolled_fingers(self):
self.device.DeleteEnrolledFingers('(s)', 'testuser')
def test_already_claimed_other_user_delete_enrolled_fingers(self):
self.device.DeleteEnrolledFingers('(s)', 'nottestuser')
def list_tests():
import unittest_inspector

View File

@ -158,20 +158,14 @@ class TestFprintdUtils(TestFprintdUtilsBase):
self.assertEqual(ret, 0)
def test_fprintd_delete(self):
# Has fingerprints enrolled
out, ret = self.run_utility_process('list', ['toto'])
self.assertRegex(out, rb'left-little-finger')
self.assertEqual(ret, 0)
self.assertRegex(out, rb'right-little-finger')
# Delete fingerprints
out, ret = self.run_utility_process('delete', ['toto'])
self.assertRegex(out, rb'Fingerprints deleted')
self.assertEqual(ret, 0)
# Doesn't have fingerprints
out, ret = self.run_utility_process('list', ['toto'])
self.assertRegex(out, rb'has no fingers enrolled for')
out, ret = self.run_utility_process('delete', ['toto'])
self.assertRegex(out, rb'No fingerprints to delete on')
self.assertEqual(ret, 0)