084cc7df3f
As reported by [1] [2], the return code of systemctl command between
systemd 253 and 254 has changed when the polkit authentication is
refused:
/bin/systemctl restart systemd-timesyncd.service
The return code changed from 1 to 4. The Polkit test case
"TestPolkitSystemd" expected 1 as return code [3].
The service log is not the same either:
systemd v253:
Failed to restart systemd-timesyncd.service: Interactive authentication required.
systemd v254:
Failed to restart systemd-timesyncd.service: Access denied
git bisect report this commit:
959301cf9f
From the PR (to get more context):
https://github.com/systemd/systemd/pull/26365
Note: systemd doesn't recommend using systemctl exit code to check unit states:
"The mapping of LSB service states to systemd unit states is imperfect, so it is better to
not rely on those return values but to look for specific unit states and substates instead."
Since we only want to check if the command failed, update our test to
check if systemctl returned a non zero code whatever the reason of the
failure.
Thanks to Yann E. MORIN for the brainstorming!
Fixes:
https://gitlab.com/buildroot.org/buildroot/-/jobs/4768561464 (TestPolkitSystemd)
[1] http://lists.busybox.net/pipermail/buildroot/2023-August/671900.html
[2] https://lists.freedesktop.org/archives/systemd-devel/2023-August/049362.html
[3] https://git.buildroot.net/buildroot/tree/support/testing/tests/package/test_polkit.py?h=2023.08-rc1#n45
[4] https://github.com/systemd/systemd/blob/v254/man/systemctl.xml#L2612
Signed-off-by: Romain Naour <romain.naour@smile.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
87 lines
3.0 KiB
Python
87 lines
3.0 KiB
Python
import os
|
|
import infra.basetest
|
|
|
|
|
|
class TestPolkitInfra(infra.basetest.BRTest):
|
|
br2_external = [infra.filepath("tests/package/br2-external/polkit")]
|
|
config = \
|
|
"""
|
|
BR2_arm=y
|
|
BR2_cortex_a9=y
|
|
BR2_ARM_ENABLE_VFP=y
|
|
BR2_TOOLCHAIN_EXTERNAL=y
|
|
BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
|
|
BR2_TARGET_ROOTFS_CPIO=y
|
|
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")
|
|
self.emulator.boot(arch="armv7", kernel="builtin",
|
|
options=["-initrd", cpio_file])
|
|
self.emulator.login()
|
|
|
|
|
|
class TestPolkitSystemd(TestPolkitInfra):
|
|
config = \
|
|
"""
|
|
{}
|
|
BR2_INIT_SYSTEMD=y
|
|
BR2_PACKAGE_SYSTEMD_POLKIT=y
|
|
BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
|
|
# BR2_TARGET_ROOTFS_TAR is not set
|
|
""".format(TestPolkitInfra.config)
|
|
|
|
def test_run(self):
|
|
TestPolkitInfra.base_test_run(self)
|
|
|
|
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.assertNotEqual(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 = "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):
|
|
config = TestPolkitInfra.config
|
|
|
|
def test_run(self):
|
|
TestPolkitInfra.base_test_run(self)
|
|
|
|
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 = "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)
|