From patchwork Fri Jul 19 14:26:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Huesca X-Patchwork-Id: 1134109 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45qtcg2d6Lz9s00 for ; Sat, 20 Jul 2019 00:27:13 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 395FD86A94; Fri, 19 Jul 2019 14:27:10 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id r-TaIsMRjR0Q; Fri, 19 Jul 2019 14:27:08 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id 8C1288574A; Fri, 19 Jul 2019 14:27:08 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id A53C21BF48C for ; Fri, 19 Jul 2019 14:27:07 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 9E5998769F for ; Fri, 19 Jul 2019 14:27:07 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3uep4rXzevYX for ; Fri, 19 Jul 2019 14:27:06 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by whitealder.osuosl.org (Postfix) with ESMTPS id 088F787675 for ; Fri, 19 Jul 2019 14:27:05 +0000 (UTC) X-Originating-IP: 86.250.200.211 Received: from localhost.localdomain (lfbn-1-17395-211.w86-250.abo.wanadoo.fr [86.250.200.211]) (Authenticated sender: victor.huesca@bootlin.com) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id B78FB20005; Fri, 19 Jul 2019 14:27:02 +0000 (UTC) From: Victor Huesca To: buildroot@buildroot.org Date: Fri, 19 Jul 2019 16:26:56 +0200 Message-Id: <20190719142656.14448-1-victor.huesca@bootlin.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [Buildroot] [PATCH v2] support/testing: add test for root password X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Victor Huesca , thomas.petazzoni@bootlin.com Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" Add support to test that the root passowrd is working as expected. - Buildtime test: Check the hash present in the /etc/shadow. - Runtime test: Build an armv7 image and try to login with a password. Signed-off-by: Victor Huesca --- Changes v1 --> v2: - Fix coding style to pass flake8 test --- .../testing/tests/core/test_root_password.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 support/testing/tests/core/test_root_password.py diff --git a/support/testing/tests/core/test_root_password.py b/support/testing/tests/core/test_root_password.py new file mode 100644 index 0000000000..c6f6b76bfd --- /dev/null +++ b/support/testing/tests/core/test_root_password.py @@ -0,0 +1,36 @@ +import os +import infra.basetest +from crypt import crypt + + +class TestRootPassword(infra.basetest.BRTest): + password = "foo" + config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ + """ + BR2_TARGET_ENABLE_ROOT_LOGIN=y + BR2_TARGET_GENERIC_ROOT_PASSWD="{}" + """.format(password) + + def test_run(self): + # 1. Test by looking hash in the /etc/shadow + shadow = os.path.join(self.builddir, "target", "etc", "shadow") + with open(shadow, "r") as f: + users = f.readlines() + for user in users: + s = user.split(":") + n, h = s[0], s[1] + if n == "root": + # Fail if the account is disabled or no password is required + self.assertTrue(h not in ["", "*"]) + # Fail if the has isn't right + self.assertTrue(crypt(self.password, h) == h) + + # 2. Test by attempting to login + try: + cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio") + self.emulator.boot(arch="armv7", + kernel="builtin", + options=["-initrd", cpio_file]) + self.emulator.login(self.password) + except SystemError: + self.fail("Unable to login with the password")