@@ -76,6 +76,8 @@ F: package/setools/
F: package/sngrep/
F: package/spidermonkey/
F: package/systemd/
+F: support/testing/tests/package/br2-external/polkit/
+F: support/testing/tests/package/test_polkit_systemd.py
N: Adam Heinrich <adam@adamh.cz>
F: package/jack1/
new file mode 100644
@@ -0,0 +1,2 @@
+source "$BR2_EXTERNAL_POLKIT_PATH/package/polkit-rules-test-initd/Config.in"
+source "$BR2_EXTERNAL_POLKIT_PATH/package/polkit-rules-test-systemd/Config.in"
new file mode 100644
@@ -0,0 +1 @@
+name: POLKIT
new file mode 100644
@@ -0,0 +1 @@
+include $(sort $(wildcard $(BR2_EXTERNAL_POLKIT_PATH)/package/*/*.mk))
new file mode 100644
@@ -0,0 +1,6 @@
+config BR2_PACKAGE_POLKIT_RULES_TEST_SYSTEMD
+ bool "polkit rules test for systemd"
+ depends on BR2_PACKAGE_POLKIT
+ help
+ Simple test to ensure polkit is loading and enforcing rules
+ correctly using a rules file meant for systemd.
new file mode 100644
@@ -0,0 +1,20 @@
+################################################################################
+#
+# polkit-rules-test-systemd
+#
+################################################################################
+
+POLKIT_RULES_TEST_SYSTEMD_DEPENDENCIES = polkit
+
+define POLKIT_RULES_TEST_SYSTEMD_USERS
+ brtest -1 brtest -1 =password /home/brtest /bin/sh brtest
+endef
+
+define POLKIT_RULES_TEST_SYSTEMD_INSTALL_TARGET_CMDS
+ mkdir -p $(TARGET_DIR)/etc/polkit-1/rules.d
+
+ $(INSTALL) -D $(POLKIT_RULES_TEST_SYSTEMD_PKGDIR)/systemd-timesyncd-restart.rules \
+ $(TARGET_DIR)/root/systemd-timesyncd-restart.rules
+endef
+
+$(eval $(generic-package))
new file mode 100644
@@ -0,0 +1,7 @@
+polkit.addRule(function(action, subject) {
+ if (action.id == "org.freedesktop.systemd1.manage-units" &&
+ action.lookup("unit") == "systemd-timesyncd.service" &&
+ subject.user == "brtest") {
+ return polkit.Result.YES;
+ }
+});
new file mode 100644
@@ -0,0 +1,51 @@
+import os
+
+import infra.basetest
+
+
+class TestPolkitSystemd(infra.basetest.BRTest):
+ br2_external = [infra.filepath("tests/package/br2-external/polkit")]
+ config = \
+ """
+ BR2_aarch64=y
+ BR2_TOOLCHAIN_EXTERNAL=y
+ BR2_INIT_SYSTEMD=y
+ BR2_JLEVEL=10
+ BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
+ BR2_LINUX_KERNEL=y
+ BR2_LINUX_KERNEL_CUSTOM_VERSION=y
+ BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.86"
+ BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
+ BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
+ BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
+ BR2_PACKAGE_POLKIT=y
+ BR2_PACKAGE_SYSTEMD_POLKIT=y
+ BR2_TARGET_ROOTFS_CPIO=y
+ BR2_TARGET_ROOTFS_CPIO_GZIP=y
+ BR2_PACKAGE_POLKIT_RULES_TEST_SYSTEMD=y
+ """
+
+ def login(self):
+ img = os.path.join(self.builddir, "images", "rootfs.cpio.gz")
+ kern = os.path.join(self.builddir, "images", "Image")
+ self.emulator.boot(arch="aarch64",
+ kernel=kern,
+ kernel_cmdline=["console=ttyAMA0"],
+ options=["-M", "virt", "-cpu", "cortex-a57", "-m", "512M", "-initrd", img])
+ self.emulator.login()
+
+ def test_run(self):
+ self.login()
+
+ 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 = "su brtest -c '/bin/systemctl restart systemd-timesyncd.service'"
+ _, exit_code = self.emulator.run(cmd, 10)
+ self.assertEqual(exit_code, 0)