Skip to contentSkip to conversation

support/testing: test_dropbear.py: use a constant for the password

PATCH New Peter Korsgaard 1 participant 6 messages Feb 5, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 support/testing: test_dropbear.py: use a constant for the password

The password is used in multiple places, so add a constant for it instead of hardcoding it multiple times.

---
 support/testing/tests/package/test_dropbear.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
support/testing/tests/package/test_dropbear.py +4 -3
index 8f7f1fee82..2a7a1bd8af 100644
@@ -4,14 +4,15 @@ import infra.basetest
 
 
 class TestDropbear(infra.basetest.BRTest):
+    passwd = "testpwd"
     config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
         """
-        BR2_TARGET_GENERIC_ROOT_PASSWD="testpwd"
+        BR2_TARGET_GENERIC_ROOT_PASSWD="{}"
         BR2_SYSTEM_DHCP="eth0"
         BR2_PACKAGE_DROPBEAR=y
         BR2_TARGET_ROOTFS_CPIO=y
         # BR2_TARGET_ROOTFS_TAR is not set
-        """
+        """.format(passwd)
 
     def test_run(self):
         img = os.path.join(self.builddir, "images", "rootfs.cpio")
@@ -20,7 +21,7 @@ class TestDropbear(infra.basetest.BRTest):
                            options=["-initrd", img,
                                     "-net", "nic",
                                     "-net", "user,hostfwd=tcp::2222-:22"])
-        self.emulator.login("testpwd")
+        self.emulator.login(self.passwd)
         cmd = "netstat -ltn 2>/dev/null | grep 0.0.0.0:22"
         _, exit_code = self.emulator.run(cmd)
         self.assertEqual(exit_code, 0)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/3 support/testing: test_dropbear.py: use a constant for the password

Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Peter" == Peter Korsgaard <[email protected]> writes:

The password is used in multiple places, so add a constant for it instead of hardcoding it multiple times.

Committed, thanks.

Signature · 1 line
Bye, Peter Korsgaard
#2 lore raw

PATCH 2/3 support/testing: test_dropbear.py: add test for ssh connection to localhost

In reply to Peter Korsgaard

Use sshpass to pass the password on the command line.

---
 support/testing/tests/package/test_dropbear.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
support/testing/tests/package/test_dropbear.py +5 -3
index 2a7a1bd8af..ad0f89316c 100644
@@ -10,6 +10,7 @@ class TestDropbear(infra.basetest.BRTest):
         BR2_TARGET_GENERIC_ROOT_PASSWD="{}"
         BR2_SYSTEM_DHCP="eth0"
         BR2_PACKAGE_DROPBEAR=y
+        BR2_PACKAGE_SSHPASS=y
         BR2_TARGET_ROOTFS_CPIO=y
         # BR2_TARGET_ROOTFS_TAR is not set
         """.format(passwd)
@@ -25,6 +26,7 @@ class TestDropbear(infra.basetest.BRTest):
         cmd = "netstat -ltn 2>/dev/null | grep 0.0.0.0:22"
         _, exit_code = self.emulator.run(cmd)
         self.assertEqual(exit_code, 0)
-        # Would be useful to try to login through SSH here, through
-        # localhost:2222, though it is not easy to pass the ssh
-        # password on the command line.
+
+        cmd = "sshpass -p {} ssh -y localhost /bin/true".format(self.passwd)
+        _, exit_code = self.emulator.run(cmd)
+        self.assertEqual(exit_code, 0)
Signature · 1 line
2.11.0
#3 lore raw

PATCH 2/3 support/testing: test_dropbear.py: add test for ssh connection to localhost

Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Peter" == Peter Korsgaard <[email protected]> writes:

Use sshpass to pass the password on the command line.

Committed, thanks.

Signature · 1 line
Bye, Peter Korsgaard
#4 lore raw

PATCH 3/3 support/testing: test_dropbear.py: drop ssh port forward to the host

In reply to Peter Korsgaard

It is not used and may conflict with other services running on port 2222 on the host machine.

---
 support/testing/tests/package/test_dropbear.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
support/testing/tests/package/test_dropbear.py +1 -1
index ad0f89316c..bfec8701f2 100644
@@ -21,7 +21,7 @@ class TestDropbear(infra.basetest.BRTest):
                            kernel="builtin",
                            options=["-initrd", img,
                                     "-net", "nic",
-                                    "-net", "user,hostfwd=tcp::2222-:22"])
+                                    "-net", "user"])
         self.emulator.login(self.passwd)
         cmd = "netstat -ltn 2>/dev/null | grep 0.0.0.0:22"
         _, exit_code = self.emulator.run(cmd)
Signature · 1 line
2.11.0
#5 lore raw

PATCH 3/3 support/testing: test_dropbear.py: drop ssh port forward to the host

Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Peter" == Peter Korsgaard <[email protected]> writes:

It is not used and may conflict with other services running on port 2222 on the host machine.

Committed, thanks.

Signature · 1 line
Bye, Peter Korsgaard