From ff45d9d71b85a618aed6d3d5e5056bada6ff81f9 Mon Sep 17 00:00:00 2001 From: Ryo Nakamura Date: Tue, 6 Feb 2024 10:35:38 +0900 Subject: add two env vars to pass password/keyphrase (#9) MSCP_SSH_AUTH_PASSWORD passes a password, and MSCP_SSH_AUTH_PASSPHRASE passes a passphrase for publickey auth. They enable avoiding interactive password input. Test cases are also added. --- test/test_e2e.py | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/test_e2e.py b/test/test_e2e.py index a73d896..fa17a6a 100644 --- a/test/test_e2e.py +++ b/test/test_e2e.py @@ -12,16 +12,16 @@ from subprocess import check_call, CalledProcessError, PIPE from util import File, check_same_md5sum -def run2ok(args): +def run2ok(args, env = None): cmd = list(map(str, args)) print("cmd: {}".format(" ".join(cmd))) - check_call(cmd) + check_call(cmd, env = env) -def run2ng(args): +def run2ng(args, env = None): cmd = list(map(str, args)) print("cmd: {}".format(" ".join(cmd))) with pytest.raises(CalledProcessError) as e: - check_call(cmd) + check_call(cmd, env = env) """ usage test """ @@ -401,3 +401,44 @@ def test_config_ng(mscp, src_prefix, dst_prefix): os.remove(config) src.cleanup() dst.cleanup() + +# username test assumes that this test runs inside a container, see Dockerfiles +def test_specify_passphrase_via_env(mscp): + src = File(os.getcwd() + "/src", size = 1024).make() + dst = File("/home/test/dst") + env = os.environ + env["MSCP_SSH_AUTH_PASSPHRASE"] = "keypassphrase" + run2ok([mscp, "-H", "-vvv", "-l", "test", "-i", "/home/test/.ssh/id_rsa_test", + src.path, "localhost:" + dst.path], env = env) + assert check_same_md5sum(src, dst) + src.cleanup() + dst.cleanup() + +def test_specify_invalid_passphrase_via_env(mscp): + src = File(os.getcwd() + "/src", size = 1024).make() + dst = File("/home/test/dst") + env = os.environ + env["MSCP_SSH_AUTH_PASSPHRASE"] = "invalid-keypassphrase" + run2ng([mscp, "-H", "-vvv", "-l", "test", "-i", "/home/test/.ssh/id_rsa_test", + src.path, "localhost:" + dst.path], env = env) + src.cleanup() + +def test_specify_password_via_env(mscp): + src = File(os.getcwd() + "/src", size = 1024).make() + dst = File("/home/test/dst") + env = os.environ + env["MSCP_SSH_AUTH_PASSWORD"] = "userpassword" + run2ok([mscp, "-H", "-vvv", "-l", "test", + src.path, "localhost:" + dst.path], env = env) + assert check_same_md5sum(src, dst) + src.cleanup() + dst.cleanup() + +def test_specify_invalid_password_via_env(mscp): + src = File(os.getcwd() + "/src", size = 1024).make() + dst = File("/home/test/dst") + env = os.environ + env["MSCP_SSH_AUTH_PASSWORD"] = "invalid-userpassword" + run2ng([mscp, "-H", "-vvv", "-l", "test", + src.path, "localhost:" + dst.path], env = env) + src.cleanup() -- cgit v1.2.3