Commit graph

156 commits

Author SHA1 Message Date
Benjamin Berg
ab8118bde2 tests: Add device removal test 2020-11-25 19:09:00 +01:00
Benjamin Berg
8ed77829a7 tests: Add test for a client vanishing during claim
Note that this test only works if the virtual_image driver opens up a
window for race condition by delaying the open callback.
2020-11-25 19:05:47 +01:00
Benjamin Berg
fd9a86eca4 tests: Fail test if return code is less than 0
This means that the application received a signal.
2020-11-25 19:04:44 +01:00
Marco Trevisan (Treviño)
1a860aa882 tests/fprintd: Add tests ensuring that concurrent calls to fprintd work
Simulate the case in which multiple users are trying to access a device
at the same time, verifying that the access is granted only to the one
that first completes the authorization phase and that no other client is
then allowed.
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
a183b779ec tests/fprintd: Make easier to call device methods asynchronously 2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
9d6c7eb1a9 dbusmock/polkitd: Add ability to simulate call hangs or delays
Added various methods that allow to make methods to delay to return a
value, both by using timing functions and using a way to manually
stop and restart the calls.

This is mostly done using async callbacks in dbus methods
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
110c0018a2 tests/fprintd: Make possible to call gdbus client as an async process
As per this refactor the sync call we already had so that reuses the
same code.
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
5611317c72 tests: Add standalone PolkitD implementation
We need to be able to hack this to be an async daemon to perform some
multi-thread tests, so replacing default implementation with a simple
one that for now just does same of default
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
0904c8a527 tests/fprintd: Ensure we can claim and release with only the verify permission 2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
93bad82540 fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.

So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.

Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.

Fixes: #61
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
b2cae5cccf tests/fprintd: Check that identification with multiple images works 2020-11-06 11:06:25 +01:00
Marco Trevisan (Treviño)
3419901f65 build: Don't add the utils tests under the daemon suite 2020-11-04 21:06:13 +01:00
Marco Trevisan (Treviño)
c85ca09e35 tests/fprintd-utils: Ensure that we exit with error if we have no device 2020-11-04 21:06:13 +01:00
Marco Trevisan (Treviño)
091f373109 tests/fprintd-utils: Check the tools return values in some tests 2020-11-04 21:06:13 +01:00
Marco Trevisan (Treviño)
f6eb3b3ea5 verify: Pass the "any" finger parameter to the daemon
fprintd supports "any" finger parameter for the VerifyStart call, and it's
up to the daemon to pick the first known if the device doesn't support
identification.

So remove the check to verify utility and add a test to verify this is
respected.
2020-11-04 21:06:13 +01:00
Marco Trevisan (Treviño)
d7ca9e6095 tests/fprintd-utils: Verify happens on first finger if device has no identification
Ensure that this is true when using the utility
2020-11-04 21:06:13 +01:00
Marco Trevisan (Treviño)
6797928884 dbusmock/fprintd: Add ability to add a device with Identification support
Devices which have identification support "any" finger and do not fallback
to a single-finger check.
2020-11-04 21:06:13 +01:00
Marco Trevisan (Treviño)
d6c70be822 dbusmock/fprintd: Add ability to remove devices 2020-11-04 21:06:13 +01:00
Marco Trevisan (Treviño)
d33a7c7e9d tests/fprintd-utils: Check that all fingers are listed 2020-11-04 21:06:13 +01:00
Marco Trevisan (Treviño)
94d3a18dcd tests/fprintd-utils: Check that verify returns an error if no finger is set 2020-11-04 21:06:13 +01:00
Marco Trevisan (Treviño)
5635383c96 tests/fprintd-utils: Check that fprintd-verify requests the expected finger 2020-11-04 21:06:13 +01:00
Marco Trevisan (Treviño)
ac98b881be dbusmock/fprintd: Make possible to retrieve the finger selected for verification
So that we can ensure that the client requested the one we expect
2020-11-04 21:06:13 +01:00
Marco Trevisan (Treviño)
629f7fcc11 dbusmock/fprintd: Reset the current action on release
So it happens in the real daemon
2020-11-04 21:06:13 +01:00
Marco Trevisan (Treviño)
5a703baa20 verify: Fail if we try to verify a non-enrolled finger
Since we list the fingers available fail early in case it's not found
2020-11-04 21:06:10 +01:00
Marco Trevisan (Treviño)
6641cb6da8 tests/fprintd-utils: Verify that we can match all the enrolled fingers 2020-11-04 21:04:21 +01:00
Marco Trevisan (Treviño)
870b48637a tests/fprintd-utils: Verify errors if the device is already claimed 2020-11-04 21:04:21 +01:00
Marco Trevisan (Treviño)
4b0cde81fd tests/fprintd-utils: Add utility function to stop the utility process
This avoids addCleanup ordering errors and also errors when we may try to
print an invalid stdout pipe (like when we have processed it all), as python
might fail with something like:

 ======================================================================
 ERROR: test_fprintd_multiple_verify_fails (__main__.TestFprintdUtilsVerify)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "~/GNOME/fprintd/tests/test_fprintd_utils.py", line 102, in <lambda>
     self.addCleanup(lambda: print(process.stdout.read()))
   File "/usr/lib/python3.8/codecs.py", line 321, in decode
     data = self.buffer + input
 TypeError: can't concat NoneType to bytes
2020-11-04 21:04:21 +01:00
Marco Trevisan (Treviño)
59b3d2af8d tests/fprintd-utils: Call addCleanup actions in reverse order
unittest addCleanup calls are called in reverse order, so we need to reverse
the order of the calls as well, otherwise we won't correctly terminate the
subprocess children
2020-11-04 21:04:21 +01:00
Marco Trevisan (Treviño)
93bcac946e tests/fprintd-utils: Move verification tests to a single class
We can factorize various checks, so let's simplify test code
2020-11-04 21:04:19 +01:00
Marco Trevisan (Treviño)
a5063dc0e4 tests/fprintd-utils: Setup the device on setUp()
No need to repeat the action in every unit test, but move the tests to a
different class to easily allow adding another class with tests with no
such initialization
2020-11-04 20:20:29 +01:00
Marco Trevisan (Treviño)
5fbc38c938 tests/fprintd-utils: Run super setUp/tearDown functions 2020-11-04 20:04:21 +01:00
Benjamin Berg
6dc699ae6f tests: Fix test not failing on error
An assertion that is raised within a callback will not be swallowed by
the C code that called the function. To ensure that errors will be
noticable, pass the result back to the surrounding scope and check it
there.
2020-10-02 17:54:20 +02:00
Benjamin Berg
e075d37590 tests: Check that a verify operation can be immediately restarted
This excercises the path where we early-report a result and the
VerifyStop call must wait for the operation to complete intenernally.

Note that this test cannot fail right now due to the FpImageDevice
internal code still trying to hide the deactivation delay internally.

See libfprint!174
2020-10-01 12:19:35 +00:00
Benjamin Berg
290e56023f tests: Test more branches in pam verify signal handler 2020-08-17 15:11:08 +02:00
Bastien Nocera
fcd2d65490 tests: Add PAM test for hardware failure
This error is supposed to help replicate the problems encountered in:
https://gitlab.freedesktop.org/libfprint/fprintd/-/issues/59
2020-04-07 10:47:35 +02:00
Marco Trevisan (Treviño)
714f499ab6 tests: Double the timeouts when testing with address sanitizer 2020-04-01 13:58:08 +00:00
Marco Trevisan (Treviño)
d72c802415 tests/fprintd: Ensure that the daemon doesn't crash or abort
An application terminating because of a signal like SIGSEGV, SIGABRT and
friends, will exit with a signal number that is 128 + $SIGNAL_NUMBER, so
let's ensure that the daemon has not been terminated because of a such error

This makes even more sense with address sanitizer builds, as the daemon
would exit with abort.
2020-04-01 13:58:08 +00:00
Marco Trevisan (Treviño)
184e1bd4d0 build: Support running tests with address sanitizer
Make possible to run tests with address sanitizer to quickly check for
memory errors, although we have to disable the error exit code in case of
leaks because we have some which are due to something else down in the stack
(and LSAN suppression files doesn't allow to define the stack to ignore
as we can in valgrind).

However, we'd abort in case of memory errors anyways, so this still helps
to prevent major problems, while still logging the leaks.

In order to run pam module tests with ASAN we need to manually pass the
library to LD_PRELOAD, as we do for the wrapper.
2020-04-01 13:58:08 +00:00
Marco Trevisan (Treviño)
f401f399a8 pam: Get preloaded libraries paths using compiler
In order to run pam module tests we need to pass the libraries via
LD_PRELOAD, this supports a list of library paths, so use the compiler in
order to find their full paths (with soname) and check their presence.

In order to support linker scripts we need to introduce a workaround.
See meson issue https://github.com/mesonbuild/meson/issues/6880
2020-04-01 13:58:08 +00:00
Marco Trevisan (Treviño)
90298134a2 tests/fprintd: Add checks for delete enrolled fingers permissions
The test doesn't need any assertion because we're calling DeleteEnrolledFingers
and in case it fails a net.reactivated.Fprint.Error.PermissionDenied error
would be thrown, and thus an exception would be raised at python level, making
the test to fail.
2020-03-27 20:45:59 +01:00
Bastien Nocera
8ff4360750 tests: Add test for STATE_DIRECTORY being multiple paths 2020-03-27 17:05:13 +01:00
Bastien Nocera
6a1fffae82 tests/fprintd: Fix claim_from_other_client_is_released_when_vanished on CI
test_claim_from_other_client_is_released_when_vanished would fail on
the CI but work on a local system because we wouldn't want long enough
for the "vanished" code path to be taken into account. Add a small
timeout to make sure it works on the CI as well.
2020-03-27 16:57:16 +01:00
Bastien Nocera
47bd3f7fbb tests/fprintd: Fix test_enroll_invalid_storage_dir test
enroll_image() was always waiting for enroll-completed rather than for
what the caller expected as the result.

======================================================================
FAIL: test_enroll_invalid_storage_dir (__main__.FPrintdVirtualDeviceClaimedTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/hadess/Projects/jhbuild/fprintd/tests/fprintd.py", line 661, in test_enroll_invalid_storage_dir
    self.enroll_image('whorl', expected_result='enroll-failed')
  File "/home/hadess/Projects/jhbuild/fprintd/tests/fprintd.py", line 384, in enroll_image
    self.wait_for_result('enroll-completed')
  File "/home/hadess/Projects/jhbuild/fprintd/tests/fprintd.py", line 373, in wait_for_result
    self.assertEqual(self._last_result, expected)
AssertionError: 'enroll-failed' != 'enroll-completed'
- enroll-failed
+ enroll-completed
2020-03-27 16:26:28 +01:00
Marco Trevisan (Treviño)
4f3589c0dc build: List single unit python tests allowing to run them separately
We run a certain number of tests right now, without being able to easily
run them separated or to check which one failed.

So add a script to inspect all the available unittests per each python
script and use it to figure out the tests we can run in meson.

As per this, define a global 'python_tests' variable in meson that allows
to register new python tests easily without having to repeat the settings
for all the tests.

For each test we have, we check if we can fetch a list of unit tests, and
if possible we create a meson test for each one.
Otherwise we just fallback to normal behavior.

This is something that can be hopefully implemented into upstream meson [1].

[1] https://github.com/mesonbuild/meson/issues/6851
2020-03-27 02:29:57 +01:00
Marco Trevisan (Treviño)
eccd790df7 tests/fprintd: Add missing implementation of list_tests
Use unittest_inspector that we provide for meson tests inspection as well
2020-03-27 02:01:14 +01:00
Marco Trevisan (Treviño)
bc29114a2c tests: Add a tool to inspect the single python unit tests
The unit tests files are provided as python files, adding a tool that
allows to list them in order to be able to run them easily via

  python3 -m unittest module.Class.test_method
2020-03-27 01:57:22 +01:00
Timothy Gu
d7fec03f24
tests/fprintd: Increase allowed timeout
On my laptop it takes 48 seconds to run.
2020-03-23 12:22:53 -04:00
Timothy Gu
4a3ae5ccaf
tests/fprintd: Allow tests to run even when virtual device is not available
The test file calls self.daemon_start() in order to start fprintd and
locate the virtual image device that's needed for the test to run.
However, since the virtual image driver is not available on all
libfprint installations, the test should be skipped if the driver is not
available.

The skipping mechanism used to work, by checking if self.device is None.
This is based on the assumption that self.device would be set to None in
cases where the driver is not available. However, even in the past
self.device is only set to None in the tearDown method and not in setUp,
so presumably in edge cases it didn't entirely work.

However, since 0fb4f3b021 which
consistently removes the self.device attribute rather than setting it to
None, the "self.device is None" check no longer works. In particular,
the following error message is shown:

    test_manager_get_default_device (__main__.FPrintdManagerTests) ...
    Did not find virtual device! Probably libfprint was build without
    the corresponding driver!
    ERROR

After this patch, the following is shown:

    test_manager_get_default_device (__main__.FPrintdManagerTests) ...
    Did not find virtual device! Probably libfprint was build without
    the corresponding driver!
    skipped 'Need virtual_image device to run the test'

We fix this bug by consistently setting self.device to None, in both the
setUp method before daemon_start gets called, and in tearDown. We also
make the same change to self.manager for consistency.

The issue was not caught on CI, as the CI configuration always installs
a libfprint version that has the virtual_image device explicitly enabled
in the preparation phase.
2020-03-23 12:22:20 -04:00
Marco Trevisan (Treviño)
d27872ff86 test_fprintd_utils: Don't use hard-coded sleep time
Make sleep time on verification dependent on the environment, so that it's
different when under valgrind
2020-03-17 17:14:35 +01:00
Marco Trevisan (Treviño)
cfbded36e1 test_fprintd_utils: Use a non-blocking pipe to read output
Avoid using a temporary file for reading the utilities output, so we can
read it as it comes, ignoring the previous one, and avoiding open/closing
the file.

To keep the output printing on cleanup working, adding an utility function
that reads the output and save it for later printing
2020-03-17 17:14:35 +01:00