[Buildroot] [PATCH v3 1/1] package/shadow: new package
Nicolas Carrier
Nicolas.Carrier at orolia.com
Fri Dec 16 14:34:34 UTC 2022
No you didn't do anything wrong, I did :/
FTR if you want to troubleshoot a failing test, you can inspect the output_folder/TestShadow-run.log file, which will give, at its beginning, the qemu command to run, in order to replicate the issue.
Here there were 2, the /tmp/ string should have been /tmp and the quotes for the su command were incorrect, single quotes were needed to avoid the interpreting of the $HOME in the shell.
Here is the fixed version:
import os
from infra.basetest import BRTest, BASIC_TOOLCHAIN_CONFIG
class TestShadow(BRTest):
username = 'user_test'
config = BASIC_TOOLCHAIN_CONFIG + \
"""
BR2_arm=y
BR2_PACKAGE_SHADOW=y
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_4=y
BR2_TARGET_ROOTFS_EXT2_SIZE="65536"
"""
timeout = 60
def login(self):
img = os.path.join(self.builddir, "images", "rootfs.ext4")
self.emulator.boot(arch="armv7",
kernel="builtin",
kernel_cmdline=["root=/dev/mmcblk0",
"rootfstype=ext4"],
options=["-drive", f"file={img},if=sd,format=raw"])
self.emulator.login()
def test_nologin(self):
self.login()
self.assertRunOk("! nologin")
cmd = 'test "$(nologin)" = "This account is currently not available."'
self.assertRunOk(cmd)
def test_useradd_del(self):
username = self.username
self.login()
self.assertRunOk(f'userdel {username} || true')
self.assertRunOk(f'groupdel {username} || true')
self.assertRunOk(f'useradd -s /bin/sh {username}')
self.assertRunOk(f'test $(su {username} -c "whoami") = {username}')
self.assertRunOk(f'userdel {username}')
def test_usermod(self):
username = self.username
new_home = '/tmp'
self.login()
self.assertRunOk(f'userdel {username} || true')
self.assertRunOk(f'groupdel {username} || true')
self.assertRunOk(f'useradd -s /bin/sh {username}')
self.assertRunOk(f'usermod {username} --home {new_home}')
self.assertRunOk(f'test $(su {username} -c \'echo $HOME\') = {new_home}')
self.assertRunOk(f'userdel {username}')
Nicolas Carrier | Software Developer | nicolas.carrier at orolia.com
De : Raphael Pavlidis <raphael.pavlidis at gmail.com>
Envoyé : vendredi 16 décembre 2022 10:42
À : Yann E. MORIN <yann.morin.1998 at free.fr>; Nicolas Carrier <Nicolas.Carrier at orolia.com>
Cc : Thomas Petazzoni <thomas.petazzoni at bootlin.com>; buildroot at buildroot.org <buildroot at buildroot.org>
Objet : Re: [Buildroot] [PATCH v3 1/1] package/shadow: new package
CAUTION: This email originated from outside of the organization.
Do not click links or open attachments unless you recognize the sender and know the content is safe.
Nicolas, All,
I added your test and executed it, but I got an error:
======================================================================
FAIL: test_usermod (tests.package.test_shadow.TestShadow)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/buildroot/support/testing/tests/package/test_shadow.py",
line 53, in test_usermod
self.assertRunOk(f'test $(su {username} -c "echo $HOME") = {new_home}')
File "/tmp/buildroot/support/testing/infra/basetest.py", line 94, in
assertRunOk
self.assertEqual(exit_code, 0)
AssertionError: 1 != 0
I used the following command:
./support/testing/run-tests -d dl -o output_folder -k
tests.package.test_shadow.TestShadow
Did I something wrong?
Regards,
Raphael Pavlidis
More information about the buildroot
mailing list