Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v2 2/4] package/polkit: test /usr/share/polkit-1/rules.d
@ 2022-09-12  6:10 Lang Daniel via buildroot
  2022-09-17 21:31 ` Peter Korsgaard
  0 siblings, 1 reply; 2+ messages in thread
From: Lang Daniel via buildroot @ 2022-09-12  6:10 UTC (permalink / raw)
  To: buildroot@buildroot.org; +Cc: Marek Belisko

Polkit has two directories that are used to store rules.
Add the second directory to the existing tests, to ensure
that both work in the future.

Signed-off-by: Daniel Lang <d.lang@abatec.at>
---
Changes v1 -> v2:
  - Rewrote tests as loop (suggested by Peter)
---
 support/testing/tests/package/test_polkit.py | 56 +++++++++++++-------
 1 file changed, 36 insertions(+), 20 deletions(-)

diff --git a/support/testing/tests/package/test_polkit.py b/support/testing/tests/package/test_polkit.py
index 502d38d13e..6d1aed6f8a 100644
--- a/support/testing/tests/package/test_polkit.py
+++ b/support/testing/tests/package/test_polkit.py
@@ -15,6 +15,10 @@ class TestPolkitInfra(infra.basetest.BRTest):
         BR2_PACKAGE_POLKIT=y
         BR2_PACKAGE_POLKIT_RULES_TEST=y
         """
+    rule_paths = [
+        "/etc/polkit-1/rules.d",
+        "/usr/share/polkit-1/rules.d"
+    ]
 
     def base_test_run(self):
         cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
@@ -36,17 +40,23 @@ class TestPolkitSystemd(TestPolkitInfra):
     def test_run(self):
         TestPolkitInfra.base_test_run(self)
 
-        cmd = "su brtest -c '/bin/systemctl restart systemd-timesyncd.service'"
-        _, exit_code = self.emulator.run(cmd, 10)
-        self.assertEqual(exit_code, 1)
+        rule_file = "systemd-timesyncd-restart.rules"
+        for rule_path in TestPolkitInfra.rule_paths:
+            cmd = "su brtest -c '/bin/systemctl restart systemd-timesyncd.service'"
+            _, exit_code = self.emulator.run(cmd, 10)
+            self.assertEqual(exit_code, 1)
 
-        cmd = "mv /root/systemd-timesyncd-restart.rules /etc/polkit-1/rules.d"
-        _, exit_code = self.emulator.run(cmd, 10)
-        self.assertEqual(exit_code, 0)
+            cmd = "cp /root/{file} {path}".format(file=rule_file, path=rule_path)
+            _, exit_code = self.emulator.run(cmd, 10)
+            self.assertEqual(exit_code, 0)
 
-        cmd = "su brtest -c '/bin/systemctl restart systemd-timesyncd.service'"
-        _, exit_code = self.emulator.run(cmd, 10)
-        self.assertEqual(exit_code, 0)
+            cmd = "su brtest -c '/bin/systemctl restart systemd-timesyncd.service'"
+            _, exit_code = self.emulator.run(cmd, 10)
+            self.assertEqual(exit_code, 0)
+
+            cmd = "rm {path}/{file}".format(file=rule_file, path=rule_path)
+            _, exit_code = self.emulator.run(cmd, 10)
+            self.assertEqual(exit_code, 0)
 
 
 class TestPolkitInitd(TestPolkitInfra):
@@ -55,16 +65,22 @@ class TestPolkitInitd(TestPolkitInfra):
     def test_run(self):
         TestPolkitInfra.base_test_run(self)
 
-        cmd = "su brtest -c 'pkexec hello-polkit'"
-        output, exit_code = self.emulator.run(cmd, 10)
-        self.assertEqual(exit_code, 127)
-        self.assertEqual(output[0], "Error executing command as another user: Not authorized")
+        rule_file = "hello-polkit.rules"
+        for rule_path in TestPolkitInfra.rule_paths:
+            cmd = "su brtest -c 'pkexec hello-polkit'"
+            output, exit_code = self.emulator.run(cmd, 10)
+            self.assertEqual(exit_code, 127)
+            self.assertEqual(output[0], "Error executing command as another user: Not authorized")
+
+            cmd = "cp /root/{file} {path}/{file}".format(file=rule_file, path=rule_path)
+            _, exit_code = self.emulator.run(cmd, 10)
+            self.assertEqual(exit_code, 0)
 
-        cmd = "mv /root/hello-polkit.rules /etc/polkit-1/rules.d/hello-polkit.rules"
-        _, exit_code = self.emulator.run(cmd, 10)
-        self.assertEqual(exit_code, 0)
+            cmd = "su brtest -c 'pkexec hello-polkit'"
+            output, exit_code = self.emulator.run(cmd, 10)
+            self.assertEqual(exit_code, 0)
+            self.assertEqual(output[0], "Hello polkit!")
 
-        cmd = "su brtest -c 'pkexec hello-polkit'"
-        output, exit_code = self.emulator.run(cmd, 10)
-        self.assertEqual(exit_code, 0)
-        self.assertEqual(output[0], "Hello polkit!")
+            cmd = "rm {path}/{file}".format(file=rule_file, path=rule_path)
+            _, exit_code = self.emulator.run(cmd, 10)
+            self.assertEqual(exit_code, 0)
\ No newline at end of file
-- 
2.25.1
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Buildroot] [PATCH v2 2/4] package/polkit: test /usr/share/polkit-1/rules.d
  2022-09-12  6:10 [Buildroot] [PATCH v2 2/4] package/polkit: test /usr/share/polkit-1/rules.d Lang Daniel via buildroot
@ 2022-09-17 21:31 ` Peter Korsgaard
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Korsgaard @ 2022-09-17 21:31 UTC (permalink / raw)
  To: Lang Daniel via buildroot; +Cc: Lang Daniel, Marek Belisko

>>>>> "Lang" == Lang Daniel via buildroot <buildroot@buildroot.org> writes:

 > Polkit has two directories that are used to store rules.
 > Add the second directory to the existing tests, to ensure
 > that both work in the future.

 > Signed-off-by: Daniel Lang <d.lang@abatec.at>
 > ---
 > Changes v1 -> v2:
 >   - Rewrote tests as loop (suggested by Peter)

Committed, thanks.

-- 
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-17 21:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-12  6:10 [Buildroot] [PATCH v2 2/4] package/polkit: test /usr/share/polkit-1/rules.d Lang Daniel via buildroot
2022-09-17 21:31 ` Peter Korsgaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox