Skip to content

Commit

Permalink
Enable scp/sftp by default (and add test)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvipanda committed Oct 26, 2024
1 parent 84cf0e9 commit c6e69b0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion jupyter_sshd_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def setup_sshd() -> Dict[str, Any]:
# Last login info is from /var/log/lastlog, which is transient in containerized systems
'-o', 'PrintLastLog no',
'-o', f'AuthorizedKeysFile {AUTHORIZED_KEYS_PATH}',
'-o', f'LogLevel {SSHD_LOG_LEVEL}'
'-o', f'LogLevel {SSHD_LOG_LEVEL}',
# Default to enabling sftp
'-o', 'Subsystem sftp internal-sftp'

]

return {
Expand Down
22 changes: 22 additions & 0 deletions tests/test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,25 @@ def test_ssh_interactive(jupyter_server):
proc.wait()
assert proc.exitstatus == 0


# Test for both the sftp protocol (default on newer scp) ("-s"), and the older
# scp protocol ("-O").
@pytest.mark.parametrize("extra_scp_args", [["-s"], ["-O"]])
def test_scp(jupyter_server, extra_scp_args):
with tempfile.NamedTemporaryFile() as f, tempfile.TemporaryDirectory() as d:
file_contents = secrets.token_hex()
f.write(file_contents.encode())
f.flush()

target_path = os.path.join(d, "target")

cmd = [
'scp', '-v',
] + extra_scp_args + [f"-o={o}" for o in get_ssh_client_options(*jupyter_server)] + [
f.name, f'127.0.0.1:{target_path}'
]

proc = subprocess.run(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)

with open(target_path) as tpf:
assert tpf.read() == file_contents

0 comments on commit c6e69b0

Please sign in to comment.