From 7470587cfa9a24d3c49adc0fb6cc60512907f31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Lothor=C3=A9?= Date: Fri, 17 Oct 2025 09:42:47 +0200 Subject: [PATCH] support/testing: add runtime tests for python-scp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a basic test involving a local SSH connection (based on dropbear server). The test validates that we are able, through python-scp, to fetch the /etc/hostname file. The test needs some basic key initialization to allow connecting to the dropbear server, hence the custom run_sample_scripts method. Signed-off-by: Alexis Lothoré [Julien: - remove unneeded os import in test script - execute setup commands with assertRunOk() - create /root/.ssh with 0700 mode - run sample scripts using super() - check in the sample file that copied files are the same ] Signed-off-by: Julien Olivain --- .../tests/package/sample_python_scp.py | 15 +++++++++++++ .../testing/tests/package/test_python_scp.py | 21 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 support/testing/tests/package/sample_python_scp.py create mode 100644 support/testing/tests/package/test_python_scp.py diff --git a/support/testing/tests/package/sample_python_scp.py b/support/testing/tests/package/sample_python_scp.py new file mode 100644 index 0000000000..c986a27f0b --- /dev/null +++ b/support/testing/tests/package/sample_python_scp.py @@ -0,0 +1,15 @@ +import filecmp + +from paramiko import SSHClient +from paramiko.client import AutoAddPolicy + +from scp import SCPClient + +ssh_client = SSHClient() +ssh_client.load_system_host_keys() +ssh_client.set_missing_host_key_policy(AutoAddPolicy) +ssh_client.connect('127.0.0.1', username='root') +scp_client = SCPClient(ssh_client.get_transport()) +scp_client.get("/etc/hostname", "/tmp/hostname") + +assert filecmp("/etc/hostname", "/tmp/hostname") diff --git a/support/testing/tests/package/test_python_scp.py b/support/testing/tests/package/test_python_scp.py new file mode 100644 index 0000000000..be04c5684c --- /dev/null +++ b/support/testing/tests/package/test_python_scp.py @@ -0,0 +1,21 @@ +from tests.package.test_python import TestPythonPackageBase + + +class TestPythonSCP(TestPythonPackageBase): + __test__ = True + config = TestPythonPackageBase.config + \ + """ + BR2_PACKAGE_DROPBEAR=y + BR2_PACKAGE_PYTHON3=y + BR2_PACKAGE_PYTHON_SCP=y + """ + sample_scripts = ["tests/package/sample_python_scp.py"] + + def run_sample_scripts(self): + # Allow passwordless root login in SSH server + self.assertRunOk("mkdir -m 0700 /root/.ssh") + self.assertRunOk("dropbearkey -t ed25519 -f .ssh/id_dropbear") + self.assertRunOk("dropbearkey -y -f .ssh/id_dropbear | grep '^ssh-ed25519' > .ssh/authorized_keys") + self.assertRunOk("dropbearconvert dropbear openssh .ssh/id_dropbear .ssh/id_ed25519") + + super().run_sample_scripts()