diff options
author | Ryo Nakamura <upa@haeena.net> | 2024-02-06 10:35:38 +0900 |
---|---|---|
committer | Ryo Nakamura <upa@haeena.net> | 2024-02-06 10:35:38 +0900 |
commit | ff45d9d71b85a618aed6d3d5e5056bada6ff81f9 (patch) | |
tree | 8f5989f7f30f8e8a9320128617fa63e22115d65a /test | |
parent | 9908fb309d9388481769e1a558a1f8dc47c4dabf (diff) |
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.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_e2e.py | 49 |
1 files changed, 45 insertions, 4 deletions
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() |