test_sudo.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import os
  2. import infra.basetest
  3. class TestSudo(infra.basetest.BRTest):
  4. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  5. """
  6. BR2_PACKAGE_SUDO=y
  7. BR2_TARGET_ROOTFS_CPIO=y
  8. # BR2_TARGET_ROOTFS_TAR is not set
  9. """
  10. def test_run(self):
  11. img = os.path.join(self.builddir, "images", "rootfs.cpio")
  12. self.emulator.boot(arch="armv5",
  13. kernel="builtin",
  14. options=["-initrd", img])
  15. self.emulator.login()
  16. # -D don't set a password
  17. # -h set home directory
  18. # -H don't create home directory
  19. # -s set shell
  20. self.assertRunOk("adduser -D -h /tmp -H -s /bin/sh sudotest")
  21. self.assertRunOk("echo 'sudotest ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers")
  22. output, exit_code = self.emulator.run("su - sudotest -c 'echo hello world'")
  23. self.assertEqual(output, ["hello world"])
  24. output, exit_code = self.emulator.run("su - sudotest -c 'sudo echo hello world'")
  25. self.assertEqual(exit_code, 0)
  26. self.assertEqual(output, ["hello world"])