From 3b83240e57a5197d23daddc71367423837ae5043 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Tue, 1 Dec 2020 13:22:30 +0100 Subject: [PATCH] tests: Fix detection of non-functional file permissions If we rely on CI_PROJECT_NAME being set, then the test will fail in similar environments outside of the fprintd main CI. So just add a os.stat call afterwards to check whether the permission changes took effect, and if not, then skip. So, instead try to create a file and check that this fails. --- tests/fprintd.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/fprintd.py b/tests/fprintd.py index bb9761d..ae0768e 100644 --- a/tests/fprintd.py +++ b/tests/fprintd.py @@ -802,18 +802,29 @@ class FPrintdVirtualDeviceClaimedTest(FPrintdVirtualDeviceBaseTest): self.assertFalse(os.path.exists(os.path.join(self.state_dir, 'testuser/virtual_image/0/7'))) def test_enroll_invalid_storage_dir(self): - if 'CI_PROJECT_NAME' in os.environ: - self.skipTest('Permissions aren\'t respected in CI environment') + # Directory wil not exist yet os.makedirs(self.state_dir, mode=0o500) self.addCleanup(os.chmod, self.state_dir, mode=0o700) + + try: + os.open(os.path.join(self.state_dir, "testfile"), os.O_CREAT | os.O_WRONLY) + self.skipTest('Permissions aren\'t respected (CI environment?)') + except PermissionError: + pass + self.enroll_image('whorl', expected_result='enroll-failed') def test_verify_invalid_storage_dir(self): - if 'CI_PROJECT_NAME' in os.environ: - self.skipTest('Permissions aren\'t respected in CI environment') self.enroll_image('whorl') os.chmod(self.state_dir, mode=0o000) self.addCleanup(os.chmod, self.state_dir, mode=0o700) + + try: + os.open(os.path.join(self.state_dir, "testfile"), os.O_CREAT | os.O_WRONLY) + self.skipTest('Permissions aren\'t respected (CI environment?)') + except PermissionError: + pass + with self.assertFprintError('NoEnrolledPrints'): self.device.VerifyStart('(s)', 'any')